use of org.apache.ignite.internal.network.netty.NettySender 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.NettySender 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.NettySender 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());
}
use of org.apache.ignite.internal.network.netty.NettySender in project ignite-3 by apache.
the class RecoveryClientHandshakeManager method onMessage.
/**
* {@inheritDoc}
*/
@Override
public HandshakeResult onMessage(Channel channel, NetworkMessage message) {
if (message instanceof HandshakeStartMessage) {
HandshakeStartMessage msg = (HandshakeStartMessage) message;
UUID remoteLaunchId = msg.launchId();
String remoteConsistentId = msg.consistentId();
HandshakeStartResponseMessage response = messageFactory.handshakeStartResponseMessage().launchId(launchId).consistentId(consistentId).receivedCount(0).connectionsCount(0).build();
ChannelFuture sendFuture = channel.writeAndFlush(new OutNetworkObject(response, Collections.emptyList()));
NettyUtils.toCompletableFuture(sendFuture).whenComplete((unused, throwable) -> {
if (throwable != null) {
handshakeCompleteFuture.completeExceptionally(new HandshakeException("Failed to send handshake response: " + throwable.getMessage(), throwable));
} else {
handshakeCompleteFuture.complete(new NettySender(channel, remoteLaunchId.toString(), remoteConsistentId));
}
});
return HandshakeResult.removeHandler(remoteLaunchId, remoteConsistentId);
}
handshakeCompleteFuture.completeExceptionally(new HandshakeException("Unexpected message during handshake: " + message.toString()));
return HandshakeResult.fail();
}
use of org.apache.ignite.internal.network.netty.NettySender in project ignite-3 by apache.
the class RecoveryServerHandshakeManager method onMessage.
/**
* {@inheritDoc}
*/
@Override
public HandshakeResult onMessage(Channel channel, NetworkMessage message) {
if (message instanceof HandshakeStartResponseMessage) {
HandshakeStartResponseMessage msg = (HandshakeStartResponseMessage) message;
UUID remoteLaunchId = msg.launchId();
String remoteConsistentId = msg.consistentId();
handshakeCompleteFuture.complete(new NettySender(channel, remoteLaunchId.toString(), remoteConsistentId));
return HandshakeResult.removeHandler(remoteLaunchId, remoteConsistentId);
}
handshakeCompleteFuture.completeExceptionally(new HandshakeException("Unexpected message during handshake: " + message.toString()));
return HandshakeResult.fail();
}
Aggregations