use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class GridProjectionForCachesSelfTest method testProjectionForClientCaches.
/**
* @throws Exception If failed.
*/
@Test
public void testProjectionForClientCaches() throws Exception {
ClusterGroup prj = ignite.cluster().forClientNodes(CACHE_NAME);
assert prj != null;
assertEquals("Invalid projection: " + prj.nodes(), 1, prj.nodes().size());
assert prj.nodes().contains(grid(1).localNode());
}
use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class ClusterGroupAbstractTest method testInvalidProjection.
/**
* Test for projection on not existing node IDs.
*/
@Test
public void testInvalidProjection() {
Collection<UUID> ids = new HashSet<>();
ids.add(UUID.randomUUID());
ids.add(UUID.randomUUID());
ClusterGroup invalidPrj = prj.forNodeIds(ids);
assertEquals(0, invalidPrj.nodes().size());
}
use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class ClusterGroupAbstractTest method testRemoteProjection.
/**
* @throws Exception If test failed.
*/
@Test
public void testRemoteProjection() throws Exception {
Collection<UUID> remoteNodeIds = remoteNodeIds();
ClusterGroup remotePrj = projection().forRemotes();
Collection<UUID> prjNodeIds = F.nodeIds(remotePrj.nodes());
assert prjNodeIds.size() == remoteNodeIds.size();
assert prjNodeIds.containsAll(remoteNodeIds());
assert !prjNodeIds.contains(localNodeId());
String name = "oneMoreGrid";
try {
Ignite g = startGrid(name);
UUID excludedId = g.cluster().localNode().id();
assert !F.nodeIds(remotePrj.nodes()).contains(excludedId);
} finally {
stopGrid(name);
}
}
use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class ClusterGroupSelfTest method testYoungest.
/**
* @throws Exception If failed.
*/
@Test
public void testYoungest() throws Exception {
IgniteCluster cluster = ignite.cluster();
ClusterGroup youngest = cluster.forYoungest();
ClusterNode youngestNode = grid(NODES_CNT - 1).localNode();
assertEquals(cluster.forNode(youngestNode).node(), youngest.node());
assertEqualsCollections(singleton(cluster.forNode(youngestNode).node()), cluster.nodes().stream().filter(youngest.predicate()::apply).collect(Collectors.toSet()));
stopGrid(NODES_CNT - 1);
try {
ClusterNode newYoungestNode = grid(NODES_CNT - 2).localNode();
assertEquals(cluster.forNode(newYoungestNode).node(), youngest.node());
assertEqualsCollections(singleton(cluster.forNode(newYoungestNode).node()), cluster.nodes().stream().filter(youngest.predicate()::apply).collect(Collectors.toSet()));
} finally {
startClientGrid(NODES_CNT - 1);
}
ClusterGroup emptyGrp = cluster.forAttribute("nonExistent", "val");
assertEquals(0, emptyGrp.forYoungest().nodes().size());
try (Ignite ignore = startGrid(NODES_CNT)) {
ClusterNode newYoungestNode = grid(NODES_CNT).localNode();
assertEquals(cluster.forNode(newYoungestNode).node(), youngest.node());
assertEqualsCollections(singleton(cluster.forNode(newYoungestNode).node()), cluster.nodes().stream().filter(youngest.predicate()::apply).collect(Collectors.toSet()));
}
}
use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class ClusterNodeMetricsUpdateTest method checkMetrics0.
/**
* @param expNodes Expected nodes.
* @param expJobs Expected jobs number per node.
*/
private void checkMetrics0(int expNodes, Map<UUID, Integer> expJobs) {
List<Ignite> nodes = Ignition.allGrids();
assertEquals(expNodes, nodes.size());
assertEquals(expNodes, expJobs.size());
int totalJobs = 0;
for (Integer c : expJobs.values()) totalJobs += c;
for (final Ignite ignite : nodes) {
ClusterMetrics m = ignite.cluster().metrics();
assertEquals(expNodes, m.getTotalNodes());
assertEquals(totalJobs, m.getTotalExecutedJobs());
for (Map.Entry<UUID, Integer> e : expJobs.entrySet()) {
UUID nodeId = e.getKey();
ClusterGroup g = ignite.cluster().forNodeId(nodeId);
ClusterMetrics nodeM = g.metrics();
assertEquals(e.getValue(), (Integer) nodeM.getTotalExecutedJobs());
}
}
}
Aggregations