Search in sources :

Example 6 with CustomPolicyFactory

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

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());
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) CustomPolicyFactory(com.yahoo.messagebus.routing.test.CustomPolicyFactory) Test(org.junit.Test)

Example 8 with CustomPolicyFactory

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());
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) CustomPolicyFactory(com.yahoo.messagebus.routing.test.CustomPolicyFactory) Test(org.junit.Test)

Example 9 with CustomPolicyFactory

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());
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) Error(com.yahoo.messagebus.Error) CustomPolicyFactory(com.yahoo.messagebus.routing.test.CustomPolicyFactory) Test(org.junit.Test)

Example 10 with CustomPolicyFactory

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());
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) Receptor(com.yahoo.messagebus.test.Receptor) CustomPolicyFactory(com.yahoo.messagebus.routing.test.CustomPolicyFactory) Test(org.junit.Test)

Aggregations

CustomPolicyFactory (com.yahoo.messagebus.routing.test.CustomPolicyFactory)13 SimpleProtocol (com.yahoo.messagebus.test.SimpleProtocol)13 Receptor (com.yahoo.messagebus.test.Receptor)12 Test (org.junit.Test)12 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)8 Error (com.yahoo.messagebus.Error)4 Spec (com.yahoo.jrt.Spec)1 Slobrok (com.yahoo.jrt.slobrok.server.Slobrok)1 RPCNetwork (com.yahoo.messagebus.network.rpc.RPCNetwork)1 RPCNetworkParams (com.yahoo.messagebus.network.rpc.RPCNetworkParams)1 RoutingPolicy (com.yahoo.messagebus.routing.RoutingPolicy)1