use of io.datatree.Tree in project moleculer-java by moleculer-java.
the class TcpTransporterTest method createOnlineDescriptorWithInfo.
protected NodeDescriptor createOnlineDescriptorWithInfo(boolean local, String nodeID) {
Tree info = new Tree();
info.put("seq", 1);
info.put("port", 1);
info.put("hostname", nodeID);
info.putList("services").putMap("test");
return new NodeDescriptor(nodeID, true, local, info);
}
use of io.datatree.Tree in project moleculer-java by moleculer-java.
the class TcpTransporterTest method createGossipRequest.
protected Tree createGossipRequest(String nodeID, int seq, int cpuSeq, int cpu) {
Tree req = new Tree();
req.put("sender", nodeID);
req.put("ver", ServiceBroker.PROTOCOL_VERSION);
Tree online = req.putList("online");
if (nodeID != null) {
online.putList(nodeID).add(seq).add(cpuSeq).add(cpu);
}
return req;
}
use of io.datatree.Tree in project moleculer-java by moleculer-java.
the class EventbusTest method testRemoteEmit.
@Test
public void testRemoteEmit() throws Exception {
// Create two listeners
br.createService("test1", new TestListener());
TestListener s1 = (TestListener) br.getLocalService("test1");
br.createService("test2", new TestListener());
TestListener s2 = (TestListener) br.getLocalService("test2");
putIncomingMessage("test.test", false, null, new Tree().put("y", 123));
assertEquals(1, s1.payloads.size());
assertEquals(1, s2.payloads.size());
s1.payloads.clear();
s2.payloads.clear();
putIncomingMessage("test.a", false, null, new Tree().put("y", 123));
assertEquals(1, s1.payloads.size());
assertEquals(1, s2.payloads.size());
assertEquals(123, s1.payloads.remove().get("y", 0));
assertEquals(123, s2.payloads.remove().get("y", 0));
putIncomingMessage("test.a", false, Groups.of("test1"), new Tree());
assertEquals(1, s1.payloads.size());
assertEquals(0, s2.payloads.size());
s1.payloads.clear();
putIncomingMessage("test.a", false, Groups.of("test2"), new Tree());
assertEquals(0, s1.payloads.size());
assertEquals(1, s2.payloads.size());
s2.payloads.clear();
putIncomingMessage("test.a", false, Groups.of("test1", "test2"), new Tree().put("y", 321));
assertEquals(1, s1.payloads.size());
assertEquals(1, s2.payloads.size());
assertEquals(321, s1.payloads.remove().get("y", 0));
assertEquals(321, s2.payloads.remove().get("y", 0));
}
use of io.datatree.Tree in project moleculer-java by moleculer-java.
the class EventbusTest method testRemoteBroadcast.
@Test
public void testRemoteBroadcast() throws Exception {
// Create two listeners
br.createService("test1", new TestListener());
TestListener s1 = (TestListener) br.getLocalService("test1");
br.createService("test2", new TestListener());
TestListener s2 = (TestListener) br.getLocalService("test2");
putIncomingMessage("test.test", true, null, new Tree().put("y", 123));
assertEquals(1, s1.payloads.size());
assertEquals(1, s2.payloads.size());
s1.payloads.clear();
s2.payloads.clear();
putIncomingMessage("test.a", true, null, new Tree().put("y", 123));
assertEquals(1, s1.payloads.size());
assertEquals(1, s2.payloads.size());
assertEquals(123, s1.payloads.remove().get("y", 0));
assertEquals(123, s2.payloads.remove().get("y", 0));
putIncomingMessage("test.a", true, Groups.of("test1"), new Tree());
assertEquals(1, s1.payloads.size());
assertEquals(0, s2.payloads.size());
s1.payloads.clear();
putIncomingMessage("test.a", true, Groups.of("test2"), new Tree());
assertEquals(0, s1.payloads.size());
assertEquals(1, s2.payloads.size());
s2.payloads.clear();
putIncomingMessage("test.a", true, Groups.of("test1", "test2"), new Tree().put("y", 321));
assertEquals(1, s1.payloads.size());
assertEquals(1, s2.payloads.size());
assertEquals(321, s1.payloads.remove().get("y", 0));
assertEquals(321, s2.payloads.remove().get("y", 0));
}
use of io.datatree.Tree in project moleculer-java by moleculer-java.
the class EventbusTest method testSimpleFuctions.
// --- TEST METHODS ---
@Test
public void testSimpleFuctions() throws Exception {
br.createService("test", new TestListener());
TestListener s = (TestListener) br.getLocalService("test");
br.broadcast("test.a1", new Tree().put("a", 15));
assertEquals(1, s.payloads.size());
Tree t = s.payloads.removeFirst();
assertEquals(15, t.get("a", -1));
br.emit("test.b", new Tree().put("b", "abc").put("c", true));
assertEquals(1, s.payloads.size());
t = s.payloads.removeFirst();
assertEquals("abc", t.get("b", ""));
assertTrue(t.get("c", false));
br.broadcastLocal("test.c", new Tree().put("d", "x"));
assertEquals(1, s.payloads.size());
t = s.payloads.removeFirst();
assertEquals("x", t.get("d", ""));
br.broadcast("test.a.b", new Tree().put("d", "x"));
assertEquals(0, s.payloads.size());
br.broadcast("foo.a1", new Tree().put("d", "x"));
assertEquals(0, s.payloads.size());
br.emit("test.b.xy", new Tree().put("d", "x"));
assertEquals(0, s.payloads.size());
br.emit("xyz.b", new Tree().put("d", "x"));
assertEquals(0, s.payloads.size());
br.broadcastLocal("test.fg.hg", new Tree().put("d", "x"));
assertEquals(0, s.payloads.size());
br.broadcastLocal("d", new Tree().put("d", "x"));
assertEquals(0, s.payloads.size());
}
Aggregations