Search in sources :

Example 51 with Tree

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);
}
Also used : NodeDescriptor(services.moleculer.transporter.tcp.NodeDescriptor) Tree(io.datatree.Tree)

Example 52 with Tree

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;
}
Also used : Tree(io.datatree.Tree)

Example 53 with Tree

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));
}
Also used : FastBuildTree(services.moleculer.util.FastBuildTree) Tree(io.datatree.Tree) Test(org.junit.Test)

Example 54 with Tree

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));
}
Also used : FastBuildTree(services.moleculer.util.FastBuildTree) Tree(io.datatree.Tree) Test(org.junit.Test)

Example 55 with Tree

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());
}
Also used : FastBuildTree(services.moleculer.util.FastBuildTree) Tree(io.datatree.Tree) Test(org.junit.Test)

Aggregations

Tree (io.datatree.Tree)60 FastBuildTree (services.moleculer.util.FastBuildTree)26 Test (org.junit.Test)12 NodeDescriptor (services.moleculer.transporter.tcp.NodeDescriptor)12 CheckedTree (services.moleculer.util.CheckedTree)9 TimeoutException (java.util.concurrent.TimeoutException)6 Promise (services.moleculer.Promise)6 CommonUtils.readTree (services.moleculer.util.CommonUtils.readTree)6 RemoteException (java.rmi.RemoteException)4 LinkedHashMap (java.util.LinkedHashMap)4 CallOptions (services.moleculer.context.CallOptions)4 Context (services.moleculer.context.Context)4 Annotation (java.lang.annotation.Annotation)3 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 Map (java.util.Map)3 NoSuchElementException (java.util.NoSuchElementException)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ServiceBrokerConfig (services.moleculer.config.ServiceBrokerConfig)3 Action (services.moleculer.service.Action)3