Search in sources :

Example 1 with FieldDescriptorMessage

use of org.apache.ignite.internal.network.message.FieldDescriptorMessage 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)));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ClusterService(org.apache.ignite.network.ClusterService) NetworkMessagesFactory(org.apache.ignite.internal.network.NetworkMessagesFactory) FieldDescriptorMessage(org.apache.ignite.internal.network.message.FieldDescriptorMessage) Test(org.junit.jupiter.api.Test)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)1 NetworkMessagesFactory (org.apache.ignite.internal.network.NetworkMessagesFactory)1 FieldDescriptorMessage (org.apache.ignite.internal.network.message.FieldDescriptorMessage)1 ClusterService (org.apache.ignite.network.ClusterService)1 Test (org.junit.jupiter.api.Test)1