Search in sources :

Example 16 with ClusterService

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();
}
Also used : ClusterImpl(io.scalecube.cluster.ClusterImpl) Field(java.lang.reflect.Field) ClusterService(org.apache.ignite.network.ClusterService) Mono(reactor.core.publisher.Mono) Method(java.lang.reflect.Method) Transport(io.scalecube.cluster.transport.api.Transport)

Example 17 with ClusterService

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));
}
Also used : ClusterService(org.apache.ignite.network.ClusterService) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) NetworkMessage(org.apache.ignite.network.NetworkMessage) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test)

Example 18 with ClusterService

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)));
}
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)

Example 19 with ClusterService

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())));
}
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 20 with ClusterService

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()));
}
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

ClusterService (org.apache.ignite.network.ClusterService)42 NetworkAddress (org.apache.ignite.network.NetworkAddress)18 StaticNodeFinder (org.apache.ignite.network.StaticNodeFinder)12 Test (org.junit.jupiter.api.Test)12 ConcurrentHashMapPartitionStorage (org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage)11 VersionedRowStore (org.apache.ignite.internal.table.distributed.storage.VersionedRowStore)11 HeapLockManager (org.apache.ignite.internal.tx.impl.HeapLockManager)11 TxManagerImpl (org.apache.ignite.internal.tx.impl.TxManagerImpl)11 List (java.util.List)10 TestScaleCubeClusterServiceFactory (org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory)10 ClusterNode (org.apache.ignite.network.ClusterNode)9 MessagingService (org.apache.ignite.network.MessagingService)9 BeforeEach (org.junit.jupiter.api.BeforeEach)8 DummyInternalTableImpl (org.apache.ignite.internal.table.impl.DummyInternalTableImpl)7 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)7 TxManager (org.apache.ignite.internal.tx.TxManager)7 RaftGroupService (org.apache.ignite.raft.client.service.RaftGroupService)7 AfterEach (org.junit.jupiter.api.AfterEach)7 JraftServerImpl (org.apache.ignite.internal.raft.server.impl.JraftServerImpl)6 Peer (org.apache.ignite.raft.client.Peer)6