/** {@inheritDoc} */ @Override public long getTopologyVersion() { return cluster.ignite().cluster().topologyVersion(); }
/** * Check if specified grid instances have unexpected topology version. * * @param expTopVer Expected topology version. * @param ignites Grid instances for checking topology version. */ private static void assertTopVer(long expTopVer, Ignite... ignites) { for (Ignite g : ignites) assertEquals("Grid has wrong topology version.", expTopVer, g.cluster().topologyVersion()); } }
/** * Sets baseline topology. */ public void resetBaselineTopology() { Ignite node = G.allGrids().get(0); node.cluster().setBaselineTopology(node.cluster().topologyVersion()); }
/** {@inheritDoc} */ @Override public Long test() { assertFalse(ignite.cluster().localNode().isClient()); return ignite.cluster().topologyVersion(); } }
/** * @param persistence If {@code true}, then persistence will be enabled. * @param staticDeploy If {@code true}, then static deployment will be used instead of a dynamic one. * @throws Exception If failed. */ private void checkDeploymentFromOutsideNode(boolean persistence, boolean staticDeploy) throws Exception { this.persistence = persistence; Ignite insideNode = startGrid(0); if (persistence) insideNode.cluster().active(true); else { IgniteCluster cluster = insideNode.cluster(); cluster.setBaselineTopology(cluster.topologyVersion()); } CountDownLatch exeLatch = new CountDownLatch(1); DummyService.exeLatch(SERVICE_NAME, exeLatch); deployServiceFromNewNode(staticDeploy); assertTrue(exeLatch.await(10, TimeUnit.SECONDS)); }
/** * @param expCnt Expected number of nodes. */ private void checkNodes(int expCnt) { assertEquals(expCnt, G.allGrids().size()); long topVer = -1L; for (Ignite ignite : G.allGrids()) { log.info("Check node: " + ignite.name()); if (topVer == -1L) topVer = ignite.cluster().topologyVersion(); else assertEquals("Unexpected topology version for node: " + ignite.name(), topVer, ignite.cluster().topologyVersion()); assertEquals("Unexpected number of nodes for node: " + ignite.name(), expCnt, ignite.cluster().nodes().size()); } }
/** * @param expCnt Expected number of nodes. */ private void checkNodes(int expCnt) { assertEquals(expCnt, G.allGrids().size()); long topVer = -1L; for (Ignite ignite : G.allGrids()) { log.info("Check node: " + ignite.name()); if (topVer == -1L) topVer = ignite.cluster().topologyVersion(); else assertEquals("Unexpected topology version for node: " + ignite.name(), topVer, ignite.cluster().topologyVersion()); assertEquals("Unexpected number of nodes for node: " + ignite.name(), expCnt, ignite.cluster().nodes().size()); } } }
/** * @throws Exception If failed */ @Test public void testNodeShutdownOnRingMessageWorkerStartNotFinished() throws Exception { try { Ignite ignite0 = startGrid(0); TestMessageWorkerFailureSpi2 spi0 = new TestMessageWorkerFailureSpi2(); nodeSpi.set(spi0); try { startGrid(1); fail(); } catch (Exception e) { log.error("Expected error: " + e, e); } Ignite ignite1 = startGrid(1); assertEquals(2, ignite1.cluster().nodes().size()); assertEquals(4, ignite1.cluster().topologyVersion()); assertEquals(2, ignite0.cluster().nodes().size()); assertEquals(4, ignite0.cluster().topologyVersion()); } finally { stopAllGrids(); } }
/** * @param srvCnt Number of server nodes. * @param clientCnt Number of client nodes. */ protected void checkNodes(int srvCnt, int clientCnt) { long topVer = -1; for (int i = 0; i < srvCnt; i++) { Ignite g = G.ignite("server-" + i); assertTrue(srvNodeIds.contains(g.cluster().localNode().id())); assertFalse(g.cluster().localNode().isClient()); checkRemoteNodes(g, srvCnt + clientCnt - 1); if (topVer < 0) topVer = g.cluster().topologyVersion(); else assertEquals(topVer, g.cluster().topologyVersion()); } for (int i = 0; i < clientCnt; i++) { Ignite g = G.ignite("client-" + i); ((TcpDiscoverySpi)g.configuration().getDiscoverySpi()).waitForClientMessagePrecessed(); assertTrue(clientNodeIds.contains(g.cluster().localNode().id())); assertTrue(g.cluster().localNode().isClient()); checkRemoteNodes(g, srvCnt + clientCnt - 1); if (topVer < 0) topVer = g.cluster().topologyVersion(); else assertEquals(topVer, g.cluster().topologyVersion()); } }
/** * Test baseline set by topology version works via control.sh * * @throws Exception If failed. */ @Test public void testBaselineVersion() throws Exception { Ignite ignite = startGrids(1); assertFalse(ignite.cluster().active()); ignite.cluster().active(true); startGrid(2); assertEquals(EXIT_CODE_OK, execute("--baseline")); assertEquals(EXIT_CODE_OK, execute("--baseline", "version", String.valueOf(ignite.cluster().topologyVersion()))); assertEquals(2, ignite.cluster().currentBaselineTopology().size()); }
/** * @param from If {@code true}, then added node will be an initiator of deployment. * Otherwise deployment <b>to</b> this node will be tested. * @throws Exception If failed. */ private void checkDeployWithNodeAddedToBlt(boolean from) throws Exception { persistence = true; Ignite insideNode = startGrid(0); IgniteCluster cluster = insideNode.cluster(); cluster.active(true); Ignite outsideNode = startGrid(1); cluster.setBaselineTopology(cluster.topologyVersion()); CountDownLatch exeLatch = new CountDownLatch(from ? 1 : 2); DummyService.exeLatch(SERVICE_NAME, exeLatch); if (from) { IgniteFuture<Void> depFut = outsideNode.services().deployClusterSingletonAsync(SERVICE_NAME, new DummyService()); depFut.get(10, TimeUnit.SECONDS); } else { IgniteFuture<Void> depFut = outsideNode.services().deployNodeSingletonAsync(SERVICE_NAME, new DummyService()); depFut.get(10, TimeUnit.SECONDS); } assertTrue(exeLatch.await(10, TimeUnit.SECONDS)); }
/** * @param from If {@code true}, then added node will be an initiator of deployment. * Otherwise deployment <b>to</b> this node will be tested. * @param staticDeploy If {@code true}, then static deployment will be used instead of a dynamic one. * @throws Exception If failed. */ private void checkDeployFromNodeRemovedFromBlt(boolean from, boolean staticDeploy) throws Exception { persistence = true; Ignite insideNode = startGrid(0); startGrid(1); IgniteCluster cluster = insideNode.cluster(); cluster.active(true); stopGrid(1); cluster.setBaselineTopology(cluster.topologyVersion()); CountDownLatch exeLatch = new CountDownLatch(from ? 1 : 2); DummyService.exeLatch(SERVICE_NAME, exeLatch); if (from) deployServiceFromNewNode(staticDeploy); else { startGrid(1); IgniteFuture<Void> depFut = insideNode.services().deployNodeSingletonAsync(SERVICE_NAME, new DummyService()); depFut.get(10, TimeUnit.SECONDS); } assertTrue(exeLatch.await(10, TimeUnit.SECONDS)); }
srv1.cluster().setBaselineTopology(srv1.cluster().topologyVersion());
/** * @throws Exception If any error occurs. */ @Test public void testNodeAdded() throws Exception { try { // Add grid #1 final Ignite g1 = startGrid(1); assertTopVer(1, g1); assertEquals(1, g1.cluster().topologyVersion()); // Add grid # 2 final Ignite g2 = startGrid(2); assertTopVer(2, g1, g2); for (int i = 1; i <= 2; i++) assertEquals(i, g2.cluster().topology(i).size()); // Add grid # 3 final Ignite g3 = startGrid(3); assertTopVer(3, g1, g2, g3); for (int i = 1; i <= 3; i++) assertEquals(i, g3.cluster().topology(i).size()); } finally { stopAllGrids(); } }
/** * @param seg Cluster segment. * @param topVer Topology version to wait for. */ protected void awaitExchangeVersionFinished(Collection<Ignite> seg, long topVer) { AffinityTopologyVersion waitTopVer = new AffinityTopologyVersion(topVer, 0); for (Ignite grid : seg) { IgniteInternalFuture<?> exchFut = ((IgniteEx)grid).context().cache().context().exchange().affinityReadyFuture(waitTopVer); if (exchFut != null && !exchFut.isDone()) { try { if (log.isDebugEnabled()) log.debug("Waiting for topology exchange future [grid=" + grid.name() + ", ver=" + topVer + ", curTopVer=" + grid.cluster().topologyVersion() + "]" ); exchFut.get(); } catch (IgniteCheckedException e) { log.error("Failed to wait for exchange [topVer=" + waitTopVer + ", node=" + grid.name() + ']', e); } } if (log.isDebugEnabled()) log.debug("Finished topology exchange future [grid=" + grid.name() + ", curTopVer=" + grid.cluster().topologyVersion() + "]" ); } }
/** * IgniteCluster::setBaselineTopology(long topVer) should throw an exception * when online node from current BaselineTopology is not presented in topology version. */ @Test public void testBltChangeTopVerRemoveOnlineNodeFails() throws Exception { Ignite ignite = startGridWithConsistentId("A"); ignite.cluster().active(true); long singleNodeTopVer = ignite.cluster().topologyVersion(); startGridWithConsistentId("OnlineConsID"); ignite.cluster().setBaselineTopology(baselineNodes(ignite.cluster().forServers().nodes())); boolean expectedExceptionThrown = false; try { ignite.cluster().setBaselineTopology(singleNodeTopVer); } catch (IgniteException e) { String errMsg = e.getMessage(); assertTrue(errMsg.startsWith("Removing online nodes")); assertTrue(errMsg.contains("[OnlineConsID]")); expectedExceptionThrown = true; } assertTrue(expectedExceptionThrown); }
/** * @throws Exception If any error occurs. */ @Test public void testNodeAddedAndRemoved() throws Exception { try { // Add grid #1 final Ignite g1 = startGrid(1); assertTopVer(1, g1); assertEquals(1, g1.cluster().topologyVersion()); // Add grid #2 final Ignite g2 = startGrid(2); assertTopVer(2, g1, g2); for (int i = 1; i <= 2; i++) assertEquals(i, g2.cluster().topology(i).size()); // Add grid #3 final Ignite g3 = startGrid(3); assertTopVer(3, g1, g2, g3); for (int i = 1; i <= 3; i++) assertEquals(i, g3.cluster().topology(i).size()); // Stop grid #3 stopGrid(g3.name()); assertTopVer(4, g1, g2); } finally { stopAllGrids(); } }
assertEquals(2L, ignite2.cluster().topologyVersion()); assertEquals(2L, ignite2.cluster().topologyVersion());
.walRebalanceVersions(grpId); Assert.assertTrue(topVers.contains(ignite.cluster().topologyVersion())); .walRebalanceVersions(grpId); Assert.assertFalse(topVers.contains(ignite.cluster().topologyVersion()));
discoveryEvent.topologySnapshot(ignite.cluster().topologyVersion(), ignite.cluster().nodes()); ctx.writeEvent(writer, discoveryEvent);