Search in sources :

Example 1 with MessagingService

use of io.atomix.messaging.MessagingService in project atomix by atomix.

the class RaftPerformanceTest method createClient.

/**
 * Creates a Raft client.
 */
private RaftClient createClient() throws Exception {
    Node node = nextNode(Node.Type.CLIENT);
    RaftClientProtocol protocol;
    if (USE_NETTY) {
        MessagingService messagingService = NettyMessagingService.builder().withEndpoint(node.endpoint()).build().start().join();
        protocol = new RaftClientMessagingProtocol(messagingService, protocolSerializer, endpointMap::get);
    } else {
        protocol = protocolFactory.newClientProtocol(node.id());
    }
    RaftClient client = RaftClient.builder().withNodeId(node.id()).withProtocol(protocol).withThreadModel(ThreadModel.THREAD_PER_SERVICE).build();
    client.connect(members.stream().map(Node::id).collect(Collectors.toList())).join();
    clients.add(client);
    return client;
}
Also used : RaftClientProtocol(io.atomix.protocols.raft.protocol.RaftClientProtocol) Node(io.atomix.cluster.Node) RaftClientMessagingProtocol(io.atomix.protocols.raft.protocol.RaftClientMessagingProtocol) NettyMessagingService(io.atomix.messaging.impl.NettyMessagingService) ManagedMessagingService(io.atomix.messaging.ManagedMessagingService) MessagingService(io.atomix.messaging.MessagingService)

Example 2 with MessagingService

use of io.atomix.messaging.MessagingService in project atomix by atomix.

the class RaftFuzzTest method createServer.

/**
 * Creates a Raft server.
 */
private RaftServer createServer(RaftMember member) {
    RaftServerProtocol protocol;
    if (USE_NETTY) {
        try {
            Endpoint endpoint = new Endpoint(InetAddress.getLocalHost(), ++port);
            MessagingService messagingManager = NettyMessagingService.builder().withEndpoint(endpoint).build().start().join();
            messagingServices.add(messagingManager);
            endpointMap.put(member.nodeId(), endpoint);
            protocol = new RaftServerMessagingProtocol(messagingManager, protocolSerializer, endpointMap::get);
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }
    } else {
        protocol = protocolFactory.newServerProtocol(member.nodeId());
    }
    RaftServer.Builder builder = RaftServer.builder(member.nodeId()).withProtocol(protocol).withStorage(RaftStorage.builder().withStorageLevel(StorageLevel.DISK).withDirectory(new File(String.format("target/fuzz-logs/%s", member.nodeId()))).withSerializer(storageSerializer).withMaxSegmentSize(1024 * 1024).build()).addPrimitiveType(TestPrimitiveType.INSTANCE);
    RaftServer server = builder.build();
    servers.add(server);
    return server;
}
Also used : RaftServerProtocol(io.atomix.protocols.raft.protocol.RaftServerProtocol) RaftServerMessagingProtocol(io.atomix.protocols.raft.protocol.RaftServerMessagingProtocol) Endpoint(io.atomix.messaging.Endpoint) UnknownHostException(java.net.UnknownHostException) File(java.io.File) NettyMessagingService(io.atomix.messaging.impl.NettyMessagingService) MessagingService(io.atomix.messaging.MessagingService)

Example 3 with MessagingService

use of io.atomix.messaging.MessagingService in project atomix by atomix.

the class RaftFuzzTest method createClient.

/**
 * Creates a Raft client.
 */
private RaftClient createClient() throws Exception {
    NodeId nodeId = nextNodeId();
    RaftClientProtocol protocol;
    if (USE_NETTY) {
        Endpoint endpoint = new Endpoint(InetAddress.getLocalHost(), ++port);
        MessagingService messagingManager = NettyMessagingService.builder().withEndpoint(endpoint).build().start().join();
        endpointMap.put(nodeId, endpoint);
        protocol = new RaftClientMessagingProtocol(messagingManager, protocolSerializer, endpointMap::get);
    } else {
        protocol = protocolFactory.newClientProtocol(nodeId);
    }
    RaftClient client = RaftClient.builder().withNodeId(nodeId).withProtocol(protocol).build();
    client.connect(members.stream().map(RaftMember::nodeId).collect(Collectors.toList())).join();
    clients.add(client);
    return client;
}
Also used : RaftClientProtocol(io.atomix.protocols.raft.protocol.RaftClientProtocol) Endpoint(io.atomix.messaging.Endpoint) NodeId(io.atomix.cluster.NodeId) RaftClientMessagingProtocol(io.atomix.protocols.raft.protocol.RaftClientMessagingProtocol) NettyMessagingService(io.atomix.messaging.impl.NettyMessagingService) MessagingService(io.atomix.messaging.MessagingService)

Example 4 with MessagingService

use of io.atomix.messaging.MessagingService in project atomix by atomix.

the class DefaultClusterEventingServiceTest method testClusterEventService.

@Test
public void testClusterEventService() throws Exception {
    TestMessagingServiceFactory factory = new TestMessagingServiceFactory();
    ClusterMetadata clusterMetadata = buildClusterMetadata(1, 1, 2, 3);
    Node localNode1 = buildNode(1, Node.Type.CORE);
    MessagingService messagingService1 = factory.newMessagingService(localNode1.endpoint()).start().join();
    ClusterService clusterService1 = new DefaultClusterService(localNode1, new TestClusterMetadataService(clusterMetadata), messagingService1).start().join();
    ClusterEventingService eventService1 = new DefaultClusterEventingService(clusterService1, messagingService1).start().join();
    Node localNode2 = buildNode(2, Node.Type.CORE);
    MessagingService messagingService2 = factory.newMessagingService(localNode2.endpoint()).start().join();
    ClusterService clusterService2 = new DefaultClusterService(localNode2, new TestClusterMetadataService(clusterMetadata), messagingService2).start().join();
    ClusterEventingService eventService2 = new DefaultClusterEventingService(clusterService2, messagingService2).start().join();
    Node localNode3 = buildNode(3, Node.Type.CORE);
    MessagingService messagingService3 = factory.newMessagingService(localNode3.endpoint()).start().join();
    ClusterService clusterService3 = new DefaultClusterService(localNode3, new TestClusterMetadataService(clusterMetadata), messagingService3).start().join();
    ClusterEventingService eventService3 = new DefaultClusterEventingService(clusterService3, messagingService3).start().join();
    Thread.sleep(100);
    Set<Integer> events = new CopyOnWriteArraySet<>();
    eventService1.<String>subscribe("test1", SERIALIZER::decode, message -> {
        assertEquals(message, "Hello world!");
        events.add(1);
    }, MoreExecutors.directExecutor()).join();
    eventService2.<String>subscribe("test1", SERIALIZER::decode, message -> {
        assertEquals(message, "Hello world!");
        events.add(2);
    }, MoreExecutors.directExecutor()).join();
    eventService2.<String>subscribe("test1", SERIALIZER::decode, message -> {
        assertEquals(message, "Hello world!");
        events.add(3);
    }, MoreExecutors.directExecutor()).join();
    eventService3.broadcast("test1", "Hello world!", SERIALIZER::encode);
    Thread.sleep(100);
    assertEquals(3, events.size());
    events.clear();
    eventService3.unicast("test1", "Hello world!");
    Thread.sleep(100);
    assertEquals(1, events.size());
    assertTrue(events.contains(3));
    events.clear();
    eventService3.unicast("test1", "Hello world!");
    Thread.sleep(100);
    assertEquals(1, events.size());
    assertTrue(events.contains(1));
    events.clear();
    eventService3.unicast("test1", "Hello world!");
    Thread.sleep(100);
    assertEquals(1, events.size());
    assertTrue(events.contains(2));
    events.clear();
    eventService3.unicast("test1", "Hello world!");
    Thread.sleep(100);
    assertEquals(1, events.size());
    assertTrue(events.contains(3));
    events.clear();
    eventService1.<String, String>subscribe("test2", SERIALIZER::decode, message -> {
        events.add(1);
        return message;
    }, SERIALIZER::encode, MoreExecutors.directExecutor()).join();
    eventService2.<String, String>subscribe("test2", SERIALIZER::decode, message -> {
        events.add(2);
        return message;
    }, SERIALIZER::encode, MoreExecutors.directExecutor()).join();
    assertEquals("Hello world!", eventService3.send("test2", "Hello world!").join());
    assertEquals(1, events.size());
    assertTrue(events.contains(1));
    events.clear();
    assertEquals("Hello world!", eventService3.send("test2", "Hello world!").join());
    assertEquals(1, events.size());
    assertTrue(events.contains(2));
    events.clear();
    assertEquals("Hello world!", eventService3.send("test2", "Hello world!").join());
    assertEquals(1, events.size());
    assertTrue(events.contains(1));
}
Also used : ClusterMetadata(io.atomix.cluster.ClusterMetadata) Node(io.atomix.cluster.Node) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ClusterMetadata(io.atomix.cluster.ClusterMetadata) ClusterEventingService(io.atomix.cluster.messaging.ClusterEventingService) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Endpoint(io.atomix.messaging.Endpoint) Test(org.junit.Test) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) UnknownHostException(java.net.UnknownHostException) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) DefaultClusterService(io.atomix.cluster.impl.DefaultClusterService) List(java.util.List) MessagingService(io.atomix.messaging.MessagingService) KryoNamespaces(io.atomix.utils.serializer.KryoNamespaces) ClusterService(io.atomix.cluster.ClusterService) Serializer(io.atomix.utils.serializer.Serializer) TestClusterMetadataService(io.atomix.cluster.impl.TestClusterMetadataService) Assert.assertEquals(org.junit.Assert.assertEquals) Node(io.atomix.cluster.Node) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) ClusterEventingService(io.atomix.cluster.messaging.ClusterEventingService) MessagingService(io.atomix.messaging.MessagingService) TestClusterMetadataService(io.atomix.cluster.impl.TestClusterMetadataService) DefaultClusterService(io.atomix.cluster.impl.DefaultClusterService) ClusterService(io.atomix.cluster.ClusterService) DefaultClusterService(io.atomix.cluster.impl.DefaultClusterService) Test(org.junit.Test)

Aggregations

MessagingService (io.atomix.messaging.MessagingService)4 Endpoint (io.atomix.messaging.Endpoint)3 NettyMessagingService (io.atomix.messaging.impl.NettyMessagingService)3 Node (io.atomix.cluster.Node)2 RaftClientMessagingProtocol (io.atomix.protocols.raft.protocol.RaftClientMessagingProtocol)2 RaftClientProtocol (io.atomix.protocols.raft.protocol.RaftClientProtocol)2 UnknownHostException (java.net.UnknownHostException)2 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 ClusterMetadata (io.atomix.cluster.ClusterMetadata)1 ClusterService (io.atomix.cluster.ClusterService)1 NodeId (io.atomix.cluster.NodeId)1 DefaultClusterService (io.atomix.cluster.impl.DefaultClusterService)1 TestClusterMetadataService (io.atomix.cluster.impl.TestClusterMetadataService)1 ClusterEventingService (io.atomix.cluster.messaging.ClusterEventingService)1 ManagedMessagingService (io.atomix.messaging.ManagedMessagingService)1 RaftServerMessagingProtocol (io.atomix.protocols.raft.protocol.RaftServerMessagingProtocol)1 RaftServerProtocol (io.atomix.protocols.raft.protocol.RaftServerProtocol)1 KryoNamespaces (io.atomix.utils.serializer.KryoNamespaces)1 Serializer (io.atomix.utils.serializer.Serializer)1 File (java.io.File)1