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());
});
}
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);
}
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;
}
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;
}
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());
}
Aggregations