ignite-4450 added test
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/4f76b75a Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/4f76b75a Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/4f76b75a Branch: refs/heads/ignite-4450 Commit: 4f76b75a020c7f5d462f1b66d45c61b568ac44dd Parents: eda71c0 Author: sboikov <[email protected]> Authored: Tue Dec 20 16:03:51 2016 +0300 Committer: sboikov <[email protected]> Committed: Tue Dec 20 16:03:51 2016 +0300 ---------------------------------------------------------------------- .../CacheLockReleaseNodeLeaveTest.java | 101 +++++++++++++++++++ 1 file changed, 101 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/4f76b75a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheLockReleaseNodeLeaveTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheLockReleaseNodeLeaveTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheLockReleaseNodeLeaveTest.java index e84fd3f..f0f18c8 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheLockReleaseNodeLeaveTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheLockReleaseNodeLeaveTest.java @@ -20,9 +20,13 @@ package org.apache.ignite.internal.processors.cache.distributed; import java.util.concurrent.Callable; import java.util.concurrent.locks.Lock; import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.IgniteKernal; +import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.util.lang.GridAbsPredicate; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; @@ -158,4 +162,101 @@ public class CacheLockReleaseNodeLeaveTest extends GridCommonAbstractTest { fut2.get(5, SECONDS); } + + /** + * @throws Exception If failed. + */ + public void testLockRelease2() throws Exception { + final Ignite ignite0 = startGrid(0); + + Ignite ignite1 = startGrid(1); + + Lock lock = ignite1.cache(null).lock("key"); + lock.lock(); + + IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() { + @Override public Void call() throws Exception { + startGrid(2); + + return null; + } + }); + + final AffinityTopologyVersion topVer = new AffinityTopologyVersion(2, 0); + + // Wait when affinity change exchange start. + boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() { + @Override public boolean apply() { + AffinityTopologyVersion topVer0 = + ((IgniteKernal)ignite0).context().cache().context().exchange().topologyVersion(); + + return topVer.compareTo(topVer0) < 0; + } + }, 10_000); + + assertTrue(wait); + + assertFalse(fut.isDone()); + + ignite1.close(); + + fut.get(10_000); + + Ignite ignite2 = ignite(2); + + lock = ignite2.cache(null).lock("key"); + lock.lock(); + lock.unlock(); + } + + /** + * @throws Exception If failed. + */ + public void testTxLockRelease2() throws Exception { + final Ignite ignite0 = startGrid(0); + + Ignite ignite1 = startGrid(1); + + IgniteCache cache = ignite1.cache(null); + ignite1.transactions().txStart(PESSIMISTIC, REPEATABLE_READ); + cache.get(1); + + IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() { + @Override public Void call() throws Exception { + startGrid(2); + + return null; + } + }); + + final AffinityTopologyVersion topVer = new AffinityTopologyVersion(2, 0); + + // Wait when affinity change exchange start. + boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() { + @Override public boolean apply() { + AffinityTopologyVersion topVer0 = + ((IgniteKernal)ignite0).context().cache().context().exchange().topologyVersion(); + + return topVer.compareTo(topVer0) < 0; + } + }, 10_000); + + assertTrue(wait); + + assertFalse(fut.isDone()); + + ignite1.close(); + + fut.get(10_000); + + Ignite ignite2 = ignite(2); + + cache = ignite2.cache(null); + + try (Transaction tx = ignite2.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { + cache.get(1); + + tx.commit(); + } + } }
