/** * @param spi Near node SPI. * @param primarySpi Primary node SPI. */ private void checkNoMessages(TestRecordingCommunicationSpi spi, TestRecordingCommunicationSpi primarySpi) { List<Object> msgs = spi.recordedMessages(false); assertEquals(0, msgs.size()); msgs = primarySpi.recordedMessages(false); assertEquals(0, msgs.size()); }
/** * @param spi Near node SPI. * @param primarySpi Primary node SPI. */ private void checkMessages(TestRecordingCommunicationSpi spi, TestRecordingCommunicationSpi primarySpi) { List<Object> msgs = spi.recordedMessages(false); assertEquals(1, msgs.size()); assertTrue(msgs.get(0) instanceof GridNearSingleGetRequest); msgs = primarySpi.recordedMessages(false); assertEquals(1, msgs.size()); assertTrue(msgs.get(0) instanceof GridNearSingleGetResponse); }
/** * Method checks that there were no rebalance for all caches (excluding sys cache). */ private void checkNoRebalanceAfterRecovery() { int sysCacheGroupId = CU.cacheId(GridCacheUtils.UTILITY_CACHE_NAME); List<Ignite> nodes = G.allGrids(); for (final Ignite node : nodes) { TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(node); Set<Integer> mvccCaches = ((IgniteEx) node).context().cache().cacheGroups().stream() .flatMap(group -> group.caches().stream()) .filter(cache -> cache.config().getAtomicityMode() == CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT) .map(GridCacheContext::groupId) .collect(Collectors.toSet()); List<Integer> rebalancedGroups = spi.recordedMessages(true).stream() .map(msg -> (GridDhtPartitionDemandMessage) msg) .map(GridCacheGroupIdMessage::groupId) .filter(grpId -> grpId != sysCacheGroupId) //TODO: remove following filter when failover for MVCC will be fixed. .filter(grpId -> !mvccCaches.contains(grpId)) .distinct() .collect(Collectors.toList()); Assert.assertTrue("There was unexpected rebalance for some groups" + " [node=" + node.name() + ", groups=" + rebalancedGroups + ']', rebalancedGroups.isEmpty()); } }
/** * @param crdIdx Coordinator node index. */ private void checkFullMessages(int crdIdx) { TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi)ignite(crdIdx).configuration().getCommunicationSpi(); List<Object> msgs = commSpi0.recordedMessages(false); assertTrue(!msgs.isEmpty()); for (Object msg : msgs) { assertTrue("Unexpected messages: " + msg, msg instanceof GridDhtPartitionsFullMessage); checkFullMessage((GridDhtPartitionsFullMessage)msg); } }
/** * @param ignite Node. * @param ccfg Cache configuration. * @param backupKey Backup key. * @param nearKey Near key. * @throws Exception If failed. */ private void checkLocalRead(Ignite ignite, CacheConfiguration<Object, Object> ccfg, Integer backupKey, Integer nearKey) throws Exception { IgniteCache<Integer, Integer> cache = ignite.cache(ccfg.getName()); TestRecordingCommunicationSpi spi = recordGetRequests(ignite, ccfg.getNearConfiguration() != null); List<Object> msgs; if (nearKey != null) { assertNull(cache.get(nearKey)); msgs = spi.recordedMessages(false); assertEquals(1, msgs.size()); } assertNull(cache.get(backupKey)); msgs = spi.recordedMessages(false); assertTrue(msgs.isEmpty()); }
/** * @throws Exception If failed. */ @Test public void testAutomaticPreload() throws Exception { Ignite g0 = startGrid(0); int cnt = KEY_CNT; IgniteCache<String, Integer> c0 = g0.cache(DEFAULT_CACHE_NAME); for (int i = 0; i < cnt; i++) c0.put(Integer.toString(i), i); Ignite g1 = startGrid(1); Ignite g2 = startGrid(2); U.sleep(1000); IgniteCache<String, Integer> c1 = g1.cache(DEFAULT_CACHE_NAME); IgniteCache<String, Integer> c2 = g2.cache(DEFAULT_CACHE_NAME); TestRecordingCommunicationSpi spi0 = (TestRecordingCommunicationSpi)g0.configuration().getCommunicationSpi(); TestRecordingCommunicationSpi spi1 = (TestRecordingCommunicationSpi)g1.configuration().getCommunicationSpi(); TestRecordingCommunicationSpi spi2 = (TestRecordingCommunicationSpi)g2.configuration().getCommunicationSpi(); info(spi0.recordedMessages(false).size() + " " + spi1.recordedMessages(false).size() + " " + spi2.recordedMessages(false).size()); checkCache(c0, cnt); checkCache(c1, cnt); checkCache(c2, cnt); }
/** * @param exp If {@code true} there should be recorded messages. */ private void checkRecordedMessages(boolean exp) { for (Ignite node : G.allGrids()) { List<Object> recorded = TestRecordingCommunicationSpi.spi(node).recordedMessages(false); if (exp) assertFalse(F.isEmpty(recorded)); else assertTrue(F.isEmpty(recorded)); } }
/** * @param nodes Number of nodes. * @param ccfg Cache configuration. * @throws Exception If failed. */ private void checkLocalRead(int nodes, CacheConfiguration<Object, Object> ccfg) throws Exception { for (int i = 0; i < nodes; i++) { Ignite ignite = ignite(i); log.info("Check node: " + ignite.name()); IgniteCache<Integer, Integer> cache = ignite.cache(ccfg.getName()); List<Integer> backupKeys = backupKeys(cache, 2, 0); Integer backupKey = backupKeys.get(0); Integer nearKey = ccfg.getCacheMode() == PARTITIONED ? nearKey(cache) : null; checkLocalRead(ignite, ccfg, backupKey, nearKey); Set<Integer> keys = new HashSet<>(backupKeys); Map<Integer, Integer> vals = cache.getAll(keys); for (Integer key : keys) assertNull(vals.get(key)); TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi)ignite.configuration().getCommunicationSpi(); List<Object> msgs = spi.recordedMessages(false); assertEquals(0, msgs.size()); } }
/** * @param crdIdx Coordinator node index. */ private void checkSingleMessages(int crdIdx) { int cnt = 0; for (Ignite ignite : Ignition.allGrids()) { if (getTestIgniteInstanceName(crdIdx).equals(ignite.name()) || ignite.configuration().isClientMode()) continue; TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi)ignite.configuration().getCommunicationSpi(); List<Object> msgs = commSpi0.recordedMessages(false); assertTrue(!msgs.isEmpty()); for (Object msg : msgs) { assertTrue("Unexpected messages: " + msg, msg instanceof GridDhtPartitionsSingleMessage); checkSingleMessage((GridDhtPartitionsSingleMessage)msg); } cnt++; } assertTrue(cnt > 0); }
List<Object> srvMsgs = commSpi0.recordedMessages(true); List<Object> clientMsgs = commSpiClient.recordedMessages(true);
List<Object> msgs = newNodeSpi.recordedMessages(false);
(TestRecordingCommunicationSpi)ignite(0).configuration().getCommunicationSpi(); Collection<GridNearLockRequest> reqs = (Collection)comm.recordedMessages(false);
List<Object> msgs = spi.recordedMessages(false);
List<Object> msgs = commSpiClient.recordedMessages(true); msgs = commSpi0.recordedMessages(true);
List<Object> msgs = commSpi0.recordedMessages(true);