Search in sources :

Example 1 with ConnectionManager

use of org.apache.ignite.internal.network.netty.ConnectionManager in project ignite-3 by apache.

the class ItRecoveryHandshakeTest method testHandshakeWithMultipleClients.

/**
 * Tests that one server can handle multiple incoming connections and perform the handshake operation successfully.
 *
 * @throws Exception If failed.
 */
@Test
public void testHandshakeWithMultipleClients() throws Exception {
    ConnectionManager server = startManager(4000);
    List<ConnectionManager> clients = new ArrayList<>();
    int clientCount = 10;
    for (int i = 0; i < clientCount; i++) {
        clients.add(startManager(4001 + i));
    }
    // A key is the client's consistent id, a value is the channel between the client and the server
    var channelsToServer = new HashMap<String, NettySender>();
    for (ConnectionManager client : clients) {
        channelsToServer.put(client.consistentId(), client.channel(server.consistentId(), server.getLocalAddress()).get(3, TimeUnit.SECONDS));
    }
    assertTrue(waitForCondition(() -> server.channels().size() == clientCount, TimeUnit.SECONDS.toMillis(3)));
    Map<String, NettySender> channels = server.channels();
    // Assert that server's channels are inbound connections opened from clients
    channelsToServer.forEach((consistentId, toServer) -> {
        NettySender toClient = channels.get(consistentId);
        assertNotNull(toClient);
        assertEquals(toServer.channel().localAddress(), toClient.channel().remoteAddress());
    });
}
Also used : ConnectionManager(org.apache.ignite.internal.network.netty.ConnectionManager) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NettySender(org.apache.ignite.internal.network.netty.NettySender) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ConnectionManager

use of org.apache.ignite.internal.network.netty.ConnectionManager in project ignite-3 by apache.

the class ItRecoveryHandshakeTest method testHandshakeFailsOnServerWhenClientResponded.

/**
 * Tests special handshake scenario: the client assumes a handshake has been finished, but the server fails on client's response. The
 * server will then close a connection and the client should get the "connection closed event".
 *
 * @throws Exception If failed.
 */
@Test
public void testHandshakeFailsOnServerWhenClientResponded() throws Exception {
    ConnectionManager manager1 = startManager(4000, SERVER_CLIENT_RESPONDED, CLIENT_DOESNT_FAIL);
    ConnectionManager manager2 = startManager(4001, SERVER_DOESNT_FAIL, CLIENT_DOESNT_FAIL);
    NettySender from2to1 = manager2.channel(manager1.consistentId(), manager1.getLocalAddress()).get(3, TimeUnit.SECONDS);
    from2to1.channel().closeFuture().get(3, TimeUnit.SECONDS);
}
Also used : ConnectionManager(org.apache.ignite.internal.network.netty.ConnectionManager) NettySender(org.apache.ignite.internal.network.netty.NettySender) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with ConnectionManager

use of org.apache.ignite.internal.network.netty.ConnectionManager in project ignite-3 by apache.

the class ItRecoveryHandshakeTest method startManager.

/**
 * Starts a {@link ConnectionManager} with a normal handshake manager adding it to the {@link #startedManagers} list.
 *
 * @param port Port.
 * @return Connection manager
 */
private ConnectionManager startManager(int port) {
    var registry = new TestMessageSerializationRegistryImpl();
    var serializationService = new SerializationService(registry, mock(UserObjectSerializationContext.class));
    var messageFactory = new NetworkMessagesFactory();
    UUID launchId = UUID.randomUUID();
    String consistentId = UUID.randomUUID().toString();
    networkConfiguration.port().update(port).join();
    NetworkView cfg = networkConfiguration.value();
    NettyBootstrapFactory bootstrapFactory = new NettyBootstrapFactory(networkConfiguration, consistentId);
    bootstrapFactory.start();
    startedBootstrapFactories.add(bootstrapFactory);
    var manager = new ConnectionManager(cfg, serializationService, consistentId, () -> new RecoveryServerHandshakeManager(launchId, consistentId, messageFactory), () -> new RecoveryClientHandshakeManager(launchId, consistentId, messageFactory), bootstrapFactory);
    manager.start();
    startedManagers.add(manager);
    return manager;
}
Also used : TestMessageSerializationRegistryImpl(org.apache.ignite.network.TestMessageSerializationRegistryImpl) NettyBootstrapFactory(org.apache.ignite.network.NettyBootstrapFactory) ConnectionManager(org.apache.ignite.internal.network.netty.ConnectionManager) NetworkMessagesFactory(org.apache.ignite.internal.network.NetworkMessagesFactory) SerializationService(org.apache.ignite.internal.network.serialization.SerializationService) UUID(java.util.UUID) UserObjectSerializationContext(org.apache.ignite.internal.network.serialization.UserObjectSerializationContext) NetworkView(org.apache.ignite.configuration.schemas.network.NetworkView)

Example 4 with ConnectionManager

use of org.apache.ignite.internal.network.netty.ConnectionManager in project ignite-3 by apache.

the class ItRecoveryHandshakeTest method startManager.

/**
 * Starts a {@link ConnectionManager} adding it to the {@link #startedManagers} list.
 *
 * @param port                  Port for the server.
 * @param serverHandshakeFailAt At what stage to fail server handshake.
 * @param clientHandshakeFailAt At what stage to fail client handshake.
 * @return Connection manager.
 */
private ConnectionManager startManager(int port, ServerStageFail serverHandshakeFailAt, ClientStageFail clientHandshakeFailAt) {
    var registry = new TestMessageSerializationRegistryImpl();
    var serializationService = new SerializationService(registry, mock(UserObjectSerializationContext.class));
    var messageFactory = new NetworkMessagesFactory();
    UUID launchId = UUID.randomUUID();
    String consistentId = UUID.randomUUID().toString();
    networkConfiguration.port().update(port).join();
    NetworkView cfg = networkConfiguration.value();
    NettyBootstrapFactory bootstrapFactory = new NettyBootstrapFactory(networkConfiguration, consistentId);
    bootstrapFactory.start();
    startedBootstrapFactories.add(bootstrapFactory);
    var manager = new ConnectionManager(cfg, serializationService, consistentId, () -> new FailingRecoveryServerHandshakeManager(launchId, consistentId, serverHandshakeFailAt, messageFactory), () -> new FailingRecoveryClientHandshakeManager(launchId, consistentId, clientHandshakeFailAt, messageFactory), bootstrapFactory);
    manager.start();
    startedManagers.add(manager);
    return manager;
}
Also used : TestMessageSerializationRegistryImpl(org.apache.ignite.network.TestMessageSerializationRegistryImpl) NettyBootstrapFactory(org.apache.ignite.network.NettyBootstrapFactory) ConnectionManager(org.apache.ignite.internal.network.netty.ConnectionManager) NetworkMessagesFactory(org.apache.ignite.internal.network.NetworkMessagesFactory) SerializationService(org.apache.ignite.internal.network.serialization.SerializationService) UUID(java.util.UUID) UserObjectSerializationContext(org.apache.ignite.internal.network.serialization.UserObjectSerializationContext) NetworkView(org.apache.ignite.configuration.schemas.network.NetworkView)

Example 5 with ConnectionManager

use of org.apache.ignite.internal.network.netty.ConnectionManager in project ignite-3 by apache.

the class ItRecoveryHandshakeTest method testHandshakeScenario.

/**
 * Tests handshake scenarios in which some of the parts of handshake protocol can fail.
 *
 * @param scenario Handshake scenario.
 * @throws Exception If failed.
 */
@ParameterizedTest
@MethodSource("handshakeScenarios")
public void testHandshakeScenario(HandshakeScenario scenario) throws Exception {
    ConnectionManager manager1 = startManager(4000, scenario.serverFailAt, CLIENT_DOESNT_FAIL);
    ConnectionManager manager2 = startManager(4001, SERVER_DOESNT_FAIL, scenario.clientFailAt);
    NettySender from2to1;
    try {
        from2to1 = manager2.channel(manager1.consistentId(), manager1.getLocalAddress()).get(3, TimeUnit.SECONDS);
    } catch (Exception e) {
        if (scenario.clientFailAt == CLIENT_DOESNT_FAIL && scenario.serverFailAt == SERVER_DOESNT_FAIL) {
            Assertions.fail(e);
        }
        return;
    }
    if (scenario.clientFailAt != CLIENT_DOESNT_FAIL || scenario.serverFailAt != SERVER_DOESNT_FAIL) {
        Assertions.fail("Handshake should've failed");
    }
    assertNotNull(from2to1);
    // Ensure the handshake has finished on both sides.
    TestMessage msg = messageFactory.testMessage().msg("test").build();
    from2to1.send(new OutNetworkObject(msg, Collections.emptyList())).get(3, TimeUnit.SECONDS);
    NettySender from1to2 = manager1.channel(manager2.consistentId(), manager2.getLocalAddress()).get(3, TimeUnit.SECONDS);
    assertNotNull(from1to2);
    assertEquals(from2to1.channel().localAddress(), from1to2.channel().remoteAddress());
}
Also used : ConnectionManager(org.apache.ignite.internal.network.netty.ConnectionManager) TestMessage(org.apache.ignite.network.TestMessage) OutNetworkObject(org.apache.ignite.network.OutNetworkObject) NettySender(org.apache.ignite.internal.network.netty.NettySender) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ConnectionManager (org.apache.ignite.internal.network.netty.ConnectionManager)6 UUID (java.util.UUID)3 NetworkView (org.apache.ignite.configuration.schemas.network.NetworkView)3 NetworkMessagesFactory (org.apache.ignite.internal.network.NetworkMessagesFactory)3 NettySender (org.apache.ignite.internal.network.netty.NettySender)3 SerializationService (org.apache.ignite.internal.network.serialization.SerializationService)3 UserObjectSerializationContext (org.apache.ignite.internal.network.serialization.UserObjectSerializationContext)3 NettyBootstrapFactory (org.apache.ignite.network.NettyBootstrapFactory)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 TestMessageSerializationRegistryImpl (org.apache.ignite.network.TestMessageSerializationRegistryImpl)2 Test (org.junit.jupiter.api.Test)2 ClusterConfig (io.scalecube.cluster.ClusterConfig)1 ClusterImpl (io.scalecube.cluster.ClusterImpl)1 ClusterMessageHandler (io.scalecube.cluster.ClusterMessageHandler)1 MembershipEvent (io.scalecube.cluster.membership.MembershipEvent)1 Address (io.scalecube.net.Address)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1