Added tests on EVT_CACHE_REBALANCE_PART_DATA_LOST event.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/8c2553ed Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/8c2553ed Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/8c2553ed Branch: refs/heads/ignite-648 Commit: 8c2553eda7ea68498c1d0235060b20f31ef55c8a Parents: 01eee2d Author: nikolay_tikhonov <ntikho...@gridgain.com> Authored: Wed Jun 17 16:12:48 2015 +0300 Committer: nikolay_tikhonov <ntikho...@gridgain.com> Committed: Wed Jun 17 16:12:48 2015 +0300 ---------------------------------------------------------------------- ...ridCachePartitionNotLoadedEventSelfTest.java | 82 ++++++++++++++++++++ .../ignite/util/TestTcpCommunicationSpi.java | 21 +++++ 2 files changed, 103 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8c2553ed/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePartitionNotLoadedEventSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePartitionNotLoadedEventSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePartitionNotLoadedEventSelfTest.java index 6da27d5..baa6d89 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePartitionNotLoadedEventSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePartitionNotLoadedEventSelfTest.java @@ -22,15 +22,19 @@ import org.apache.ignite.cache.*; import org.apache.ignite.cache.affinity.*; import org.apache.ignite.configuration.*; import org.apache.ignite.events.*; +import org.apache.ignite.internal.*; +import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.*; import org.apache.ignite.lang.*; import org.apache.ignite.spi.discovery.tcp.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; +import org.apache.ignite.testframework.*; import org.apache.ignite.testframework.junits.common.*; import org.apache.ignite.util.*; import org.eclipse.jetty.util.*; import java.util.*; +import java.util.concurrent.*; /** * @@ -150,6 +154,84 @@ public class GridCachePartitionNotLoadedEventSelfTest extends GridCommonAbstract } /** + * @throws Exception If failed. + */ + public void testStableTopology() throws Exception { + backupCnt = 1; + + startGrid(1); + + awaitPartitionMapExchange(); + + startGrid(0); + + PartitionNotFullyLoadedListener lsnr = new PartitionNotFullyLoadedListener(); + + grid(1).events().localListen(lsnr, EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST); + + IgniteCache<Integer, Integer> cache0 = jcache(0); + + int key = primaryKey(cache0); + + jcache(1).put(key, key); + + assert cache0.containsKey(key); + + TestTcpCommunicationSpi.stop(ignite(0)); + + stopGrid(0, true); + + awaitPartitionMapExchange(); + + assert jcache(1).containsKey(key); + + assert lsnr.lostParts.isEmpty(); + } + + + /** + * @throws Exception If failed. + */ + public void testMapPartitioned() throws Exception { + backupCnt = 0; + + startGrid(0); + + startGrid(1); + + PartitionNotFullyLoadedListener lsnr = new PartitionNotFullyLoadedListener(); + + grid(1).events().localListen(lsnr, EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST); + + TestTcpCommunicationSpi.skipMsgType(ignite(0), GridDhtPartitionsFullMessage.class); + + IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() { + @Override public Object call() throws Exception { + startGrid(2); + + return null; + } + }); + + boolean timeout = false; + + try { + fut.get(1, TimeUnit.SECONDS); + } + catch (IgniteFutureTimeoutCheckedException e) { + timeout = true; + } + + assert timeout; + + stopGrid(0, true); + + awaitPartitionMapExchange(); + + assert !lsnr.lostParts.isEmpty(); + } + + /** * */ private static class PartitionNotFullyLoadedListener implements IgnitePredicate<Event> { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8c2553ed/modules/core/src/test/java/org/apache/ignite/util/TestTcpCommunicationSpi.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/util/TestTcpCommunicationSpi.java b/modules/core/src/test/java/org/apache/ignite/util/TestTcpCommunicationSpi.java index ad2a262..6e4e50b 100644 --- a/modules/core/src/test/java/org/apache/ignite/util/TestTcpCommunicationSpi.java +++ b/modules/core/src/test/java/org/apache/ignite/util/TestTcpCommunicationSpi.java @@ -19,6 +19,7 @@ package org.apache.ignite.util; import org.apache.ignite.*; import org.apache.ignite.cluster.*; +import org.apache.ignite.internal.managers.communication.*; import org.apache.ignite.plugin.extensions.communication.*; import org.apache.ignite.spi.*; import org.apache.ignite.spi.communication.tcp.*; @@ -30,11 +31,17 @@ public class TestTcpCommunicationSpi extends TcpCommunicationSpi { /** */ private volatile boolean stopped; + /** */ + private Class ignoreMsg; + /** {@inheritDoc} */ @Override public void sendMessage(final ClusterNode node, final Message msg) throws IgniteSpiException { if (stopped) return; + if (ignoreMsg != null && ((GridIoMessage)msg).message().getClass().equals(ignoreMsg)) + return; + super.sendMessage(node, msg); } @@ -46,9 +53,23 @@ public class TestTcpCommunicationSpi extends TcpCommunicationSpi { } /** + * + */ + public void stop(Class ignoreMsg) { + this.ignoreMsg = ignoreMsg; + } + + /** * Stop SPI, messages will not send anymore. */ public static void stop(Ignite ignite) { ((TestTcpCommunicationSpi)ignite.configuration().getCommunicationSpi()).stop(); } + + /** + * Skip messages will not send anymore. + */ + public static void skipMsgType(Ignite ignite, Class clazz) { + ((TestTcpCommunicationSpi)ignite.configuration().getCommunicationSpi()).stop(clazz); + } }