Repository: ignite Updated Branches: refs/heads/master 403601b52 -> c1ac19df8
IGNITE-1376: Fixed test clear routine. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/3f75c1c4 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/3f75c1c4 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/3f75c1c4 Branch: refs/heads/master Commit: 3f75c1c4427dc32d990560d0b8dc80a191f5f666 Parents: 367d805 Author: vozerov-gridgain <voze...@gridgain.com> Authored: Tue Sep 15 15:31:42 2015 +0300 Committer: vozerov-gridgain <voze...@gridgain.com> Committed: Tue Sep 15 15:31:42 2015 +0300 ---------------------------------------------------------------------- .../processors/igfs/IgfsFileWorkerBatch.java | 15 ++++- .../processors/igfs/IgfsAbstractSelfTest.java | 60 +++++++++----------- .../igfs/IgfsDualAbstractSelfTest.java | 10 +++- 3 files changed, 49 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/3f75c1c4/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileWorkerBatch.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileWorkerBatch.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileWorkerBatch.java index 6bea187..130846b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileWorkerBatch.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileWorkerBatch.java @@ -49,6 +49,9 @@ public abstract class IgfsFileWorkerBatch implements Runnable { /** Output stream to the file. */ private final OutputStream out; + /** Cancel flag. */ + private volatile boolean cancelled; + /** Finishing flag. */ private volatile boolean finishing; @@ -108,6 +111,13 @@ public abstract class IgfsFileWorkerBatch implements Runnable { } /** + * @return {@code True} if batch write was terminated abruptly due to explicit cancellation. + */ + boolean cancelled() { + return cancelled; + } + + /** * Process the batch. */ @SuppressWarnings("unchecked") @@ -124,8 +134,11 @@ public abstract class IgfsFileWorkerBatch implements Runnable { break; } - else if (data == CANCEL_MARKER) + else if (data == CANCEL_MARKER) { + cancelled = true; + throw new IgniteCheckedException("Write to file was cancelled due to node stop."); + } else if (data != null) { try { out.write(data); http://git-wip-us.apache.org/repos/asf/ignite/blob/3f75c1c4/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java index 7513bb8..957363f 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java @@ -188,8 +188,8 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { /** * Constructor. * - * @param mode - * @param memoryMode + * @param mode IGFS mode. + * @param memoryMode Memory mode. */ protected IgfsAbstractSelfTest(IgfsMode mode, CacheMemoryMode memoryMode) { assert mode != null && mode != PROXY; @@ -201,9 +201,10 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { } /** + * Data chunk. * - * @param length - * @return + * @param length Length. + * @return Data chunk. */ static byte[] createChunk(int length) { byte[] chunk = new byte[length]; @@ -255,6 +256,7 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { * @return Started grid instance. * @throws Exception If failed. */ + @SuppressWarnings("unchecked") protected Ignite startGridWithIgfs(String gridName, String igfsName, IgfsMode mode, @Nullable IgfsSecondaryFileSystem secondaryFs, @Nullable IgfsIpcEndpointConfiguration restCfg) throws Exception { FileSystemConfiguration igfsCfg = new FileSystemConfiguration(); @@ -309,9 +311,10 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { } /** + * Prepare cache configuration. * - * @param dataCacheCfg - * @param metaCacheCfg + * @param dataCacheCfg Data cache configuration. + * @param metaCacheCfg Meta cache configuration. */ protected void prepareCacheConfigurations(CacheConfiguration dataCacheCfg, CacheConfiguration metaCacheCfg) { // Noop @@ -782,9 +785,9 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { boolean ok = igfs.delete(SUBDIR, false); assertFalse(ok); - } catch (IgfsDirectoryNotEmptyException idnee) { - // ok, expected - U.debug("Expected: " + idnee); + } + catch (IgfsDirectoryNotEmptyException ignore) { + // No-op, expected. } checkExist(igfs, igfsSecondary, SUBDIR, SUBSUBDIR, FILE); @@ -841,7 +844,7 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { /** * Ensure that formatting is not propagated to the secondary file system. - * + * * TODO: IGNITE-586. * * @throws Exception If failed. @@ -850,7 +853,7 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { public void testFormat() throws Exception { // Test works too long and fails. fail("https://issues.apache.org/jira/browse/IGNITE-586"); - + IgniteKernal grid = (IgniteKernal)G.ignite("grid"); GridCacheAdapter cache = grid.internalCache("dataCache"); @@ -2249,6 +2252,7 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { } } + @SuppressWarnings("EmptyTryBlock") public void create(UniversalFileSystemAdapter uni, @Nullable IgfsPath[] dirs, @Nullable IgfsPath[] files) throws Exception { if (dirs != null) { for (IgfsPath dir : dirs) @@ -2257,8 +2261,8 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { if (files != null) { for (IgfsPath file : files) - try (OutputStream os = uni.openOutputStream(file.toString(), false)) { - // noop + try (OutputStream ignore = uni.openOutputStream(file.toString(), false)) { + // No-op } } } @@ -2291,12 +2295,12 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { /** * Create the file in the given IGFS and write provided data chunks to it. * + * @param uni File system adapter. * @param file File. - * @param overwrite Overwrite flag. * @param chunks Data chunks. * @throws IOException In case of IO exception. */ - protected static void createFile(UniversalFileSystemAdapter uni, IgfsPath file, boolean overwrite, @Nullable byte[]... chunks) + protected static void createFile(UniversalFileSystemAdapter uni, IgfsPath file, @Nullable byte[]... chunks) throws IOException { OutputStream os = null; @@ -2658,7 +2662,14 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { for (Map.Entry<IgfsPath, IgfsFileWorkerBatch> entry : workerMap.entrySet()) { entry.getValue().cancel(); - entry.getValue().await(); + + try { + entry.getValue().await(); + } + catch (IgniteCheckedException e) { + if (!entry.getValue().cancelled()) + throw e; + } } // Clear igfs. @@ -2675,21 +2686,6 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { public static void clear(UniversalFileSystemAdapter uni) throws Exception { IgfsEx igfsEx = uni.getAdapter(IgfsEx.class); - if (igfsEx != null) { - Field workerMapFld = IgfsImpl.class.getDeclaredField("workerMap"); - - workerMapFld.setAccessible(true); - - // Wait for all workers to finish. - Map<IgfsPath, IgfsFileWorkerBatch> workerMap = (Map<IgfsPath, IgfsFileWorkerBatch>)workerMapFld.get(igfs); - - for (Map.Entry<IgfsPath, IgfsFileWorkerBatch> entry : workerMap.entrySet()) { - entry.getValue().cancel(); - entry.getValue().await(); - } - } - - // Clear the filesystem: - uni.format(); + clear(igfsEx); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/3f75c1c4/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsDualAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsDualAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsDualAbstractSelfTest.java index 0141173..683054b 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsDualAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsDualAbstractSelfTest.java @@ -1129,7 +1129,7 @@ public abstract class IgfsDualAbstractSelfTest extends IgfsAbstractSelfTest { create(igfsSecondary, paths(DIR, SUBDIR), null); create(igfs, null, null); - createFile(igfsSecondary, FILE, true, chunk); + createFile(igfsSecondary, FILE, chunk); checkFileContent(igfs, FILE, chunk); } @@ -1139,6 +1139,7 @@ public abstract class IgfsDualAbstractSelfTest extends IgfsAbstractSelfTest { * * @throws Exception If failed. */ + @SuppressWarnings({"ResultOfMethodCallIgnored", "ThrowableResultOfMethodCallIgnored"}) public void testOpenNoPrefetch() throws Exception { create(igfsSecondary, paths(DIR, SUBDIR), paths(FILE)); @@ -1216,6 +1217,7 @@ public abstract class IgfsDualAbstractSelfTest extends IgfsAbstractSelfTest { * * @throws Exception If failed. */ + @SuppressWarnings("ResultOfMethodCallIgnored") public void testOpenPrefetch() throws Exception { create(igfsSecondary, paths(DIR, SUBDIR), paths(FILE)); @@ -1251,6 +1253,8 @@ public abstract class IgfsDualAbstractSelfTest extends IgfsAbstractSelfTest { IgfsFileInfo info = meta.info(meta.fileId(FILE)); + assert info != null; + IgfsBlockKey key = new IgfsBlockKey(info.id(), info.affinityKey(), info.evictExclude(), 2); IgniteCache<IgfsBlockKey, byte[]> dataCache = igfs.context().kernalContext().cache().jcache( @@ -1344,7 +1348,7 @@ public abstract class IgfsDualAbstractSelfTest extends IgfsAbstractSelfTest { igfsSecondaryFileSystem.update(SUBDIR, props); - createFile(igfsSecondary, FILE, true, /*BLOCK_SIZE,*/ chunk); + createFile(igfsSecondary, FILE, /*BLOCK_SIZE,*/ chunk); appendFile(igfs, FILE, chunk); @@ -1371,7 +1375,7 @@ public abstract class IgfsDualAbstractSelfTest extends IgfsAbstractSelfTest { igfsSecondaryFileSystem.update(DIR, propsDir); igfsSecondaryFileSystem.update(SUBDIR, propsSubDir); - createFile(igfsSecondary, FILE, true, /*BLOCK_SIZE,*/ chunk); + createFile(igfsSecondary, FILE, /*BLOCK_SIZE,*/ chunk); appendFile(igfs, FILE, chunk);