Search in sources :

Example 6 with SimpleMessage

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

the class RoutableTestCase method testReplySwapState.

public void testReplySwapState() {
    Reply foo = new SimpleReply("foo");
    Message fooMsg = new SimpleMessage("foo");
    foo.setMessage(fooMsg);
    foo.setRetryDelay(1);
    foo.addError(new Error(ErrorCode.APP_FATAL_ERROR, "fatal"));
    foo.addError(new Error(ErrorCode.APP_TRANSIENT_ERROR, "transient"));
    Reply bar = new SimpleReply("bar");
    Message barMsg = new SimpleMessage("bar");
    bar.setMessage(barMsg);
    bar.setRetryDelay(2);
    bar.addError(new Error(ErrorCode.ERROR_LIMIT, "err"));
    foo.swapState(bar);
    assertEquals(barMsg, foo.getMessage());
    assertEquals(fooMsg, bar.getMessage());
    assertEquals(2.0, foo.getRetryDelay());
    assertEquals(1.0, bar.getRetryDelay());
    assertEquals(1, foo.getNumErrors());
    assertEquals(2, bar.getNumErrors());
}
Also used : SimpleReply(com.yahoo.messagebus.test.SimpleReply) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleReply(com.yahoo.messagebus.test.SimpleReply)

Example 7 with SimpleMessage

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

the class RoutableTestCase method testMessageDiscard.

public void testMessageDiscard() {
    Receptor handler = new Receptor();
    Message msg = new SimpleMessage("foo");
    msg.pushHandler(handler);
    msg.discard();
    assertNull(handler.getReply(0));
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage)

Example 8 with SimpleMessage

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

the class RoutableTestCase method testMessageSwapState.

public void testMessageSwapState() {
    Message foo = new SimpleMessage("foo");
    Route fooRoute = Route.parse("foo");
    foo.setRoute(fooRoute);
    foo.setRetry(1);
    foo.setTimeReceivedNow();
    foo.setTimeRemaining(2);
    Message bar = new SimpleMessage("bar");
    Route barRoute = Route.parse("bar");
    bar.setRoute(barRoute);
    bar.setRetry(3);
    bar.setTimeReceivedNow();
    bar.setTimeRemaining(4);
    foo.swapState(bar);
    assertEquals(barRoute, foo.getRoute());
    assertEquals(fooRoute, bar.getRoute());
    assertEquals(3, foo.getRetry());
    assertEquals(1, bar.getRetry());
    assertTrue(foo.getTimeReceived() >= bar.getTimeReceived());
    assertEquals(4, foo.getTimeRemaining());
    assertEquals(2, bar.getTimeRemaining());
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Route(com.yahoo.messagebus.routing.Route)

Example 9 with SimpleMessage

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

the class BasicNetworkTestCase method testTimeoutsFollowMessage.

public void testTimeoutsFollowMessage() {
    SourceSessionParams params = new SourceSessionParams().setTimeout(600.0);
    SourceSession ss = src.mb.createSourceSession(new Receptor(), params);
    DestinationSession ds = dst.mb.createDestinationSession("session", true, new Receptor());
    assertTrue(src.waitSlobrok("test/dst/session", 1));
    // Test default timeouts being set.
    Message msg = new SimpleMessage("msg");
    msg.getTrace().setLevel(9);
    long now = SystemTimer.INSTANCE.milliTime();
    assertTrue(ss.send(msg, Route.parse("dst")).isAccepted());
    assertNotNull(msg = ((Receptor) ds.getMessageHandler()).getMessage(60));
    assertTrue(msg.getTimeReceived() >= now);
    assertTrue(params.getTimeout() * 1000 >= msg.getTimeRemaining());
    ds.acknowledge(msg);
    assertNotNull(((Receptor) ss.getReplyHandler()).getReply(60));
    // Test default timeouts being overwritten.
    msg = new SimpleMessage("msg");
    msg.getTrace().setLevel(9);
    msg.setTimeRemaining(2 * (long) (params.getTimeout() * 1000));
    assertTrue(ss.send(msg, Route.parse("dst")).isAccepted());
    assertNotNull(msg = ((Receptor) ds.getMessageHandler()).getMessage(60));
    assertTrue(params.getTimeout() * 1000 < msg.getTimeRemaining());
    ds.acknowledge(msg);
    assertNotNull(((Receptor) ss.getReplyHandler()).getReply(60));
    ss.destroy();
    ds.destroy();
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage)

Example 10 with SimpleMessage

use of com.yahoo.messagebus.test.SimpleMessage 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)

Aggregations

SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)58 Test (org.junit.Test)38 SimpleReply (com.yahoo.messagebus.test.SimpleReply)23 Response (com.yahoo.jdisc.Response)14 Receptor (com.yahoo.messagebus.test.Receptor)13 ServerTestDriver (com.yahoo.messagebus.jdisc.test.ServerTestDriver)12 ClientTestDriver (com.yahoo.messagebus.jdisc.test.ClientTestDriver)9 TestServer (com.yahoo.messagebus.network.rpc.test.TestServer)7 Slobrok (com.yahoo.jrt.slobrok.server.Slobrok)6 Route (com.yahoo.messagebus.routing.Route)5 MessageQueue (com.yahoo.messagebus.jdisc.test.MessageQueue)4 ReplyQueue (com.yahoo.messagebus.jdisc.test.ReplyQueue)4 Request (com.yahoo.jdisc.Request)3 TestDriver (com.yahoo.jdisc.test.TestDriver)3 EmptyReply (com.yahoo.messagebus.EmptyReply)3 Reply (com.yahoo.messagebus.Reply)3 SimpleProtocol (com.yahoo.messagebus.test.SimpleProtocol)3 Error (com.yahoo.messagebus.Error)2 Message (com.yahoo.messagebus.Message)2 RemoteClient (com.yahoo.messagebus.jdisc.test.RemoteClient)2