/** * @param spi SPI. * @param cacheName Cache name. */ private void blockSupplySend(TestRecordingCommunicationSpi spi, final String cacheName) { final int grpId = CU.cacheId(cacheName); spi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() { @Override public boolean apply(ClusterNode node, Message msg) { return msg.getClass().equals(GridDhtPartitionSupplyMessage.class) && ((GridDhtPartitionSupplyMessage)msg).groupId() == grpId; } }); }
/** {@inheritDoc} */ @Override protected void execute() { for (IgniteEx server : baseline) { TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(server); spi.blockMessages(this::blockMessage); } block.run(); }
/** * @param spi SPI. * @param cacheName Cache name. */ private void blockSupplySend(TestRecordingCommunicationSpi spi, final String cacheName) { final int grpId = groupIdForCache(spi.ignite(), cacheName); spi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() { @Override public boolean apply(ClusterNode node, Message msg) { if (!msg.getClass().equals(GridDhtPartitionSupplyMessage.class)) return false; return ((GridDhtPartitionSupplyMessage)msg).groupId() == grpId; } }); }
/** * @param crd Exchange coordinator. * @param topVer Exchange topology version. */ private void blockExchangeFinish(Ignite crd, long topVer) { final AffinityTopologyVersion topVer0 = new AffinityTopologyVersion(topVer); TestRecordingCommunicationSpi.spi(crd).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() { @Override public boolean apply(ClusterNode node, Message msg) { if (msg instanceof GridDhtPartitionsFullMessage) { GridDhtPartitionsFullMessage msg0 = (GridDhtPartitionsFullMessage)msg; return msg0.exchangeId() != null && msg0.exchangeId().topologyVersion().equals(topVer0); } return false; } }); }
/** * */ private void blockRebalance() { final int grpId = groupIdForCache(ignite(0), TEST_CACHE); for (Ignite node : G.allGrids()) { testSpi(node).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() { @Override public boolean apply(ClusterNode node, Message msg) { return (msg instanceof GridDhtPartitionSupplyMessage) && ((GridCacheGroupIdMessage)msg).groupId() == grpId; } }); } }
/** * @param spi SPI. * @param topVer Exchange topology version. */ private void blockExchangeSingleMessage(TestRecordingCommunicationSpi spi, final AffinityTopologyVersion topVer) { spi.blockMessages((IgniteBiPredicate<ClusterNode, Message>)(clusterNode, msg) -> { if (msg instanceof GridDhtPartitionsSingleMessage) { GridDhtPartitionsSingleMessage pMsg = (GridDhtPartitionsSingleMessage)msg; if (pMsg.exchangeId() != null && pMsg.exchangeId().topologyVersion().equals(topVer)) return true; } return false; }); }
/** * @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); } }
spi.blockMessages((node, msg) -> { if (msg instanceof GridDhtPartitionsSingleMessage) { latch.countDown();
/** */ private static void blockProbe(IgniteEx ign, Transaction tx) { ((TestRecordingCommunicationSpi)ign.configuration().getCommunicationSpi()) .blockMessages((node, msg) -> { if (msg instanceof DeadlockProbe) { DeadlockProbe msg0 = (DeadlockProbe)msg; GridNearTxLocal tx0 = ((TransactionProxyImpl)tx).tx(); return msg0.initiatorVersion().equals(tx0.xidVersion()); } return false; }); }
/** * Blocks sending full message from coordinator to non-coordinator node. * @param from Coordinator node. * @param to Non-coordinator node. */ private void blockSendingFullMessage(IgniteEx from, IgniteEx to) { // Block FullMessage for newly joined nodes. TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(from); // Delay sending full messages (without exchange id). spi.blockMessages((node, msg) -> { if (msg instanceof GridDhtPartitionsFullMessage) { GridDhtPartitionsFullMessage fullMsg = (GridDhtPartitionsFullMessage) msg; if (fullMsg.exchangeId() != null && node.order() == to.localNode().order()) { log.warning("Blocked sending " + msg + " to " + to.localNode()); return true; } } return false; }); }
/** * @throws Exception If failed. */ private void putAllBackupFailure1() throws Exception { ccfg = cacheConfiguration(1, FULL_SYNC); startServers(4); client = true; Ignite client = startGrid(4); IgniteCache<Integer, Integer> nearCache = client.cache(TEST_CACHE); if (!blockRebalance) awaitPartitionMapExchange(); Ignite srv0 = ignite(0); List<Integer> keys = primaryKeys(srv0.cache(TEST_CACHE), 3); Ignite backup = backup(client.affinity(TEST_CACHE), keys.get(0)); testSpi(backup).blockMessages(GridDhtAtomicNearResponse.class, client.name()); Map<Integer, Integer> map = new HashMap<>(); for (Integer key : keys) map.put(key, key); log.info("Start put [map=" + map + ']'); IgniteFuture<?> fut = nearCache.putAllAsync(map); U.sleep(500); assertFalse(fut.isDone()); stopGrid(backup.name()); fut.get(); checkData(map); }
spi1.blockMessages(GridDhtPartitionsSingleMessage.class, ignite(0).name());
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { System.setProperty(IGNITE_PDS_WAL_REBALANCE_THRESHOLD, "0"); //to make all rebalance wal-based IgniteConfiguration cfg = super.getConfiguration(gridName); cfg.setConsistentId(gridName); CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(CACHE_NAME) .setAtomicityMode(CacheAtomicityMode.ATOMIC) .setRebalanceMode(CacheRebalanceMode.ASYNC) .setCacheMode(CacheMode.REPLICATED) .setAffinity(new RendezvousAffinityFunction(false, PARTS_CNT)); cfg.setCacheConfiguration(ccfg); DataStorageConfiguration dbCfg = new DataStorageConfiguration() .setWalHistorySize(Integer.MAX_VALUE) .setWalMode(WALMode.LOG_ONLY) .setCheckpointFrequency(15 * 60 * 1000) .setDefaultDataRegionConfiguration( new DataRegionConfiguration() .setPersistenceEnabled(true) .setMaxSize(DataStorageConfiguration.DFLT_DATA_REGION_INITIAL_SIZE) ); cfg.setDataStorageConfiguration(dbCfg); cfg.setCommunicationSpi(new WalRebalanceCheckingCommunicationSpi()); if (blockMessagePredicate != null) { TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) cfg.getCommunicationSpi(); spi.blockMessages(blockMessagePredicate); } return cfg; }
/** * @throws Exception If failed. */ @Test public void testPutMissedDhtRequest_UnstableTopology() throws Exception { blockRebalance = true; ccfg = cacheConfiguration(1, FULL_SYNC); startServers(4); client = true; Ignite client = startGrid(4); IgniteCache<Integer, Integer> nearCache = client.cache(TEST_CACHE); testSpi(ignite(0)).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() { @Override public boolean apply(ClusterNode node, Message msg) { return msg instanceof GridDhtAtomicAbstractUpdateRequest; } }); Integer key = primaryKey(ignite(0).cache(TEST_CACHE)); log.info("Start put [key=" + key + ']'); IgniteFuture<?> fut = nearCache.putAsync(key, key); U.sleep(500); assertFalse(fut.isDone()); stopGrid(0); fut.get(); checkData(F.asMap(key, key)); }
/** * @param atomicityMode Cache atomicity mode. * @throws Exception If failed. */ private void clientStartCoordinatorFails(CacheAtomicityMode atomicityMode) throws Exception { Ignite srv0 = startGrids(3); final int KEYS = 500; IgniteCache<Object, Object> cache = srv0.createCache(cacheConfiguration(DEFAULT_CACHE_NAME, atomicityMode, 1)); for (int i = 0; i < KEYS; i++) cache.put(i, i); client = true; final Ignite c = startGrid(3); TestRecordingCommunicationSpi.spi(srv0).blockMessages(GridDhtAffinityAssignmentResponse.class, c.name()); IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() { @Override public Void call() throws Exception { c.cache(DEFAULT_CACHE_NAME); return null; } }, "start-cache"); U.sleep(1000); assertFalse(fut.isDone()); stopGrid(0); fut.get(); cache = c.cache(DEFAULT_CACHE_NAME); for (int i = 0; i < KEYS; i++) { assertEquals(i, cache.get(i)); cache.put(i, i + 1); assertEquals(i + 1, cache.get(i)); } }
/** * Tests that idle verify print partitions info when node failing. * * @throws Exception If failed. */ @Test public void testCacheIdleVerifyDumpWhenNodeFailing() throws Exception { Ignite ignite = startGrids(3); Ignite unstable = startGrid("unstable"); ignite.cluster().active(true); createCacheAndPreload(ignite, 100); for (int i = 0; i < 3; i++) { TestRecordingCommunicationSpi.spi(unstable).blockMessages(GridJobExecuteResponse.class, getTestIgniteInstanceName(i)); } injectTestSystemOut(); IgniteInternalFuture fut = GridTestUtils.runAsync(() -> { assertEquals(EXIT_CODE_OK, execute("--cache", "idle_verify", "--dump")); }); TestRecordingCommunicationSpi.spi(unstable).waitForBlocked(); UUID unstableNodeId = unstable.cluster().localNode().id(); unstable.close(); fut.get(); checkExceptionMessageOnReport(unstableNodeId); }
/** * @throws Exception If failed. */ private void putBackupFailure1() throws Exception { ccfg = cacheConfiguration(1, FULL_SYNC); startServers(4); client = true; Ignite client = startGrid(4); IgniteCache<Integer, Integer> nearCache = client.cache(TEST_CACHE); if (!blockRebalance) awaitPartitionMapExchange(); Ignite srv0 = ignite(0); Integer key = primaryKey(srv0.cache(TEST_CACHE)); Ignite backup = backup(client.affinity(TEST_CACHE), key); testSpi(backup).blockMessages(GridDhtAtomicNearResponse.class, client.name()); log.info("Start put [key=" + key + ']'); IgniteFuture<?> fut = nearCache.putAsync(key, key); U.sleep(500); assertFalse(fut.isDone()); stopGrid(backup.name()); fut.get(); checkData(F.asMap(key, key)); }
spi.blockMessages(msgCls, prim.name());
/** * @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)); }
/** * @throws Exception If failed. */ @Test public void testPutNearNodeFailure() throws Exception { startGrids(2); client = true; Ignite clientNode = startGrid(2); final IgniteCache<Integer, Integer> nearCache = clientNode.createCache(cacheConfiguration(1, FULL_SYNC)); awaitPartitionMapExchange(); final Ignite srv0 = grid(0); final Ignite srv1 = grid(1); final Integer key = primaryKey(srv0.cache(TEST_CACHE)); nearCache.putAsync(key, key); testSpi(srv1).blockMessages(GridDhtAtomicNearResponse.class, clientNode.name()); stopGrid(2); GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { return ((IgniteKernal)srv0).context().cache().context().mvcc().atomicFuturesCount() == 0; } }, 5000); assertEquals(0, ((IgniteKernal)srv0).context().cache().context().mvcc().atomicFuturesCount()); assertEquals(0, ((IgniteKernal)srv1).context().cache().context().mvcc().atomicFuturesCount()); checkData(F.asMap(key, key)); }