use of org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode in project ignite by apache.
the class TcpClientDiscoverySpiFailureTimeoutSelfTest method clientReconnectOnCoordinatorRouterFail.
/**
* Test tries to provoke scenario when client sends reconnect message before router failure detected.
*
* @param srvNodes Number of additional server nodes.
* @throws Exception If failed.
*/
public void clientReconnectOnCoordinatorRouterFail(int srvNodes) throws Exception {
startServerNodes(1);
Ignite srv = G.ignite("server-0");
final TcpDiscoveryNode srvNode = (TcpDiscoveryNode) srv.cluster().localNode();
final UUID srvNodeId = srvNode.id();
clientIpFinder = new TcpDiscoveryVmIpFinder();
clientIpFinder.setAddresses(Collections.singleton("localhost:" + srvNode.discoveryPort() + ".." + (srvNode.discoveryPort() + 1)));
failureThreshold = 1000L;
netTimeout = 1000L;
// Client should connect to coordinator.
startClientNodes(1);
failureThreshold = 10_000L;
netTimeout = 5000L;
List<String> nodes = new ArrayList<>();
for (int i = 0; i < srvNodes; i++) {
Ignite g = startGrid("server-" + srvIdx.getAndIncrement());
nodes.add(g.name());
srvNodeIds.add(g.cluster().localNode().id());
}
checkNodes(1 + srvNodes, 1);
nodes.add("client-0");
final CountDownLatch latch = new CountDownLatch(nodes.size());
final AtomicBoolean err = new AtomicBoolean();
for (String node : nodes) {
G.ignite(node).events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
DiscoveryEvent disoEvt = (DiscoveryEvent) evt;
if (disoEvt.eventNode().id().equals(srvNodeId)) {
info("Expected node failed event: " + ((DiscoveryEvent) evt).eventNode());
latch.countDown();
} else {
log.info("Unexpected node failed event: " + evt);
err.set(true);
}
return true;
}
}, EVT_NODE_FAILED);
}
Thread.sleep(5000);
Ignite client = G.ignite("client-0");
UUID nodeId = client.cluster().localNode().id();
log.info("Fail coordinator: " + srvNodeId);
TestTcpDiscoverySpi srvSpi = (TestTcpDiscoverySpi) srv.configuration().getDiscoverySpi();
srvSpi.pauseAll(false);
try {
Thread.sleep(2000);
} finally {
srvSpi.simulateNodeFailure();
srvSpi.resumeAll();
}
try {
assertTrue(latch.await(failureThreshold + 3000, TimeUnit.MILLISECONDS));
assertFalse("Unexpected event, see log for details.", err.get());
assertEquals(nodeId, client.cluster().localNode().id());
} finally {
srvSpi.resumeAll();
}
}
Aggregations