use of org.apache.ignite.network.ClusterNode 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())));
}
use of org.apache.ignite.network.ClusterNode 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()));
}
use of org.apache.ignite.network.ClusterNode in project ignite-3 by apache.
the class RendezvousAffinityFunction method neighbors.
/**
* Builds neighborhood map for all nodes in snapshot.
*
* @param topSnapshot Topology snapshot.
* @return Neighbors map.
*/
public static Map<String, Collection<ClusterNode>> neighbors(Collection<ClusterNode> topSnapshot) {
Map<String, Collection<ClusterNode>> macMap = new HashMap<>(topSnapshot.size(), 1.0f);
// Group by mac addresses.
for (ClusterNode node : topSnapshot) {
String macs = String.valueOf(node.hashCode());
// node.attribute(IgniteNodeAttributes.ATTR_MACS);
Collection<ClusterNode> nodes = macMap.get(macs);
if (nodes == null) {
macMap.put(macs, nodes = new HashSet<>());
}
nodes.add(node);
}
Map<String, Collection<ClusterNode>> neighbors = new HashMap<>(topSnapshot.size(), 1.0f);
for (Collection<ClusterNode> group : macMap.values()) {
for (ClusterNode node : group) {
neighbors.put(node.id(), group);
}
}
return neighbors;
}
use of org.apache.ignite.network.ClusterNode in project ignite-3 by apache.
the class RendezvousAffinityFunction method replicatedAssign.
/**
* Creates assignment for REPLICATED table.
*
* @param nodes Topology.
* @param sortedNodes Sorted for specified partitions nodes.
* @return Assignment.
*/
private static List<ClusterNode> replicatedAssign(List<ClusterNode> nodes, Iterable<ClusterNode> sortedNodes) {
ClusterNode first = sortedNodes.iterator().next();
List<ClusterNode> res = new ArrayList<>(nodes.size());
res.add(first);
for (ClusterNode n : nodes) {
if (!n.equals(first)) {
res.add(n);
}
}
assert res.size() == nodes.size() : "Not enough replicas: " + res.size();
return res;
}
use of org.apache.ignite.network.ClusterNode in project ignite-3 by apache.
the class AffinityServiceTest method testCalculatedAssignmentHappyPath.
@Test
public void testCalculatedAssignmentHappyPath() {
List<List<ClusterNode>> assignments = AffinityUtils.calculateAssignments(Arrays.asList(new ClusterNode(UUID.randomUUID().toString(), "node0", new NetworkAddress("localhost", 8080)), new ClusterNode(UUID.randomUUID().toString(), "node1", new NetworkAddress("localhost", 8081))), 10, 3);
assertEquals(10, assignments.size());
for (List<ClusterNode> partitionAssignment : assignments) {
assertEquals(2, partitionAssignment.size());
}
}
Aggregations