/** {@inheritDoc} */ @Override public void simulateNodeFailure() { super.simulateNodeFailure(); } }
@Override public void apply(TcpDiscoveryAbstractMessage msg) { if (msg instanceof TcpDiscoveryNodeAddedMessage) { discoMap.get(g.name()).simulateNodeFailure(); throw new RuntimeException("Avoid message sending: " + msg.getClass()); } } });
@Override public void apply(TcpDiscoveryAbstractMessage msg) { if (msg instanceof TcpDiscoveryNodeLeftMessage) { discoMap.get(g.name()).simulateNodeFailure(); throw new RuntimeException("Avoid message sending: " + msg.getClass()); } } });
/** * @param idx Index. */ private void failServer(int idx) { ((TcpDiscoverySpi)G.ignite("server-" + idx).configuration().getDiscoverySpi()).simulateNodeFailure(); }
/** * @param idx Index. */ private void failClient(int idx) { ((TcpDiscoverySpi)G.ignite("client-" + idx).configuration().getDiscoverySpi()).simulateNodeFailure(); }
/** * @throws Exception If any error occurs. */ @Test public void testOrdinaryNodeFailure() throws Exception { try { Ignite g1 = startGrid(1); Ignite g2 = startGrid(2); Ignite g3 = startGrid(3); final CountDownLatch cnt = new CountDownLatch(2); g1.events().localListen( new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { cnt.countDown(); return true; } }, EventType.EVT_NODE_FAILED ); info("Nodes were started"); discoMap.get(g2.name()).simulateNodeFailure(); discoMap.get(g3.name()).simulateNodeFailure(); assert cnt.await(25, SECONDS); } finally { stopAllGrids(); } }
/** * @throws Exception If any error occurs. */ @Test public void testCoordinatorNodeFailure() throws Exception { try { Ignite g1 = startGrid(1); Ignite g2 = startGrid(2); final CountDownLatch cnt = new CountDownLatch(1); g2.events().localListen(new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { cnt.countDown(); return true; } }, EventType.EVT_NODE_FAILED); info("Nodes were started"); discoMap.get(g1.name()).simulateNodeFailure(); assert cnt.await(20, SECONDS); } finally { stopAllGrids(); } }
/** * @throws Exception If any error occurs. */ private void testFailureDetectionOnNodePing(Ignite pingingNode, Ignite failedNode) throws Exception { final CountDownLatch cnt = new CountDownLatch(1); final UUID failedNodeId = failedNode.cluster().localNode().id(); pingingNode.events().localListen( new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { cnt.countDown(); return true; } }, EventType.EVT_NODE_FAILED ); info("Nodes were started"); discoMap.get(failedNode.name()).simulateNodeFailure(); TcpDiscoverySpi spi = discoMap.get(pingingNode.name()); boolean res = spi.pingNode(failedNodeId); assertFalse("Ping is ok for node " + failedNodeId + ", but had to fail.", res); // Metrics update interval is 40 seconds, but we should detect node failure faster. assert cnt.await(7, SECONDS); }
/** * */ private void doFailNodes(boolean simulateNodeFailure) throws Exception { startGrids(5); grid(0).events().enabledEvents(); failedNodes = new HashSet<>(Arrays.asList(grid(3).cluster().localNode(), grid(4).cluster().localNode())); CountDownLatch latch = new CountDownLatch(failedNodes.size()); grid(0).events().localListen(e -> { DiscoveryEvent evt = (DiscoveryEvent)e; if (failedNodes.contains(evt.eventNode())) latch.countDown(); return true; }, EventType.EVT_NODE_FAILED); compromisedNode = (TcpDiscoveryNode)grid(2).localNode(); for (int i = 3; i < 5; i++) failedAddrs.addAll(((TcpDiscoveryNode)grid(i).localNode()).socketAddresses()); System.out.println(">> Start failing nodes"); forceFailConnectivity = true; if (simulateNodeFailure) { for (int i = 3; i < 5; i++) ((TcpDiscoverySpi)grid(i).configuration().getDiscoverySpi()).simulateNodeFailure(); } assert latch.await(waitTime(), TimeUnit.MILLISECONDS); assertEquals(3, grid(0).cluster().forServers().nodes().size()); }
final CountDownLatch latch = new CountDownLatch(1); clientSpi.simulateNodeFailure();