use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class ClosureServiceClientsNodesTest method testDefaultService.
/**
* @throws Exception If failed.
*/
public void testDefaultService() throws Exception {
UUID clientNodeId = grid(0).cluster().localNode().id();
for (int i = 0; i < NODES_CNT; i++) {
log.info("Iteration: " + i);
final Ignite ignite = grid(i);
ignite.services().deployNodeSingleton(SINGLETON_NAME, new TestService());
final ClusterGroup grp = ignite.cluster();
assertEquals(NODES_CNT, grp.nodes().size());
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return ignite.services(grp).serviceDescriptors().size() == 1;
}
}, 5000);
Collection<ServiceDescriptor> srvDscs = ignite.services(grp).serviceDescriptors();
assertEquals(1, srvDscs.size());
Map<UUID, Integer> nodesMap = F.first(srvDscs).topologySnapshot();
assertEquals(NODES_CNT - 1, nodesMap.size());
for (Map.Entry<UUID, Integer> nodeInfo : nodesMap.entrySet()) {
assertFalse(clientNodeId.equals(nodeInfo.getKey()));
assertEquals(1, nodeInfo.getValue().intValue());
}
ignite.services().cancelAll();
}
}
use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class GridMessagingSelfTest method testSendReceiveMessageWithStringTopic.
/**
* Tests simple message sending-receiving with string topic.
*
* @throws Exception If error occurs.
*/
public void testSendReceiveMessageWithStringTopic() throws Exception {
final Collection<Object> rcvMsgs = new GridConcurrentHashSet<>();
//to make it modifiable
final AtomicBoolean error = new AtomicBoolean(false);
final CountDownLatch rcvLatch = new CountDownLatch(3);
ignite1.message().localListen(S_TOPIC_1, new P2<UUID, Object>() {
@Override
public boolean apply(UUID nodeId, Object msg) {
try {
log.info("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ", topic=" + S_TOPIC_1 + ']');
if (!nodeId.equals(ignite1.cluster().localNode().id())) {
log.error("Unexpected sender node: " + nodeId);
error.set(true);
return false;
}
if (!MSG_1.equals(msg)) {
log.error("Unexpected message " + msg + " for topic: " + S_TOPIC_1);
error.set(true);
return false;
}
rcvMsgs.add(msg);
return true;
} finally {
rcvLatch.countDown();
}
}
});
ignite1.message().localListen(S_TOPIC_2, new P2<UUID, Object>() {
@Override
public boolean apply(UUID nodeId, Object msg) {
try {
log.info("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ", topic=" + S_TOPIC_2 + ']');
if (!nodeId.equals(ignite1.cluster().localNode().id())) {
log.error("Unexpected sender node: " + nodeId);
error.set(true);
return false;
}
if (!MSG_2.equals(msg)) {
log.error("Unexpected message " + msg + " for topic: " + S_TOPIC_2);
error.set(true);
return false;
}
rcvMsgs.add(msg);
return true;
} finally {
rcvLatch.countDown();
}
}
});
ignite1.message().localListen(null, new P2<UUID, Object>() {
@Override
public boolean apply(UUID nodeId, Object msg) {
try {
log.info("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ", topic=default]");
if (!nodeId.equals(ignite1.cluster().localNode().id())) {
log.error("Unexpected sender node: " + nodeId);
error.set(true);
return false;
}
if (!MSG_3.equals(msg)) {
log.error("Unexpected message " + msg + " for topic: default");
error.set(true);
return false;
}
rcvMsgs.add(msg);
return true;
} finally {
rcvLatch.countDown();
}
}
});
ClusterGroup rNode1 = ignite1.cluster().forLocal();
message(rNode1).send(S_TOPIC_1, MSG_1);
message(rNode1).send(S_TOPIC_2, MSG_2);
message(rNode1).send(null, MSG_3);
assertTrue(rcvLatch.await(3, TimeUnit.SECONDS));
assertFalse(error.get());
assertTrue(rcvMsgs.contains(MSG_1));
assertTrue(rcvMsgs.contains(MSG_2));
assertTrue(rcvMsgs.contains(MSG_3));
}
use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class GridMessagingSelfTest method testRemoteListen.
/**
* Tests simple message sending-receiving with the use of
* remoteListen() method.
*
* @throws Exception If error occurs.
*/
public void testRemoteListen() throws Exception {
final Collection<Object> rcvMsgs = new GridConcurrentHashSet<>();
rcvLatch = new CountDownLatch(4);
ignite2.message().remoteListen(null, new P2<UUID, Object>() {
@Override
public boolean apply(UUID nodeId, Object msg) {
try {
log.info("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']');
rcvMsgs.add(msg);
return true;
} finally {
rcvLatch.countDown();
}
}
});
// Includes node from grid2.
ClusterGroup prj2 = ignite1.cluster().forRemotes();
message(prj2).send(null, MSG_1);
message(prj2).send(null, MSG_2);
message(ignite2.cluster().forLocal()).send(null, MSG_3);
// We should get only 3 message.
assertFalse(rcvLatch.await(3, TimeUnit.SECONDS));
assertTrue(rcvMsgs.contains(MSG_1));
assertTrue(rcvMsgs.contains(MSG_2));
assertTrue(rcvMsgs.contains(MSG_3));
}
use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class GridMessagingSelfTest method testRemoteListenWithIntTopic.
/**
* Tests simple message sending-receiving with the use of
* remoteListen() method and topics.
*
* @throws Exception If error occurs.
*/
public void testRemoteListenWithIntTopic() throws Exception {
final Collection<Object> rcvMsgs = new GridConcurrentHashSet<>();
//to make it modifiable
final AtomicBoolean error = new AtomicBoolean(false);
rcvLatch = new CountDownLatch(3);
ignite2.message().remoteListen(I_TOPIC_1, new P2<UUID, Object>() {
@IgniteInstanceResource
private transient Ignite g;
@Override
public boolean apply(UUID nodeId, Object msg) {
assertEquals(ignite2, g);
try {
log.info("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ", topic=" + I_TOPIC_1 + ']');
if (!nodeId.equals(ignite1.cluster().localNode().id())) {
log.error("Unexpected sender node: " + nodeId);
error.set(true);
return false;
}
if (!MSG_1.equals(msg)) {
log.error("Unexpected message " + msg + " for topic: " + I_TOPIC_1);
error.set(true);
return false;
}
rcvMsgs.add(msg);
return true;
} finally {
rcvLatch.countDown();
}
}
});
ignite2.message().remoteListen(I_TOPIC_2, new P2<UUID, Object>() {
@IgniteInstanceResource
private transient Ignite g;
@Override
public boolean apply(UUID nodeId, Object msg) {
assertEquals(ignite2, g);
try {
log.info("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ", topic=" + I_TOPIC_2 + ']');
if (!nodeId.equals(ignite1.cluster().localNode().id())) {
log.error("Unexpected sender node: " + nodeId);
error.set(true);
return false;
}
if (!MSG_2.equals(msg)) {
log.error("Unexpected message " + msg + " for topic: " + I_TOPIC_2);
error.set(true);
return false;
}
rcvMsgs.add(msg);
return true;
} finally {
rcvLatch.countDown();
}
}
});
ignite2.message().remoteListen(null, new P2<UUID, Object>() {
@IgniteInstanceResource
private transient Ignite g;
@Override
public boolean apply(UUID nodeId, Object msg) {
assertEquals(ignite2, g);
try {
log.info("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ", topic=default]");
if (!nodeId.equals(ignite1.cluster().localNode().id())) {
log.error("Unexpected sender node: " + nodeId);
error.set(true);
return false;
}
if (!MSG_3.equals(msg)) {
log.error("Unexpected message " + msg + " for topic: default");
error.set(true);
return false;
}
rcvMsgs.add(msg);
return true;
} finally {
rcvLatch.countDown();
}
}
});
// Includes node from grid2.
ClusterGroup prj2 = ignite1.cluster().forRemotes();
message(prj2).send(I_TOPIC_1, MSG_1);
message(prj2).send(I_TOPIC_2, MSG_2);
message(prj2).send(null, MSG_3);
assertTrue(rcvLatch.await(3, TimeUnit.SECONDS));
assertFalse(error.get());
assertTrue(rcvMsgs.contains(MSG_1));
assertTrue(rcvMsgs.contains(MSG_2));
assertTrue(rcvMsgs.contains(MSG_3));
}
use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.
the class GridMarshallerAbstractTest method testServices.
/**
* @throws Exception If failed.
*/
public void testServices() throws Exception {
IgniteConfiguration cfg = optimize(getConfiguration("g1"));
try (Ignite g1 = G.start(cfg)) {
IgniteServices services = grid().services(grid().cluster().forNode(g1.cluster().localNode()));
services.deployNodeSingleton("test", new DummyService());
GridMarshallerTestBean inBean = newTestBean(services);
byte[] buf = marshal(inBean);
GridMarshallerTestBean outBean = unmarshal(buf);
assert inBean.getObjectField() != null;
assert outBean.getObjectField() != null;
assert inBean.getObjectField().getClass().equals(IgniteServicesImpl.class);
assert outBean.getObjectField().getClass().equals(IgniteServicesImpl.class);
assert inBean != outBean;
assert inBean.equals(outBean);
ClusterGroup inPrj = services.clusterGroup();
ClusterGroup outPrj = ((IgniteServices) outBean.getObjectField()).clusterGroup();
assert inPrj.getClass().equals(outPrj.getClass());
assert F.eqNotOrdered(inPrj.nodes(), outPrj.nodes());
outBean.checkNullResources();
}
}
Aggregations