/** * @param latch Latch. * @param timeout Timeout. * @throws InterruptedException If interrupted. */ protected void await(CountDownLatch latch, long timeout) throws InterruptedException { assertTrue("Latch count: " + latch.getCount(), latch.await(timeout, MILLISECONDS)); }
/** * @param latch Latch. * @throws InterruptedException If interrupted. */ private void awaitClient(CountDownLatch latch) throws InterruptedException { assertTrue("Failed to wait for latch, latch count: " + latch.getCount(), latch.await(awaitClientTime(), MILLISECONDS)); }
/** * @param ignite Grid. * @param expCnt Expected nodes count. */ private void checkRemoteNodes(Ignite ignite, int expCnt) { Collection<ClusterNode> nodes = ignite.cluster().forRemotes().nodes(); assertEquals("Unexpected state for node: " + ignite.name(), expCnt, nodes.size()); for (ClusterNode node : nodes) { UUID id = node.id(); if (clientNodeIds.contains(id)) assertTrue(node.isClient()); else if (srvNodeIds.contains(id)) assertFalse(node.isClient()); else assert false : "Unexpected node ID: " + id; } }
/** * @throws Exception If failed. */ @Test public void testClientFailReconnectDisabled() throws Exception { reconnectDisabled = true; startServerNodes(1); startClientNodes(1); Ignite srv = G.ignite("server-0"); TestTcpDiscoverySpi srvSpi = ((TestTcpDiscoverySpi)srv.configuration().getDiscoverySpi()); Ignite client = G.ignite("client-0"); final CountDownLatch segmentedLatch = new CountDownLatch(1); client.events().localListen(new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { if (evt.type() == EVT_NODE_SEGMENTED) segmentedLatch.countDown(); return false; } }, EVT_NODE_SEGMENTED); srvFailedLatch = new CountDownLatch(1); attachListeners(1, 0); log.info("Fail client node."); srvSpi.failNode(client.cluster().localNode().id(), null); assertTrue(srvFailedLatch.await(5000, MILLISECONDS)); assertTrue(segmentedLatch.await(5000, MILLISECONDS)); checkNodes(1, 0); }
/** * @throws Exception If failed. */ @Test public void testMetrics() throws Exception { startServerNodes(3); startClientNodes(3); checkNodes(3, 3); attachListeners(3, 3); assertTrue(checkMetrics(3, 3, 0)); G.ignite("client-0").compute().broadcast(F.noop()); assertTrue(GridTestUtils.waitForCondition(new PA() { @Override public boolean apply() { return checkMetrics(3, 3, 1); } }, 10000)); checkMetrics(3, 3, 1); G.ignite("server-0").compute().broadcast(F.noop()); assertTrue(GridTestUtils.waitForCondition(new PA() { @Override public boolean apply() { return checkMetrics(3, 3, 2); } }, 10000)); }
assertTrue(disconnectLatch.await(awaitTime(), MILLISECONDS)); assertTrue(reconnectLatch.await(awaitTime(), MILLISECONDS));
assertTrue(disconnectLatch.await(5000, MILLISECONDS)); assertTrue(failLatch.await(5000, MILLISECONDS)); assertTrue(reconnectLatch.await(5000, MILLISECONDS)); assertTrue(joinLatch.await(5000, MILLISECONDS));
/** * @throws Exception If failed. */ @Test public void testClientToClientPing() throws Exception { startGrid("server-p1"); Ignite c1 = startGrid("client-p1"); startGrid("server-p2"); Ignite c2 = startGrid("client-p2"); boolean res = ((IgniteEx)c1).context().discovery().pingNode(c2.cluster().localNode().id()); assertTrue(res); }
/** * @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()); } }
/** * @throws Exception If any error occurs. */ @Test public void testGridStartTime() throws Exception { startServerNodes(2); startClientNodes(2); long startTime = -1; for (Ignite g : G.allGrids()) { IgniteEx kernal = (IgniteEx)g; assertTrue(kernal.context().discovery().gridStartTime() > 0); if (startTime == -1) startTime = kernal.context().discovery().gridStartTime(); else assertEquals(startTime, kernal.context().discovery().gridStartTime()); } }