ignite-3621 Fixed 'testEvictExpired'. (cherry picked from commit bfe4458)
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/74d2fc24 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/74d2fc24 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/74d2fc24 Branch: refs/heads/ignite-comm-balance Commit: 74d2fc2416b8e6bc0598152552021f984a013061 Parents: b2faa33 Author: sboikov <[email protected]> Authored: Wed Sep 28 14:31:24 2016 +0300 Committer: sboikov <[email protected]> Committed: Wed Sep 28 15:43:42 2016 +0300 ---------------------------------------------------------------------- ...heAtomicClientOnlyMultiNodeFullApiSelfTest.java | 17 +++++++++++++++-- ...acheAtomicNearOnlyMultiNodeFullApiSelfTest.java | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/74d2fc24/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest.java index 927ee62..65f780b 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest.java @@ -36,6 +36,7 @@ import org.apache.ignite.cache.CachePeekMode; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.NearCacheConfiguration; import org.apache.ignite.events.Event; +import org.apache.ignite.internal.util.lang.GridAbsPredicate; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgnitePredicate; @@ -45,6 +46,7 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; import static org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_SWAPPED; import static org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_UNSWAPPED; +import static org.apache.ignite.testframework.GridTestUtils.waitForCondition; /** * @@ -193,7 +195,7 @@ public class GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest extends GridCache @Override public void testEvictExpired() throws Exception { IgniteCache<String, Integer> cache = jcache(); - String key = primaryKeysForCache(cache, 1).get(0); + final String key = primaryKeysForCache(cache, 1).get(0); cache.put(key, 1); @@ -204,7 +206,18 @@ public class GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest extends GridCache grid(0).cache(null). withExpiryPolicy(new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl))).put(key, 1); - Thread.sleep(ttl + 100); + boolean wait = waitForCondition(new GridAbsPredicate() { + @Override public boolean apply() { + for (int i = 0; i < gridCount(); i++) { + if (peek(jcache(i), key) != null) + return false; + } + + return true; + } + }, ttl + 1000); + + assertTrue("Failed to wait for entry expiration.", wait); // Expired entry should not be swapped. cache.localEvict(Collections.singleton(key)); http://git-wip-us.apache.org/repos/asf/ignite/blob/74d2fc24/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java index 3ce38f3..6542e76 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java @@ -29,9 +29,11 @@ import org.apache.ignite.cache.CachePeekMode; import org.apache.ignite.cache.affinity.Affinity; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.NearCacheConfiguration; +import org.apache.ignite.internal.util.lang.GridAbsPredicate; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; +import static org.apache.ignite.testframework.GridTestUtils.waitForCondition; /** * Tests NEAR_ONLY cache. @@ -124,7 +126,7 @@ public class GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest extends GridCacheNe IgniteCache<String, Integer> cache = jcache(); - String key = primaryKeysForCache(cache, 1).get(0); + final String key = primaryKeysForCache(cache, 1).get(0); cache.put(key, 1); @@ -135,7 +137,18 @@ public class GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest extends GridCacheNe grid(0).cache(null). withExpiryPolicy(new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl))).put(key, 1); - Thread.sleep(ttl + 100); + boolean wait = waitForCondition(new GridAbsPredicate() { + @Override public boolean apply() { + for (int i = 0; i < gridCount(); i++) { + if (peek(jcache(i), key) != null) + return false; + } + + return true; + } + }, ttl + 1000); + + assertTrue("Failed to wait for entry expiration.", wait); // Expired entry should not be swapped. cache.localEvict(Collections.singleton(key));
