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());
}
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));
}
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());
}
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();
}
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());
}
Aggregations