Search in sources :

Example 6 with TestMessage

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());
}
Also used : ConnectionManager(org.apache.ignite.internal.network.netty.ConnectionManager) TestMessage(org.apache.ignite.network.TestMessage) OutNetworkObject(org.apache.ignite.network.OutNetworkObject) NettySender(org.apache.ignite.internal.network.netty.NettySender) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with TestMessage

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())));
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) ClusterService(org.apache.ignite.network.ClusterService) TestMessage(org.apache.ignite.network.TestMessage) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 8 with TestMessage

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()));
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) ClusterService(org.apache.ignite.network.ClusterService) TestMessage(org.apache.ignite.network.TestMessage) Test(org.junit.jupiter.api.Test)

Aggregations

TestMessage (org.apache.ignite.network.TestMessage)8 Test (org.junit.jupiter.api.Test)7 CompletableFuture (java.util.concurrent.CompletableFuture)4 NetworkMessage (org.apache.ignite.network.NetworkMessage)4 OutNetworkObject (org.apache.ignite.network.OutNetworkObject)4 InetSocketAddress (java.net.InetSocketAddress)3 ClusterNode (org.apache.ignite.network.ClusterNode)3 ClusterService (org.apache.ignite.network.ClusterService)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ByteBuf (io.netty.buffer.ByteBuf)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 DecoderException (io.netty.handler.codec.DecoderException)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 ArrayList (java.util.ArrayList)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1