Search in sources :

Example 26 with Receptor

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

the class RPCNetworkTestCase method requireThatProtocolEncodeExceptionIsCaught.

@Test
public void requireThatProtocolEncodeExceptionIsCaught() throws Exception {
    RuntimeException e = new RuntimeException();
    Slobrok slobrok = new Slobrok();
    TestServer server = new TestServer(new MessageBusParams().addProtocol(MyProtocol.newEncodeException(e)), new RPCNetworkParams().setSlobrokConfigId(slobrok.configId()));
    Receptor receptor = new Receptor();
    SourceSession src = server.mb.createSourceSession(new SourceSessionParams().setTimeout(600.0).setReplyHandler(receptor));
    DestinationSession dst = server.mb.createDestinationSession(new DestinationSessionParams());
    assertTrue(src.send(new MyMessage().setRoute(Route.parse(dst.getConnectionSpec()))).isAccepted());
    Reply reply = receptor.getReply(60);
    assertNotNull(reply);
    assertEquals(1, reply.getNumErrors());
    StringWriter expected = new StringWriter();
    e.printStackTrace(new PrintWriter(expected));
    String actual = reply.getError(0).toString();
    assertTrue(actual, actual.contains(expected.toString()));
}
Also used : Utf8String(com.yahoo.text.Utf8String) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer) StringWriter(java.io.StringWriter) Receptor(com.yahoo.messagebus.test.Receptor) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 27 with Receptor

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

the class AdvancedRoutingTestCase method setUp.

@Override
public void setUp() throws ListenFailedException, UnknownHostException {
    slobrok = new Slobrok();
    dstServer = new TestServer(new MessageBusParams().addProtocol(new SimpleProtocol()), new RPCNetworkParams().setIdentity(new Identity("dst")).setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
    dstFoo = dstServer.mb.createDestinationSession(new DestinationSessionParams().setName("foo").setMessageHandler(new Receptor()));
    dstBar = dstServer.mb.createDestinationSession(new DestinationSessionParams().setName("bar").setMessageHandler(new Receptor()));
    dstBaz = dstServer.mb.createDestinationSession(new DestinationSessionParams().setName("baz").setMessageHandler(new Receptor()));
    srcServer = new TestServer(new MessageBusParams().setRetryPolicy(new RetryTransientErrorsPolicy().setBaseDelay(0)).addProtocol(new SimpleProtocol()), new RPCNetworkParams().setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
    srcSession = srcServer.mb.createSourceSession(new SourceSessionParams().setTimeout(600.0).setReplyHandler(new Receptor()));
    assertTrue(srcServer.waitSlobrok("dst/*", 3));
}
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 28 with Receptor

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

the class AdvancedRoutingTestCase method testAdvanced.

// //////////////////////////////////////////////////////////////////////////////
// 
// Tests
// 
// //////////////////////////////////////////////////////////////////////////////
public void testAdvanced() {
    SimpleProtocol protocol = new SimpleProtocol();
    protocol.addPolicyFactory("Custom", new CustomPolicyFactory(false, ErrorCode.NO_ADDRESS_FOR_SERVICE));
    srcServer.mb.putProtocol(protocol);
    srcServer.setupRouting(new RoutingTableSpec(SimpleProtocol.NAME).addHop(new HopSpec("bar", "dst/bar")).addHop(new HopSpec("baz", "dst/baz")).addRoute(new RouteSpec("baz").addHop("baz")));
    Message msg = new SimpleMessage("msg");
    msg.getTrace().setLevel(9);
    assertTrue(srcSession.send(msg, Route.parse("[Custom:" + dstFoo.getConnectionSpec() + ",bar,route:baz,dst/cox,?dst/unknown]")).isAccepted());
    // Initial send.
    assertNotNull(msg = ((Receptor) dstFoo.getMessageHandler()).getMessage(60));
    dstFoo.acknowledge(msg);
    assertNotNull(msg = ((Receptor) dstBar.getMessageHandler()).getMessage(60));
    Reply reply = new EmptyReply();
    reply.swapState(msg);
    reply.addError(new Error(ErrorCode.TRANSIENT_ERROR, "bar"));
    dstBar.reply(reply);
    assertNotNull(msg = ((Receptor) dstBaz.getMessageHandler()).getMessage(60));
    reply = new EmptyReply();
    reply.swapState(msg);
    reply.addError(new Error(ErrorCode.TRANSIENT_ERROR, "baz1"));
    dstBaz.reply(reply);
    // First retry.
    assertNull(((Receptor) dstFoo.getMessageHandler()).getMessage(0));
    assertNotNull(msg = ((Receptor) dstBar.getMessageHandler()).getMessage(60));
    dstBar.acknowledge(msg);
    assertNotNull(msg = ((Receptor) dstBaz.getMessageHandler()).getMessage(60));
    reply = new EmptyReply();
    reply.swapState(msg);
    reply.addError(new Error(ErrorCode.TRANSIENT_ERROR, "baz2"));
    dstBaz.reply(reply);
    // Second retry.
    assertNull(((Receptor) dstFoo.getMessageHandler()).getMessage(0));
    assertNull(((Receptor) dstBar.getMessageHandler()).getMessage(0));
    assertNotNull(msg = ((Receptor) dstBaz.getMessageHandler()).getMessage(60));
    reply = new EmptyReply();
    reply.swapState(msg);
    reply.addError(new Error(ErrorCode.FATAL_ERROR, "baz3"));
    dstBaz.reply(reply);
    // Done.
    reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
    assertNotNull(reply);
    System.out.println(reply.getTrace());
    assertEquals(2, reply.getNumErrors());
    assertEquals(ErrorCode.FATAL_ERROR, reply.getError(0).getCode());
    assertEquals(ErrorCode.NO_ADDRESS_FOR_SERVICE, reply.getError(1).getCode());
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Error(com.yahoo.messagebus.Error) CustomPolicyFactory(com.yahoo.messagebus.routing.test.CustomPolicyFactory)

Example 29 with Receptor

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

the class TimeoutTestCase method destroyResources.

@After
public void destroyResources() {
    slobrok.stop();
    dstSession.destroy();
    dstServer.destroy();
    srcSession.destroy();
    srcServer.destroy();
    Message msg = ((Receptor) dstSession.getMessageHandler()).getMessage(0);
    if (msg != null) {
        msg.discard();
    }
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) After(org.junit.After)

Example 30 with Receptor

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

the class PolicyTestCase method testExternSend.

@Test
public void testExternSend() throws Exception {
    // Setup local source node.
    Slobrok local = new Slobrok();
    TestServer src = new TestServer("src", null, local, new DocumentProtocol(manager));
    SourceSession ss = src.mb.createSourceSession(new Receptor(), new SourceSessionParams().setTimeout(TIMEOUT));
    // Setup remote cluster with routing config.
    Slobrok slobrok = new Slobrok();
    TestServer itr = new TestServer("itr", new RoutingTableSpec(DocumentProtocol.NAME).addRoute(new RouteSpec("default").addHop("dst")).addHop(new HopSpec("dst", "dst/session")), slobrok, new DocumentProtocol(manager));
    IntermediateSession is = itr.mb.createIntermediateSession("session", true, new Receptor(), new Receptor());
    TestServer dst = new TestServer("dst", null, slobrok, new DocumentProtocol(manager));
    DestinationSession ds = dst.mb.createDestinationSession("session", true, new Receptor());
    // Send message from local node to remote cluster and resolve route there.
    Message msg = new RemoveDocumentMessage(new DocumentId("doc:scheme:"));
    msg.getTrace().setLevel(9);
    msg.setRoute(Route.parse("[Extern:tcp/localhost:" + slobrok.port() + ";itr/session] default"));
    assertTrue(ss.send(msg).isAccepted());
    assertNotNull(msg = ((Receptor) is.getMessageHandler()).getMessage(TIMEOUT));
    is.forward(msg);
    assertNotNull(msg = ((Receptor) ds.getMessageHandler()).getMessage(TIMEOUT));
    ds.acknowledge(msg);
    Reply reply = ((Receptor) is.getReplyHandler()).getReply(TIMEOUT);
    assertNotNull(reply);
    is.forward(reply);
    assertNotNull(reply = ((Receptor) ss.getReplyHandler()).getReply(TIMEOUT));
    System.out.println(reply.getTrace().toString());
    // Perform necessary cleanup.
    src.destroy();
    itr.destroy();
    dst.destroy();
    slobrok.stop();
    local.stop();
}
Also used : TestServer(com.yahoo.messagebus.network.rpc.test.TestServer) Receptor(com.yahoo.messagebus.test.Receptor) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) Test(org.junit.Test)

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