use of org.apache.ignite.network.TestMessage 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.network.TestMessage in project ignite-3 by apache.
the class ItScaleCubeNetworkMessagingTest method messageWasSentToAllMembersSuccessfully.
/**
* Tests sending and receiving messages.
*
* @throws Exception in case of errors.
*/
@Test
public void messageWasSentToAllMembersSuccessfully(TestInfo testInfo) throws Exception {
Map<String, TestMessage> messageStorage = new ConcurrentHashMap<>();
var messageReceivedLatch = new CountDownLatch(3);
testCluster = new Cluster(3, testInfo);
for (ClusterService member : testCluster.members) {
member.messagingService().addMessageHandler(TestMessageTypes.class, (message, senderAddr, correlationId) -> {
messageStorage.put(member.localConfiguration().getName(), (TestMessage) message);
messageReceivedLatch.countDown();
});
}
testCluster.startAwait();
var testMessage = messageFactory.testMessage().msg("Message from Alice").build();
ClusterService alice = testCluster.members.get(0);
for (ClusterNode member : alice.topologyService().allMembers()) {
alice.messagingService().weakSend(member, testMessage);
}
boolean messagesReceived = messageReceivedLatch.await(3, TimeUnit.SECONDS);
assertTrue(messagesReceived);
testCluster.members.stream().map(member -> member.localConfiguration().getName()).map(messageStorage::get).forEach(msg -> assertThat(msg.msg(), is(testMessage.msg())));
}
use of org.apache.ignite.network.TestMessage in project ignite-3 by apache.
the class ItScaleCubeNetworkMessagingTest method testInvokeMessageToSelf.
/**
* Sends a messages from a node to itself and awaits the response.
*
* @throws Exception in case of errors.
*/
@Test
public void testInvokeMessageToSelf(TestInfo testInfo) throws Exception {
testCluster = new Cluster(1, testInfo);
testCluster.startAwait();
ClusterService member = testCluster.members.get(0);
ClusterNode self = member.topologyService().localMember();
var requestMessage = messageFactory.testMessage().msg("request").build();
var responseMessage = messageFactory.testMessage().msg("response").build();
member.messagingService().addMessageHandler(TestMessageTypes.class, (message, senderAddr, correlationId) -> {
if (message.equals(requestMessage)) {
member.messagingService().respond(self, responseMessage, correlationId);
}
});
TestMessage actualResponseMessage = member.messagingService().invoke(self, requestMessage, 1000).thenApply(TestMessage.class::cast).get(3, TimeUnit.SECONDS);
assertThat(actualResponseMessage.msg(), is(responseMessage.msg()));
}
Aggregations