/** * Stops block messages and sends all already blocked messages. */ public void stopBlock() { stopBlock(true, null); }
/** * Stops block messages and sends all already blocked messages if sndMsgs is 'true'. * * @param sndMsgs {@code True} to send blocked messages. */ public void stopBlock(boolean sndMsgs) { stopBlock(sndMsgs, null); }
/** * */ private void stopBlock() { for (Ignite node : G.allGrids()) TestRecordingCommunicationSpi.spi(node).stopBlock(); }
/** {@inheritDoc} */ @Override void stop() throws Exception { for (IgniteEx server : baseline) { TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(server); spi.stopBlock(); } super.stop(); } }
@Override public Void call() throws Exception { spi.waitForBlocked(); final IgniteFuture<?> fut = txRef.get().rollbackAsync(); doSleep(500); spi.stopBlock(true); fut.get(); return null; } }, "tx-rollback-thread");
/** * @throws Exception If failed. */ @Params(baseline = 9, atomicityMode = TRANSACTIONAL, cacheMode = REPLICATED) @Test public void testStopBaselineTransactionalReplicated() throws Exception { AtomicInteger cntDownCntr = new AtomicInteger(0); doTest( asMessagePredicate(discoEvt -> discoEvt.type() == EventType.EVT_NODE_LEFT), () -> { IgniteEx node = baseline.get(baseline.size() - cntDownCntr.get() - 1); TestRecordingCommunicationSpi.spi(node).stopBlock(); cntDownCntr.incrementAndGet(); for (int i = 0; i < cntDownCntr.get(); i++) cntFinishedReadOperations.countDown(); // This node and previously stopped nodes as well. stopGrid(node.name()); } ); }
/** * Restore initial state */ protected void unsplit() { if (log.isInfoEnabled()) log.info(">>> Restoring from split"); segmented = false; for (Ignite ignite : G.allGrids()) { TestRecordingCommunicationSpi comm = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi(); comm.stopBlock(); } }
/** * @throws Exception If failed. */ @Params(baseline = 4, atomicityMode = TRANSACTIONAL, cacheMode = REPLICATED) @Test public void testRestartBaselineTransactionalReplicated() throws Exception { doTest( asMessagePredicate(discoEvt -> discoEvt.type() == EventType.EVT_NODE_JOINED), () -> { IgniteEx node = baseline.get(baseline.size() - 1); TestRecordingCommunicationSpi.spi(node).stopBlock(); stopGrid(node.name()); for (int i = 0; i < baselineServersCount() - 2; i++) cntFinishedReadOperations.countDown(); startGrid(node.name()); } ); }
/** * @param cls Message class. * @param nodeToBlock Node to block. * @param block Block. */ private void toggleBlocking(Class<? extends Message> cls, Ignite nodeToBlock, boolean block) { for (Ignite ignite : G.allGrids()) { if (ignite == nodeToBlock) continue; final TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi)ignite.configuration().getCommunicationSpi(); if (block) spi.blockMessages(cls, nodeToBlock.name()); else spi.stopBlock(true); } }
/** * Wait for rebalance, client node joins. * * @throws Exception If failed. */ @Test public void testDelayAssignmentClientJoin() throws Exception { Ignite ignite0 = startServer(0, 1); TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi)ignite0.configuration().getCommunicationSpi(); blockSupplySend(spi, CACHE_NAME1); startServer(1, 2); startClient(2, 3); checkAffinity(3, topVer(3, 0), false); spi.stopBlock(); checkAffinity(3, topVer(3, 1), true); }
/** * Wait for rebalance, client node leaves. * * @throws Exception If failed. */ @Test public void testDelayAssignmentClientLeave() throws Exception { Ignite ignite0 = startServer(0, 1); startClient(1, 2); checkAffinity(2, topVer(2, 0), true); TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi)ignite0.configuration().getCommunicationSpi(); blockSupplySend(spi, CACHE_NAME1); startServer(2, 3); checkAffinity(3, topVer(3, 0), false); stopNode(1, 4); checkAffinity(2, topVer(4, 0), false); spi.stopBlock(); checkAffinity(2, topVer(4, 1), true); }
/** * Wait for rebalance, coordinator leaves, 3 nodes. * * @throws Exception If failed. */ @Test public void testDelayAssignmentCoordinatorLeave2() throws Exception { Ignite ignite0 = startServer(0, 1); Ignite ignite1 = startServer(1, 2); checkAffinity(2, topVer(2, 1), true); TestRecordingCommunicationSpi spi0 = (TestRecordingCommunicationSpi)ignite0.configuration().getCommunicationSpi(); TestRecordingCommunicationSpi spi1 = (TestRecordingCommunicationSpi)ignite1.configuration().getCommunicationSpi(); blockSupplySend(spi0, CACHE_NAME1); blockSupplySend(spi1, CACHE_NAME1); startServer(2, 3); stopNode(0, 4); checkAffinity(2, topVer(4, 0), false); spi1.stopBlock(); checkAffinity(2, topVer(4, 1), true); }
/** * Wait for rebalance, client cache is started. * * @throws Exception If failed. */ @Test public void testDelayAssignmentClientCacheStart() throws Exception { Ignite ignite0 = startServer(0, 1); TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi)ignite0.configuration().getCommunicationSpi(); blockSupplySend(spi, CACHE_NAME1); startServer(1, 2); startServer(2, 3); cacheC = new IgniteClosure<String, CacheConfiguration[]>() { @Override public CacheConfiguration[] apply(String nodeName) { return null; } }; Ignite client = startClient(3, 4); checkAffinity(4, topVer(4, 0), false); assertNotNull(client.cache(CACHE_NAME1)); checkAffinity(4, topVer(4, 0), false); spi.stopBlock(); checkAffinity(4, topVer(4, 1), true); }
/** * Wait for rebalance, cache is started. * * @throws Exception If failed. */ @Test public void testDelayAssignmentCacheStart() throws Exception { Ignite ignite0 = startServer(0, 1); TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi)ignite0.configuration().getCommunicationSpi(); blockSupplySend(spi, CACHE_NAME1); startServer(1, 2); startServer(2, 3); checkAffinity(3, topVer(3, 0), false); CacheConfiguration ccfg = cacheConfiguration(); ccfg.setName(CACHE_NAME2); ignite0.createCache(ccfg); calculateAffinity(3); checkAffinity(3, topVer(3, 1), false); spi.stopBlock(); checkAffinity(3, topVer(3, 2), true); }
/** * Wait for rebalance, cache is destroyed. * * @throws Exception If failed. */ @Test public void testDelayAssignmentCacheDestroy() throws Exception { Ignite ignite0 = startServer(0, 1); CacheConfiguration ccfg = cacheConfiguration(); ccfg.setName(CACHE_NAME2); ignite0.createCache(ccfg); TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi)ignite0.configuration().getCommunicationSpi(); blockSupplySend(spi, CACHE_NAME2); startServer(1, 2); startServer(2, 3); checkAffinity(3, topVer(3, 0), false); ignite0.destroyCache(CACHE_NAME2); checkAffinity(3, topVer(3, 1), false); checkAffinity(3, topVer(3, 2), true); spi.stopBlock(); }
/** * @param joinCnt Number of joining nodes. * @throws Exception If failed. */ private void delayAssignmentMultipleJoin(int joinCnt) throws Exception { Ignite ignite0 = startServer(0, 1); TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi)ignite0.configuration().getCommunicationSpi(); blockSupplySend(spi, CACHE_NAME1); int majorVer = 1; for (int i = 0; i < joinCnt; i++) { majorVer++; startServer(i + 1, majorVer); checkAffinity(majorVer, topVer(majorVer, 0), false); } List<IgniteInternalFuture<?>> futs = affFutures(majorVer, topVer(majorVer, 1)); U.sleep(1000); for (IgniteInternalFuture<?> fut : futs) assertFalse(fut.isDone()); spi.stopBlock(); checkAffinity(majorVer, topVer(majorVer, 1), true); for (IgniteInternalFuture<?> fut : futs) assertTrue(fut.isDone()); awaitPartitionMapExchange(); }
/** * Test checks that delayed full messages are processed correctly in case of changed coordinator. * * @throws Exception If failed. */ @Test public void testDelayedFullMessageReplacedIfCoordinatorChanged() throws Exception { spiFactory = TestRecordingCommunicationSpi::new; IgniteEx crd = startGrid("crd"); IgniteEx newCrd = startGrid(1); IgniteEx problemNode = startGrid(2); crd.cluster().active(true); awaitPartitionMapExchange(); blockSendingFullMessage(crd, problemNode); IgniteInternalFuture joinNextNodeFut = GridTestUtils.runAsync(() -> startGrid(3)); joinNextNodeFut.get(); U.sleep(5000); blockSendingFullMessage(newCrd, problemNode); IgniteInternalFuture stopCoordinatorFut = GridTestUtils.runAsync(() -> stopGrid("crd")); stopCoordinatorFut.get(); U.sleep(5000); TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(newCrd); spi.stopBlock(true); awaitPartitionMapExchange(); }
/** * Wait for rebalance, send affinity change message, but affinity already changed (new node joined). * * @throws Exception If failed. */ @Test public void testDelayAssignmentAffinityChanged() throws Exception { Ignite ignite0 = startServer(0, 1); DiscoverySpiTestListener lsnr = new DiscoverySpiTestListener(); ((IgniteDiscoverySpi)ignite0.configuration().getDiscoverySpi()).setInternalListener(lsnr); TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi)ignite0.configuration().getCommunicationSpi(); startClient(1, 2); checkAffinity(2, topVer(2, 0), true); lsnr.blockCustomEvent(CacheAffinityChangeMessage.class); startServer(2, 3); checkAffinity(3, topVer(3, 0), false); lsnr.waitCustomEvent(); blockSupplySend(commSpi0, CACHE_NAME1); startServer(3, 4); lsnr.stopBlockCustomEvents(); checkAffinity(4, topVer(4, 0), false); checkNoExchange(4, topVer(4, 1)); commSpi0.stopBlock(); checkAffinity(4, topVer(4, 1), true); }
/** * @throws Exception If failed. */ @Test public void testPutPrimarySync() throws Exception { startGrids(2); client = true; Ignite clientNode = startGrid(2); client = false; final IgniteCache<Integer, Integer> nearCache = clientNode.createCache(cacheConfiguration(1, PRIMARY_SYNC)); awaitPartitionMapExchange(); Ignite srv0 = grid(0); final Ignite srv1 = grid(1); final Integer key = primaryKey(srv0.cache(TEST_CACHE)); testSpi(srv0).blockMessages(GridDhtAtomicSingleUpdateRequest.class, srv1.name()); IgniteFuture<?> fut = nearCache.putAsync(key, key); fut.get(5, TimeUnit.SECONDS); assertEquals(key, srv0.cache(TEST_CACHE).get(key)); assertNull(srv1.cache(TEST_CACHE).localPeek(key)); testSpi(srv0).stopBlock(true); GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { return srv1.cache(TEST_CACHE).localPeek(key) != null; } }, 5000); checkData(F.asMap(key, key)); }