Repository: incubator-ignite Updated Branches: refs/heads/ignite-614 [created] 37e60c1a0
#ignite-614: Add delay in FileSwapSpaceSpi.remove only for testing. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/ee180bc6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/ee180bc6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/ee180bc6 Branch: refs/heads/ignite-614 Commit: ee180bc6e77d5c74f9e27d4889ccf2e19684a924 Parents: 7e599b6 Author: ivasilinets <ivasilin...@gridgain.com> Authored: Thu May 14 13:17:41 2015 +0300 Committer: ivasilinets <ivasilin...@gridgain.com> Committed: Thu May 14 13:17:41 2015 +0300 ---------------------------------------------------------------------- .../spi/swapspace/file/FileSwapSpaceSpi.java | 7 ++ .../cache/GridCacheSwapPreloadSelfTest.java | 102 ++++++++++--------- 2 files changed, 59 insertions(+), 50 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ee180bc6/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java index e7db285..e8e7191 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java @@ -392,6 +392,13 @@ public class FileSwapSpaceSpi extends IgniteSpiAdapter implements SwapSpaceSpi, byte[] val = space.remove(key, c != null); + try { + U.sleep(1000); + } + catch (IgniteInterruptedCheckedException e) { + e.printStackTrace(); + } + if (c != null) c.apply(val); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ee180bc6/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapPreloadSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapPreloadSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapPreloadSelfTest.java index 6176da4..57c3b9e 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapPreloadSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapPreloadSelfTest.java @@ -156,83 +156,85 @@ public class GridCacheSwapPreloadSelfTest extends GridCommonAbstractTest { final AtomicBoolean done = new AtomicBoolean(); IgniteInternalFuture<?> fut = null; - try { - startGrid(0); + for (int attempt = 0; attempt < 10; attempt++) { + try { + startGrid(0); - final IgniteCache<Integer, Integer> cache = grid(0).cache(null); + final IgniteCache<Integer, Integer> cache = grid(0).cache(null); - assertNotNull(cache); + assertNotNull(cache); - // Populate. - for (int i = 0; i < ENTRY_CNT; i++) - cache.put(i, i); + // Populate. + for (int i = 0; i < ENTRY_CNT; i++) + cache.put(i, i); - Set<Integer> keys = new HashSet<>(); + Set<Integer> keys = new HashSet<>(); - for (Cache.Entry<Integer, Integer> entry : cache.localEntries()) - keys.add(entry.getKey()); + for (Cache.Entry<Integer, Integer> entry : cache.localEntries()) + keys.add(entry.getKey()); - cache.localEvict(keys); + cache.localEvict(keys); + + fut = multithreadedAsync(new Callable<Object>() { + @Nullable @Override public Object call() throws Exception { + Random rnd = new Random(); - fut = multithreadedAsync(new Callable<Object>() { - @Nullable @Override public Object call() throws Exception { - Random rnd = new Random(); + while (!done.get()) { + int key = rnd.nextInt(ENTRY_CNT); - while (!done.get()) { - int key = rnd.nextInt(ENTRY_CNT); + Integer i = cache.get(key); - Integer i = cache.get(key); + assertNotNull(i); + assertEquals(Integer.valueOf(key), i); - assertNotNull(i); - assertEquals(Integer.valueOf(key), i); + //cache.localEvict(Collections.singleton(rnd.nextInt(ENTRY_CNT))); + } - cache.localEvict(Collections.singleton(rnd.nextInt(ENTRY_CNT))); + return null; } + }, 10); - return null; - } - }, 10); + startGrid(1); - startGrid(1); + done.set(true); - done.set(true); + fut.get(); - fut.get(); + fut = null; - fut = null; + int size = grid(1).cache(null).localSize(CachePeekMode.PRIMARY, CachePeekMode.BACKUP, + CachePeekMode.NEAR, CachePeekMode.ONHEAP); - int size = grid(1).cache(null).localSize(CachePeekMode.PRIMARY, CachePeekMode.BACKUP, - CachePeekMode.NEAR, CachePeekMode.ONHEAP); + info("New node cache size: " + size); - info("New node cache size: " + size); + if (size != ENTRY_CNT) { + Set<Integer> keySet = new TreeSet<>(); - if (size != ENTRY_CNT) { - Set<Integer> keySet = new TreeSet<>(); + int next = 0; - int next = 0; + for (IgniteCache.Entry<Integer, Integer> e : grid(1).<Integer, Integer>cache(null).localEntries()) + keySet.add(e.getKey()); - for (IgniteCache.Entry<Integer, Integer> e : grid(1).<Integer, Integer>cache(null).localEntries()) - keySet.add(e.getKey()); + for (Integer i : keySet) { + while (next < i) + info("Missing key: " + next++); - for (Integer i : keySet) { - while (next < i) - info("Missing key: " + next++); - - next++; + next++; + } } - } - assertEquals(ENTRY_CNT, size); - } - finally { - done.set(true); - - try { - if (fut != null) - fut.get(); + assertEquals(ENTRY_CNT, size); } finally { - stopAllGrids(); + done.set(true); + + try { + if (fut != null) + fut.get(); + } + finally { + stopAllGrids(); + } } } }