# sprint-2 fixed test
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/1b241ee1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/1b241ee1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/1b241ee1 Branch: refs/heads/ignite-573 Commit: 1b241ee11afc5fcd97d0e79ca6e5aaec7beb1892 Parents: 905b67b Author: sboikov <sboi...@gridgain.com> Authored: Wed Mar 25 11:17:59 2015 +0300 Committer: sboikov <sboi...@gridgain.com> Committed: Wed Mar 25 11:17:59 2015 +0300 ---------------------------------------------------------------------- ...cheNearUpdateTopologyChangeAbstractTest.java | 4 ++- .../cache/GridCacheAbstractFullApiSelfTest.java | 13 --------- .../GridCacheInterceptorAbstractSelfTest.java | 2 ++ .../dht/GridCacheAtomicNearCacheSelfTest.java | 30 +++++++------------- .../junits/common/GridCommonAbstractTest.java | 18 ++++++++++++ 5 files changed, 34 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b241ee1/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNearUpdateTopologyChangeAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNearUpdateTopologyChangeAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNearUpdateTopologyChangeAbstractTest.java index 809f5f0..4f20694 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNearUpdateTopologyChangeAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNearUpdateTopologyChangeAbstractTest.java @@ -119,12 +119,14 @@ public abstract class CacheNearUpdateTopologyChangeAbstractTest extends IgniteCa awaitPartitionMapExchange(); - GridTestUtils.waitForCondition(new GridAbsPredicate() { + boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { return aff.isPrimary(primaryIgnite.cluster().localNode(), key); } }, 10_000); + assertTrue(wait); + log.info("Primary node: " + primaryNode(key, null).name()); assertTrue(aff.isPrimary(primaryIgnite.cluster().localNode(), key)); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b241ee1/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java index e4f4427..e694b95 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java @@ -4144,19 +4144,6 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract } /** - * @param cache Cache. - * @throws Exception If failed. - */ - protected void atomicClockModeDelay(IgniteCache cache) throws Exception { - CacheConfiguration ccfg = (CacheConfiguration)cache.getConfiguration(CacheConfiguration.class); - - if (ccfg.getCacheMode() != LOCAL && - ccfg.getAtomicityMode() == CacheAtomicityMode.ATOMIC && - ccfg.getAtomicWriteOrderMode() == CacheAtomicWriteOrderMode.CLOCK) - U.sleep(100); - } - - /** * @throws Exception If failed. */ public void testLocalClearKey() throws Exception { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b241ee1/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheInterceptorAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheInterceptorAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheInterceptorAbstractSelfTest.java index a30e3dd..ae6c5e1 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheInterceptorAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheInterceptorAbstractSelfTest.java @@ -800,6 +800,8 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst // Put from grid 1 to be sure grid 0 does not have value for near key. jcache(1).putAll(F.asMap(key1, 1, key2, 2, key3, 3)); + atomicClockModeDelay(jcache(1)); + interceptor.disabled = false; log.info("Update [op=" + op + ", key1=" + key1 + ", key2=" + key2 + ", key3=" + key3 + http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b241ee1/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheAtomicNearCacheSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheAtomicNearCacheSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheAtomicNearCacheSelfTest.java index adf8253..2d28328 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheAtomicNearCacheSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheAtomicNearCacheSelfTest.java @@ -221,10 +221,10 @@ public class GridCacheAtomicNearCacheSelfTest extends GridCommonAbstractTest { int val = 4; for (int i = 0; i < GRID_CNT; i++) { - delay(); - IgniteCache<Integer, Integer> cache = grid(i).cache(null); + atomicClockModeDelay(cache); + for (Integer key : nearKeys.keySet()) nearKeys.put(key, val); @@ -307,10 +307,10 @@ public class GridCacheAtomicNearCacheSelfTest extends GridCommonAbstractTest { int val = nearKey + 1; for (int i = 0; i < GRID_CNT; i++) { - delay(); - IgniteCache<Integer, Integer> cache = grid(i).cache(null); + atomicClockModeDelay(cache); + log.info("Transform [grid=" + grid(i).name() + ", val=" + val + ']'); cache.invoke(nearKey, new Processor(val)); @@ -400,10 +400,10 @@ public class GridCacheAtomicNearCacheSelfTest extends GridCommonAbstractTest { int val = 4; for (int i = 0; i < GRID_CNT; i++) { - delay(); - IgniteCache<Integer, Integer> cache = grid(i).cache(null); + atomicClockModeDelay(cache); + for (Integer key : nearKeys) nearKeys.add(key); @@ -521,10 +521,10 @@ public class GridCacheAtomicNearCacheSelfTest extends GridCommonAbstractTest { int val = nearKey + 1; for (int i = 0; i < GRID_CNT; i++) { - delay(); - IgniteCache<Integer, Integer> cache = grid(i).cache(null); + atomicClockModeDelay(cache); + log.info("Put [grid=" + grid(i).name() + ", val=" + val + ']'); cache.put(nearKey, val); @@ -626,7 +626,7 @@ public class GridCacheAtomicNearCacheSelfTest extends GridCommonAbstractTest { IgniteCache<Integer, Integer> primaryCache = G.ignite( (String) aff.mapKeyToNode(nearKey).attribute(ATTR_GRID_NAME)).cache(null); - delay(); + atomicClockModeDelay(cache0); primaryCache.put(nearKey, 2); // This put should see that near entry evicted on grid0 and remove reader. @@ -672,10 +672,10 @@ public class GridCacheAtomicNearCacheSelfTest extends GridCommonAbstractTest { Ignite primaryNode = G.ignite((String) aff.mapKeyToNode(nearKey).attribute(ATTR_GRID_NAME)); - delay(); - IgniteCache<Integer, Integer> primaryCache = primaryNode.cache(null); + atomicClockModeDelay(primaryCache); + primaryCache.put(nearKey, 2); // Put from primary, check there are no readers. checkEntry(primaryNode, nearKey, 2, false); @@ -783,14 +783,6 @@ public class GridCacheAtomicNearCacheSelfTest extends GridCommonAbstractTest { } /** - * @throws IgniteCheckedException If failed. - */ - private void delay() throws IgniteCheckedException { - if (writeOrderMode == CLOCK) - U.sleep(100); - } - - /** * @param backups Backups number. * @param writeOrderMode Write order mode. * @throws Exception If failed. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b241ee1/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java index 3939465..10fb19f 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java @@ -18,6 +18,7 @@ package org.apache.ignite.testframework.junits.common; import org.apache.ignite.*; +import org.apache.ignite.cache.*; import org.apache.ignite.cache.affinity.*; import org.apache.ignite.cluster.*; import org.apache.ignite.compute.*; @@ -784,4 +785,21 @@ public abstract class GridCommonAbstractTest extends GridAbstractTest { return grid(node); } + + /** + * In ATOMIC cache with CLOCK mode if key is updated from different nodes at same time + * only one update wins others are ignored (can happen in test event when updates are executed from + * different nodes sequentially), this delay is used to avoid lost updates. + * + * @param cache Cache. + * @throws Exception If failed. + */ + protected void atomicClockModeDelay(IgniteCache cache) throws Exception { + CacheConfiguration ccfg = (CacheConfiguration)cache.getConfiguration(CacheConfiguration.class); + + if (ccfg.getCacheMode() != LOCAL && + ccfg.getAtomicityMode() == CacheAtomicityMode.ATOMIC && + ccfg.getAtomicWriteOrderMode() == CacheAtomicWriteOrderMode.CLOCK) + U.sleep(100); + } }