use of io.atomix.cluster.Node in project atomix by atomix.
the class RaftPerformanceTest method nextNode.
/**
* Returns the next unique member identifier.
*
* @return The next unique member identifier.
*/
private Node nextNode(Node.Type type) {
Endpoint endpoint = Endpoint.from("localhost", ++port);
Node node = Node.builder(NodeId.from(String.valueOf(++nextId))).withType(type).withEndpoint(endpoint).build();
endpointMap.put(node.id(), endpoint);
return node;
}
use of io.atomix.cluster.Node in project atomix by atomix.
the class AbstractAtomixTest method createAtomix.
/**
* Creates an Atomix instance.
*/
protected static Atomix createAtomix(Node.Type type, int id, Integer... ids) {
Node localNode = Node.builder(String.valueOf(id)).withType(type).withEndpoint(Endpoint.from("localhost", BASE_PORT + id)).build();
Collection<Node> bootstrapNodes = Stream.of(ids).map(nodeId -> Node.builder(String.valueOf(nodeId)).withType(Node.Type.CORE).withEndpoint(Endpoint.from("localhost", BASE_PORT + nodeId)).build()).collect(Collectors.toList());
return new TestAtomix.Builder().withClusterName("test").withDataDirectory(new File("target/test-logs/" + id)).withLocalNode(localNode).withBootstrapNodes(bootstrapNodes).withCorePartitions(3).withDataPartitions(// Lower number of partitions for faster testing
3).build();
}
use of io.atomix.cluster.Node in project atomix by atomix.
the class DefaultClusterEventingService method gossip.
/**
* Sends a gossip message to an active peer.
*/
private void gossip() {
List<Node> nodes = clusterService.getNodes().stream().filter(node -> !localNodeId.equals(node.id())).filter(node -> node.getState() == Node.State.ACTIVE).collect(Collectors.toList());
if (!nodes.isEmpty()) {
Collections.shuffle(nodes);
Node node = nodes.get(0);
updateNode(node);
}
}
use of io.atomix.cluster.Node in project atomix by atomix.
the class DefaultClusterMetadataServiceTest method testSingleNodeBootstrap.
@Test
public void testSingleNodeBootstrap() throws Exception {
TestMessagingServiceFactory messagingServiceFactory = new TestMessagingServiceFactory();
ClusterMetadata clusterMetadata = buildClusterMetadata(1);
Node localNode1 = buildNode(1, Node.Type.CORE);
ManagedClusterMetadataService metadataService1 = new DefaultClusterMetadataService(clusterMetadata, messagingServiceFactory.newMessagingService(localNode1.endpoint()).start().join());
metadataService1.start().join();
assertEquals(1, metadataService1.getMetadata().bootstrapNodes().size());
Node localNode2 = buildNode(2, Node.Type.CORE);
ManagedClusterMetadataService metadataService2 = new DefaultClusterMetadataService(clusterMetadata, messagingServiceFactory.newMessagingService(localNode2.endpoint()).start().join());
metadataService2.start().join();
metadataService2.addNode(localNode2);
assertEquals(2, metadataService2.getMetadata().bootstrapNodes().size());
}
use of io.atomix.cluster.Node in project atomix by atomix.
the class DefaultClusterMetadataServiceTest method testClusterMetadataService.
@Test
public void testClusterMetadataService() throws Exception {
TestMessagingServiceFactory messagingServiceFactory = new TestMessagingServiceFactory();
ClusterMetadata clusterMetadata = buildClusterMetadata(1, 2, 3);
Node localNode1 = buildNode(1, Node.Type.CORE);
ManagedClusterMetadataService metadataService1 = new DefaultClusterMetadataService(clusterMetadata, messagingServiceFactory.newMessagingService(localNode1.endpoint()).start().join());
Node localNode2 = buildNode(2, Node.Type.CORE);
ManagedClusterMetadataService metadataService2 = new DefaultClusterMetadataService(clusterMetadata, messagingServiceFactory.newMessagingService(localNode2.endpoint()).start().join());
Node localNode3 = buildNode(3, Node.Type.CORE);
ManagedClusterMetadataService metadataService3 = new DefaultClusterMetadataService(clusterMetadata, messagingServiceFactory.newMessagingService(localNode3.endpoint()).start().join());
List<CompletableFuture<ClusterMetadataService>> futures = new ArrayList<>();
futures.add(metadataService1.start());
futures.add(metadataService2.start());
futures.add(metadataService3.start());
Futures.allOf(futures).join();
assertEquals(3, metadataService1.getMetadata().bootstrapNodes().size());
assertEquals(3, metadataService2.getMetadata().bootstrapNodes().size());
assertEquals(3, metadataService3.getMetadata().bootstrapNodes().size());
Node localNode4 = buildNode(4, Node.Type.CORE);
ManagedClusterMetadataService metadataService4 = new DefaultClusterMetadataService(clusterMetadata, messagingServiceFactory.newMessagingService(localNode4.endpoint()).start().join());
metadataService4.start().join();
assertEquals(3, metadataService4.getMetadata().bootstrapNodes().size());
TestClusterMetadataEventListener localEventListener = new TestClusterMetadataEventListener();
metadataService4.addListener(localEventListener);
TestClusterMetadataEventListener remoteEventListener1 = new TestClusterMetadataEventListener();
metadataService1.addListener(remoteEventListener1);
TestClusterMetadataEventListener remoteEventListener2 = new TestClusterMetadataEventListener();
metadataService2.addListener(remoteEventListener2);
TestClusterMetadataEventListener remoteEventListener3 = new TestClusterMetadataEventListener();
metadataService3.addListener(remoteEventListener3);
metadataService4.addNode(localNode4);
assertEquals(4, metadataService4.getMetadata().bootstrapNodes().size());
assertEquals(4, localEventListener.event().subject().bootstrapNodes().size());
assertEquals(4, remoteEventListener1.event().subject().bootstrapNodes().size());
assertEquals(4, metadataService1.getMetadata().bootstrapNodes().size());
assertEquals(4, remoteEventListener2.event().subject().bootstrapNodes().size());
assertEquals(4, metadataService2.getMetadata().bootstrapNodes().size());
assertEquals(4, remoteEventListener3.event().subject().bootstrapNodes().size());
assertEquals(4, metadataService3.getMetadata().bootstrapNodes().size());
Node localNode5 = buildNode(5, Node.Type.CORE);
ManagedClusterMetadataService metadataService5 = new DefaultClusterMetadataService(clusterMetadata, messagingServiceFactory.newMessagingService(localNode5.endpoint()).start().join());
metadataService5.start().join();
assertEquals(4, metadataService5.getMetadata().bootstrapNodes().size());
}
Aggregations