Search in sources :

Example 36 with TcpDiscoveryNode

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();
    }
}
Also used : TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) ArrayList(java.util.ArrayList) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)

Aggregations

TcpDiscoveryNode (org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)36 Ignite (org.apache.ignite.Ignite)12 ClusterNode (org.apache.ignite.cluster.ClusterNode)11 UUID (java.util.UUID)10 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)7 IOException (java.io.IOException)6 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)6 TcpDiscoveryVmIpFinder (org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder)6 ArrayList (java.util.ArrayList)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Event (org.apache.ignite.events.Event)5 IgniteException (org.apache.ignite.IgniteException)4 Nullable (org.jetbrains.annotations.Nullable)4 Socket (java.net.Socket)3 SocketTimeoutException (java.net.SocketTimeoutException)3 Collection (java.util.Collection)3 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)3 StreamCorruptedException (java.io.StreamCorruptedException)2 InetSocketAddress (java.net.InetSocketAddress)2