use of com.yahoo.messagebus.routing.test.CustomPolicyFactory 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());
}
use of com.yahoo.messagebus.routing.test.CustomPolicyFactory in project vespa by vespa-engine.
the class RoutingTestCase method requireThatPolicySelectWorks.
@Test
public void requireThatPolicySelectWorks() {
SimpleProtocol protocol = new SimpleProtocol();
protocol.addPolicyFactory("Custom", new CustomPolicyFactory());
srcServer.mb.putProtocol(protocol);
assertTrue(srcSession.send(createMessage("msg"), Route.parse("[Custom:dst/session]")).isAccepted());
Message msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60);
assertNotNull(msg);
dstSession.acknowledge(msg);
Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
assertNotNull(reply);
System.out.println(reply.getTrace());
assertFalse(reply.hasErrors());
}
use of com.yahoo.messagebus.routing.test.CustomPolicyFactory in project vespa by vespa-engine.
the class RoutingTestCase method requireThatPolicyCanExpandToPolicy.
@Test
public void requireThatPolicyCanExpandToPolicy() {
SimpleProtocol protocol = new SimpleProtocol();
protocol.addPolicyFactory("Custom", new CustomPolicyFactory(true, ErrorCode.NO_ADDRESS_FOR_SERVICE));
srcServer.mb.putProtocol(protocol);
retryPolicy.setEnabled(false);
assertTrue(srcSession.send(createMessage("msg"), Route.parse("[Custom:[Custom:dst/session],[Custom:dst/unknown]]")).isAccepted());
Message msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60);
assertNotNull(msg);
dstSession.acknowledge(msg);
Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
assertNotNull(reply);
System.out.println(reply.getTrace());
assertEquals(1, reply.getNumErrors());
assertEquals(ErrorCode.NO_ADDRESS_FOR_SERVICE, reply.getError(0).getCode());
}
use of com.yahoo.messagebus.routing.test.CustomPolicyFactory in project vespa by vespa-engine.
the class RoutingTestCase method requireThatPolicyCanDisableReselectOnRetry.
@Test
public void requireThatPolicyCanDisableReselectOnRetry() {
SimpleProtocol protocol = new SimpleProtocol();
protocol.addPolicyFactory("Custom", new CustomPolicyFactory(false));
srcServer.mb.putProtocol(protocol);
assertTrue(srcSession.send(createMessage("msg"), Route.parse("[Custom:dst/session]")).isAccepted());
Message msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60);
assertNotNull(msg);
Reply reply = new EmptyReply();
reply.swapState(msg);
reply.addError(new Error(ErrorCode.APP_TRANSIENT_ERROR, "err"));
dstSession.reply(reply);
assertNotNull(msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60));
dstSession.acknowledge(msg);
assertNotNull(reply = ((Receptor) srcSession.getReplyHandler()).getReply(60));
System.out.println(reply.getTrace());
assertFalse(reply.hasErrors());
assertTrace(Arrays.asList("Selecting [dst/session].", "[APP_TRANSIENT_ERROR @ localhost]", "-[APP_TRANSIENT_ERROR @ localhost]", "Merged [dst/session].", "-Selecting [dst/session].", "Sending reply", "Merged [dst/session]."), reply.getTrace());
}
use of com.yahoo.messagebus.routing.test.CustomPolicyFactory in project vespa by vespa-engine.
the class RoutingTestCase method requireThatPolicyOnlyConsumesDeclaredErrors.
@Test
public void requireThatPolicyOnlyConsumesDeclaredErrors() {
SimpleProtocol protocol = new SimpleProtocol();
protocol.addPolicyFactory("Custom", new CustomPolicyFactory());
srcServer.mb.putProtocol(protocol);
retryPolicy.setEnabled(false);
assertTrue(srcSession.send(createMessage("msg"), Route.parse("[Custom:dst/unknown]")).isAccepted());
Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
assertNotNull(reply);
System.out.println(reply.getTrace());
assertEquals(1, reply.getNumErrors());
assertEquals(ErrorCode.NO_ADDRESS_FOR_SERVICE, reply.getError(0).getCode());
assertTrace(Arrays.asList("Selecting [dst/unknown].", "[NO_ADDRESS_FOR_SERVICE @ localhost]", "Merged [dst/unknown]."), reply.getTrace());
}
Aggregations