use of org.apache.ignite.network.ClusterService in project ignite-3 by apache.
the class ItScaleCubeNetworkMessagingTest method stopForcefully.
/**
* Find the cluster's transport and force it to stop.
*
* @param cluster Cluster to be shutdown.
* @throws Exception If failed to stop.
*/
private static void stopForcefully(ClusterService cluster) throws Exception {
Field clusterSvcImplField = cluster.getClass().getDeclaredField("val$clusterSvc");
clusterSvcImplField.setAccessible(true);
ClusterService innerClusterSvc = (ClusterService) clusterSvcImplField.get(cluster);
Field clusterImplField = innerClusterSvc.getClass().getDeclaredField("cluster");
clusterImplField.setAccessible(true);
ClusterImpl clusterImpl = (ClusterImpl) clusterImplField.get(innerClusterSvc);
Field transportField = clusterImpl.getClass().getDeclaredField("transport");
transportField.setAccessible(true);
Transport transport = (Transport) transportField.get(clusterImpl);
Method stop = transport.getClass().getDeclaredMethod("stop");
stop.setAccessible(true);
Mono<?> invoke = (Mono<?>) stop.invoke(transport);
invoke.block();
}
use of org.apache.ignite.network.ClusterService in project ignite-3 by apache.
the class ItScaleCubeNetworkMessagingTest method testInvokeDuringStop.
/**
* Tests that if the network component is stopped while waiting for a response to an "invoke" call, the corresponding future completes
* exceptionally.
*/
@Test
public void testInvokeDuringStop(TestInfo testInfo) throws InterruptedException {
testCluster = new Cluster(2, testInfo);
testCluster.startAwait();
ClusterService member0 = testCluster.members.get(0);
ClusterService member1 = testCluster.members.get(1);
// we don't register a message listener on the receiving side, so all "invoke"s should timeout
// perform two invokes to test that multiple requests can get cancelled
CompletableFuture<NetworkMessage> invoke0 = member0.messagingService().invoke(member1.topologyService().localMember(), messageFactory.testMessage().build(), 1000);
CompletableFuture<NetworkMessage> invoke1 = member0.messagingService().invoke(member1.topologyService().localMember(), messageFactory.testMessage().build(), 1000);
member0.stop();
ExecutionException e = assertThrows(ExecutionException.class, () -> invoke0.get(1, TimeUnit.SECONDS));
assertThat(e.getCause(), instanceOf(NodeStoppingException.class));
e = assertThrows(ExecutionException.class, () -> invoke1.get(1, TimeUnit.SECONDS));
assertThat(e.getCause(), instanceOf(NodeStoppingException.class));
}
use of org.apache.ignite.network.ClusterService in project ignite-3 by apache.
the class ItScaleCubeNetworkMessagingTest method testMessageGroupsHandlers.
/**
* Tests that messages from different message groups can be delivered to different sets of handlers.
*
* @throws Exception in case of errors.
*/
@Test
public void testMessageGroupsHandlers(TestInfo testInfo) throws Exception {
testCluster = new Cluster(2, testInfo);
testCluster.startAwait();
ClusterService node1 = testCluster.members.get(0);
ClusterService node2 = testCluster.members.get(1);
var testMessageFuture1 = new CompletableFuture<NetworkMessage>();
var testMessageFuture2 = new CompletableFuture<NetworkMessage>();
var networkMessageFuture = new CompletableFuture<NetworkMessage>();
// register multiple handlers for the same group
node1.messagingService().addMessageHandler(TestMessageTypes.class, (message, senderAddr, correlationId) -> assertTrue(testMessageFuture1.complete(message)));
node1.messagingService().addMessageHandler(TestMessageTypes.class, (message, senderAddr, correlationId) -> assertTrue(testMessageFuture2.complete(message)));
// register a different handle for the second group
node1.messagingService().addMessageHandler(NetworkMessageTypes.class, (message, senderAddr, correlationId) -> {
if (message instanceof FieldDescriptorMessage) {
assertTrue(networkMessageFuture.complete(message));
}
});
var testMessage = messageFactory.testMessage().msg("foo").build();
FieldDescriptorMessage networkMessage = new NetworkMessagesFactory().fieldDescriptorMessage().build();
// test that a message gets delivered to both handlers
node2.messagingService().send(node1.topologyService().localMember(), testMessage).get(1, TimeUnit.SECONDS);
// test that a message from the other group is only delivered to a single handler
node2.messagingService().send(node1.topologyService().localMember(), networkMessage).get(1, TimeUnit.SECONDS);
assertThat(testMessageFuture1, willBe(equalTo(testMessage)));
assertThat(testMessageFuture2, willBe(equalTo(testMessage)));
assertThat(networkMessageFuture, willBe(equalTo(networkMessage)));
}
use of org.apache.ignite.network.ClusterService 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.ClusterService 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