Search in sources :

Example 61 with Receptor

use of com.yahoo.messagebus.test.Receptor in project vespa by vespa-engine.

the class ErrorTestCase method requireThatErrorIsPropagated.

@Test
public void requireThatErrorIsPropagated() throws Exception {
    RoutingTableSpec table = new RoutingTableSpec(SimpleProtocol.NAME);
    table.addHop("itr", "test/itr/session", Arrays.asList("test/itr/session"));
    table.addHop("dst", "test/dst/session", Arrays.asList("test/dst/session"));
    table.addRoute("test", Arrays.asList("itr", "dst"));
    Slobrok slobrok = new Slobrok();
    TestServer src = new TestServer("test/src", table, slobrok, null);
    TestServer itr = new TestServer("test/itr", table, slobrok, null);
    TestServer dst = new TestServer("test/dst", table, slobrok, null);
    Receptor ss_rr = new Receptor();
    SourceSession ss = src.mb.createSourceSession(ss_rr);
    Receptor is_mr = new Receptor();
    Receptor is_rr = new Receptor();
    IntermediateSession is = itr.mb.createIntermediateSession("session", true, is_mr, is_rr);
    Receptor ds_mr = new Receptor();
    DestinationSession ds = dst.mb.createDestinationSession("session", true, ds_mr);
    src.waitSlobrok("test/itr/session", 1);
    src.waitSlobrok("test/dst/session", 1);
    itr.waitSlobrok("test/dst/session", 1);
    for (int i = 0; i < 5; i++) {
        assertTrue(ss.send(new SimpleMessage("msg"), "test").isAccepted());
        Message msg = is_mr.getMessage(60);
        assertNotNull(msg);
        is.forward(msg);
        assertNotNull(msg = ds_mr.getMessage(60));
        Reply reply = new EmptyReply();
        msg.swapState(reply);
        reply.addError(new Error(ErrorCode.APP_FATAL_ERROR, "fatality"));
        ds.reply(reply);
        assertNotNull(reply = is_rr.getReply(60));
        assertEquals(reply.getNumErrors(), 1);
        assertEquals(reply.getError(0).getService(), "test/dst/session");
        reply.addError(new Error(ErrorCode.APP_FATAL_ERROR, "fatality"));
        is.forward(reply);
        assertNotNull(reply = ss_rr.getReply(60));
        assertEquals(reply.getNumErrors(), 2);
        assertEquals(reply.getError(0).getService(), "test/dst/session");
        assertEquals(reply.getError(1).getService(), "test/itr/session");
    }
    ss.destroy();
    is.destroy();
    ds.destroy();
    dst.destroy();
    itr.destroy();
    src.destroy();
    slobrok.stop();
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer) RoutingTableSpec(com.yahoo.messagebus.routing.RoutingTableSpec) Receptor(com.yahoo.messagebus.test.Receptor) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) Test(org.junit.Test)

Example 62 with Receptor

use of com.yahoo.messagebus.test.Receptor in project vespa by vespa-engine.

the class SendProxyTestCase method setUp.

@Override
public void setUp() throws UnknownHostException, ListenFailedException {
    slobrok = new Slobrok();
    dstServer = new TestServer(new MessageBusParams().addProtocol(new SimpleProtocol()), new RPCNetworkParams().setIdentity(new Identity("dst")).setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
    dstSession = dstServer.mb.createDestinationSession(new DestinationSessionParams().setName("session").setMessageHandler(new Receptor()));
    srcServer = new TestServer(new MessageBusParams().addProtocol(new SimpleProtocol()), new RPCNetworkParams().setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
    srcSession = srcServer.mb.createSourceSession(new SourceSessionParams().setTimeout(600.0).setThrottlePolicy(null).setReplyHandler(new Receptor()));
    assertTrue(srcServer.waitSlobrok("dst/session", 1));
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) Receptor(com.yahoo.messagebus.test.Receptor) RPCNetworkParams(com.yahoo.messagebus.network.rpc.RPCNetworkParams) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) Identity(com.yahoo.messagebus.network.Identity) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer)

Example 63 with Receptor

use of com.yahoo.messagebus.test.Receptor in project vespa by vespa-engine.

the class SendProxyTestCase method sendMessage.

private void sendMessage(int traceLevel, Error err) {
    Message msg = new SimpleMessage("foo");
    msg.getTrace().setLevel(traceLevel);
    assertTrue(srcSession.send(msg, Route.parse("dst/session")).isAccepted());
    assertNotNull(msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60));
    if (err != null) {
        Reply reply = new SimpleReply("bar");
        reply.swapState(msg);
        reply.addError(err);
        dstSession.reply(reply);
    } else {
        dstSession.acknowledge(msg);
    }
    Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
    assertNotNull(reply);
}
Also used : SimpleReply(com.yahoo.messagebus.test.SimpleReply) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleReply(com.yahoo.messagebus.test.SimpleReply)

Example 64 with Receptor

use of com.yahoo.messagebus.test.Receptor in project vespa by vespa-engine.

the class SimpleTripTestCase method testSimpleTrip.

public void testSimpleTrip() throws ListenFailedException, UnknownHostException {
    Slobrok slobrok = new Slobrok();
    TestServer server = new TestServer(new MessageBusParams().addProtocol(new SimpleProtocol()), new RPCNetworkParams().setIdentity(new Identity("srv")).setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
    DestinationSession dst = server.mb.createDestinationSession(new DestinationSessionParams().setName("session").setMessageHandler(new Receptor()));
    SourceSession src = server.mb.createSourceSession(new SourceSessionParams().setTimeout(600.0).setReplyHandler(new Receptor()));
    assertTrue(server.waitSlobrok("srv/session", 1));
    assertTrue(src.send(new SimpleMessage("msg"), Route.parse("srv/session")).isAccepted());
    Message msg = ((Receptor) dst.getMessageHandler()).getMessage(60);
    assertNotNull(msg);
    assertEquals(SimpleProtocol.NAME, msg.getProtocol());
    assertEquals(SimpleProtocol.MESSAGE, msg.getType());
    assertEquals("msg", ((SimpleMessage) msg).getValue());
    Reply reply = new SimpleReply("reply");
    reply.swapState(msg);
    dst.reply(reply);
    assertNotNull(reply = ((Receptor) src.getReplyHandler()).getReply(60));
    assertEquals(SimpleProtocol.NAME, reply.getProtocol());
    assertEquals(SimpleProtocol.REPLY, reply.getType());
    assertEquals("reply", ((SimpleReply) reply).getValue());
    src.destroy();
    dst.destroy();
    server.destroy();
}
Also used : SimpleReply(com.yahoo.messagebus.test.SimpleReply) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer) SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) Receptor(com.yahoo.messagebus.test.Receptor) RPCNetworkParams(com.yahoo.messagebus.network.rpc.RPCNetworkParams) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) SimpleReply(com.yahoo.messagebus.test.SimpleReply) Identity(com.yahoo.messagebus.network.Identity)

Example 65 with Receptor

use of com.yahoo.messagebus.test.Receptor in project vespa by vespa-engine.

the class TraceTripTestCase method testTrip.

public void testTrip() {
    Receptor src_rr = new Receptor();
    SourceSession src_s = src.mb.createSourceSession(src_rr);
    new Proxy(pxy.mb);
    assertTrue(src.waitSlobrok("test/pxy/session", 1));
    new Server(dst.mb);
    assertTrue(src.waitSlobrok("test/dst/session", 1));
    assertTrue(pxy.waitSlobrok("test/dst/session", 1));
    Message msg = new SimpleMessage("");
    msg.getTrace().setLevel(1);
    msg.getTrace().trace(1, "Client message", false);
    src_s.send(msg, "test");
    Reply reply = src_rr.getReply(60);
    reply.getTrace().trace(1, "Client reply", false);
    assertTrue(reply.getNumErrors() == 0);
    TraceNode t = new TraceNode().addChild("Client message").addChild("Proxy message").addChild("Server message").addChild("Server reply").addChild("Proxy reply").addChild("Client reply");
    System.out.println("reply: " + reply.getTrace().getRoot().encode());
    System.out.println("want : " + t.encode());
    assertTrue(reply.getTrace().getRoot().encode().equals(t.encode()));
}
Also used : TestServer(com.yahoo.messagebus.network.rpc.test.TestServer) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage)

Aggregations

Receptor (com.yahoo.messagebus.test.Receptor)69 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)46 Test (org.junit.Test)35 SimpleProtocol (com.yahoo.messagebus.test.SimpleProtocol)30 TestServer (com.yahoo.messagebus.network.rpc.test.TestServer)18 Slobrok (com.yahoo.jrt.slobrok.server.Slobrok)17 CustomPolicyFactory (com.yahoo.messagebus.routing.test.CustomPolicyFactory)12 RPCNetworkParams (com.yahoo.messagebus.network.rpc.RPCNetworkParams)10 Error (com.yahoo.messagebus.Error)9 Identity (com.yahoo.messagebus.network.Identity)9 SimpleReply (com.yahoo.messagebus.test.SimpleReply)6 DocumentProtocol (com.yahoo.documentapi.messagebus.protocol.DocumentProtocol)3 ArrayList (java.util.ArrayList)3 Before (org.junit.Before)3 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)2 Route (com.yahoo.messagebus.routing.Route)2 Version (com.yahoo.component.Version)1 VersionSpecification (com.yahoo.component.VersionSpecification)1 DocumentMessage (com.yahoo.documentapi.messagebus.protocol.DocumentMessage)1 DocumentReply (com.yahoo.documentapi.messagebus.protocol.DocumentReply)1