From 28f2a857883593eabc11d60edd559ea5f6ee926a Mon Sep 17 00:00:00 2001 From: Alexey Goncharuk Date: Tue, 28 Jul 2015 16:08:40 -0700 Subject: [PATCH] # ignite-1165 --- .../cache/distributed/near/GridNearGetFuture.java | 20 ++-- .../IgniteCacheNearOffheapGetSelfTest.java | 131 +++++++++++++++++++++ ...idCachePartitionedMultiNodeFullApiSelfTest.java | 6 +- .../ignite/testsuites/IgniteCacheTestSuite2.java | 1 + 4 files changed, 147 insertions(+), 11 deletions(-) create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheNearOffheapGetSelfTest.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java index 58f6fe5..d109d2b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java @@ -437,17 +437,19 @@ public final class GridNearGetFuture extends GridCompoundIdentityFuture dht = cache().dht(); + GridCacheEntryEx dhtEntry = null; + try { - entry = dht.context().isSwapOrOffheapEnabled() ? dht.entryEx(key) : dht.peekEx(key); + dhtEntry = dht.context().isSwapOrOffheapEnabled() ? dht.entryEx(key) : dht.peekEx(key); // If near cache does not have value, then we peek DHT cache. - if (entry != null) { - boolean isNew = entry.isNewLocked() || !entry.valid(topVer); + if (dhtEntry != null) { + boolean isNew = dhtEntry.isNewLocked() || !dhtEntry.valid(topVer); - v = entry.innerGet(tx, + v = dhtEntry.innerGet(tx, /*swap*/true, /*read-through*/false, /*fail-fast*/true, @@ -461,7 +463,7 @@ public final class GridNearGetFuture extends GridCompoundIdentityFuture extends GridCompoundIdentityFuture nearOnly = ignite(gridCount() - 1).cache(null); + + // Start extra node. + IgniteEx ignite = startGrid(gridCount()); + + try { + final int keyCnt = 30; + + for (int i = 0; i < keyCnt; i++) + ignite(0).cache(null).put(i, i); + + for (int i = 0; i < keyCnt; i++) + assertEquals(i, nearOnly.get(i)); + + Collection invalidatedKeys = new ArrayList<>(); + + Affinity cacheAff = ignite.affinity(null); + + // Going to stop the last node. + for (int i = 0; i < keyCnt; i++) { + if (cacheAff.mapKeyToNode(i).equals(ignite.localNode())) + invalidatedKeys.add(i); + } + + stopGrid(gridCount()); + + for (Integer key : invalidatedKeys) + assertEquals(key, nearOnly.get(key)); + } + finally { + if (Ignition.state(getTestGridName(gridCount())) == IgniteState.STARTED) + stopGrid(gridCount()); + } + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java index 30c9e8a..747de21 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java @@ -306,7 +306,7 @@ public class GridCachePartitionedMultiNodeFullApiSelfTest extends GridCacheParti for (int i = 0; i < gridCount(); i++) { IgniteEx ignite = grid(i); - if (!ignite.configuration().isClientMode()) { + if (!Boolean.TRUE.equals(ignite.configuration().isClientMode())) { if (ignite0 == null) ignite0 = ignite; else if (ignite1 == null) @@ -361,7 +361,9 @@ public class GridCachePartitionedMultiNodeFullApiSelfTest extends GridCacheParti boolean nearEnabled = cache2.getConfiguration(CacheConfiguration.class).getNearConfiguration() != null; assertEquals(nearEnabled ? 2 : 0, cache2.localSize(NEAR)); - assertEquals(0, cache2.localSize(CachePeekMode.ALL) - cache2.localSize(NEAR)); + + if (cacheMode() != REPLICATED) + assertEquals(0, cache2.localSize(CachePeekMode.ALL) - cache2.localSize(NEAR)); } /** diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java index 6a59826..bf760f5 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java @@ -123,6 +123,7 @@ public class IgniteCacheTestSuite2 extends TestSuite { suite.addTest(new TestSuite(GridCacheColocatedOptimisticTransactionSelfTest.class)); suite.addTestSuite(GridCacheAtomicMessageCountSelfTest.class); suite.addTest(new TestSuite(GridCacheNearPartitionedClearSelfTest.class)); + suite.addTest(new TestSuite(IgniteCacheNearOffheapGetSelfTest.class)); suite.addTest(new TestSuite(GridCacheDhtExpiredEntriesPreloadSelfTest.class)); suite.addTest(new TestSuite(GridCacheNearExpiredEntriesPreloadSelfTest.class)); -- 1.9.5 (Apple Git-50.3)