use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class ClusterGroupSelfTest method testAgeClusterGroupSerialization.
/**
* @throws Exception If failed.
*/
public void testAgeClusterGroupSerialization() throws Exception {
Marshaller marshaller = ignite.configuration().getMarshaller();
ClusterGroup grp = ignite.cluster().forYoungest();
ClusterNode node = grp.node();
byte[] arr = marshaller.marshal(grp);
ClusterGroup obj = marshaller.unmarshal(arr, null);
assertEquals(node.id(), obj.node().id());
try (Ignite ignore = startGrid()) {
obj = marshaller.unmarshal(arr, null);
assertEquals(grp.node().id(), obj.node().id());
assertFalse(node.id().equals(obj.node().id()));
}
}
use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class ClusterGroupSelfTest method testNewNodes.
/**
* @throws Exception If failed.
*/
public void testNewNodes() throws Exception {
ClusterGroup youngest = ignite.cluster().forYoungest();
ClusterGroup oldest = ignite.cluster().forOldest();
ClusterNode old = oldest.node();
ClusterNode last = youngest.node();
assertNotNull(last);
try (Ignite g = startGrid(NODES_CNT)) {
ClusterNode n = g.cluster().localNode();
ClusterNode latest = youngest.node();
assertNotNull(latest);
assertEquals(latest.id(), n.id());
assertEquals(oldest.node(), old);
}
}
use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class ClusterGroupSelfTest method testForPredicate.
/**
* @throws Exception If failed.
*/
public void testForPredicate() throws Exception {
IgnitePredicate<ClusterNode> evenP = new IgnitePredicate<ClusterNode>() {
@Override
public boolean apply(ClusterNode node) {
return node.order() % 2 == 0;
}
};
IgnitePredicate<ClusterNode> oddP = new IgnitePredicate<ClusterNode>() {
@Override
public boolean apply(ClusterNode node) {
return node.order() % 2 == 1;
}
};
ClusterGroup remotes = ignite.cluster().forRemotes();
ClusterGroup evenYoungest = remotes.forPredicate(evenP).forYoungest();
ClusterGroup evenOldest = remotes.forPredicate(evenP).forOldest();
ClusterGroup oddYoungest = remotes.forPredicate(oddP).forYoungest();
ClusterGroup oddOldest = remotes.forPredicate(oddP).forOldest();
int clusterSize = ignite.cluster().nodes().size();
assertEquals(grid(gridMaxOrder(clusterSize, true)).localNode().id(), evenYoungest.node().id());
assertEquals(grid(1).localNode().id(), evenOldest.node().id());
assertEquals(grid(gridMaxOrder(clusterSize, false)).localNode().id(), oddYoungest.node().id());
assertEquals(grid(2).localNode().id(), oddOldest.node().id());
try (Ignite g4 = startGrid(NODES_CNT);
Ignite g5 = startGrid(NODES_CNT + 1)) {
clusterSize = g4.cluster().nodes().size();
assertEquals(grid(gridMaxOrder(clusterSize, true)).localNode().id(), evenYoungest.node().id());
assertEquals(grid(1).localNode().id(), evenOldest.node().id());
assertEquals(grid(gridMaxOrder(clusterSize, false)).localNode().id(), oddYoungest.node().id());
assertEquals(grid(2).localNode().id(), oddOldest.node().id());
}
}
use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class ClusterGroupSelfTest method testEmptyGroup.
/**
* @throws Exception If failed.
*/
public void testEmptyGroup() throws Exception {
ClusterGroup emptyGrp = ignite.cluster().forAttribute("nonExistent", "val");
assertEquals(0, emptyGrp.forOldest().nodes().size());
assertEquals(0, emptyGrp.forYoungest().nodes().size());
assertEquals(0, emptyGrp.forAttribute("nonExistent2", "val").nodes().size());
assertEquals(0, emptyGrp.forCacheNodes("cacheName").nodes().size());
assertEquals(0, emptyGrp.forClientNodes("cacheName").nodes().size());
assertEquals(0, emptyGrp.forClients().nodes().size());
assertEquals(0, emptyGrp.forDaemons().nodes().size());
assertEquals(0, emptyGrp.forDataNodes("cacheName").nodes().size());
assertEquals(0, emptyGrp.forRandom().nodes().size());
assertEquals(0, emptyGrp.forRemotes().nodes().size());
assertEquals(0, emptyGrp.forServers().nodes().size());
assertEquals(0, emptyGrp.forHost(ignite.cluster().localNode()).nodes().size());
assertEquals(0, emptyGrp.forHost("127.0.0.1").nodes().size());
}
use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class ServicePredicateAccessCacheTest method testPredicateAccessCache.
/**
* @throws Exception If failed.
*/
public void testPredicateAccessCache() throws Exception {
final Ignite ignite0 = startGrid(0);
ignite0.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME).setName("testCache").setAtomicityMode(ATOMIC).setCacheMode(REPLICATED).setWriteSynchronizationMode(FULL_SYNC));
latch = new CountDownLatch(1);
final ClusterGroup grp = ignite0.cluster().forPredicate(new IgnitePredicate<ClusterNode>() {
@Override
public boolean apply(ClusterNode node) {
System.out.println("Predicated started [thread=" + Thread.currentThread().getName() + ']');
latch.countDown();
try {
Thread.sleep(3000);
} catch (InterruptedException ignore) {
// No-op.
}
System.out.println("Call contains key [thread=" + Thread.currentThread().getName() + ']');
boolean ret = Ignition.localIgnite().cache("testCache").containsKey(node.id().toString());
System.out.println("After contains key [ret=" + ret + ", thread=" + Thread.currentThread().getName() + ']');
return ret;
}
});
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
info("Start deploy service.");
ignite0.services(grp).deployNodeSingleton("testService", new TestService());
info("Service deployed.");
return null;
}
}, "deploy-thread");
latch.await();
startGrid(1);
fut.get();
}
Aggregations