Search in sources :

Example 1 with CustomPolicyFactory

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

the class RoutingTestCase method requireThatPolicyCanConsumeErrors.

@Test
public void requireThatPolicyCanConsumeErrors() {
    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:dst/session,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());
    assertTrace(Arrays.asList("Selecting [dst/session, dst/unknown].", "[NO_ADDRESS_FOR_SERVICE @ localhost]", "Sending reply", "Merged [dst/session, dst/unknown]."), reply.getTrace());
}
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 2 with CustomPolicyFactory

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

the class RoutingTestCase method requireThatRetryCallsSelect.

@Test
public void requireThatRetryCallsSelect() {
    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);
    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 3 with CustomPolicyFactory

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

the class RoutingTestCase method requireThatTransientErrorsAreRetriedWithPolicy.

@Test
public void requireThatTransientErrorsAreRetriedWithPolicy() {
    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);
    Reply reply = new EmptyReply();
    reply.swapState(msg);
    reply.addError(new Error(ErrorCode.APP_TRANSIENT_ERROR, "err1"));
    dstSession.reply(reply);
    assertNotNull(msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60));
    reply = new EmptyReply();
    reply.swapState(msg);
    reply.addError(new Error(ErrorCode.APP_TRANSIENT_ERROR, "err2"));
    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("Source session accepted a 3 byte message. 1 message(s) now pending.", "Running routing policy 'Custom'.", "Selecting [dst/session].", "Component 'dst/session' selected by policy 'Custom'.", "Resolving 'dst/session'.", "Sending message (version ${VERSION}) from client to 'dst/session'", "Message (type 1) received at 'dst' for session 'session'.", "[APP_TRANSIENT_ERROR @ localhost]: err1", "Sending reply (version ${VERSION}) from 'dst'.", "Reply (type 0) received at client.", "Routing policy 'Custom' merging replies.", "Merged [dst/session].", "Message scheduled for retry 1 in 0.0 seconds.", "Resender resending message.", "Running routing policy 'Custom'.", "Selecting [dst/session].", "Component 'dst/session' selected by policy 'Custom'.", "Resolving 'dst/session'.", "Sending message (version ${VERSION}) from client to 'dst/session'", "Message (type 1) received at 'dst' for session 'session'.", "[APP_TRANSIENT_ERROR @ localhost]: err2", "Sending reply (version ${VERSION}) from 'dst'.", "Reply (type 0) received at client.", "Routing policy 'Custom' merging replies.", "Merged [dst/session].", "Message scheduled for retry 2 in 0.0 seconds.", "Resender resending message.", "Running routing policy 'Custom'.", "Selecting [dst/session].", "Component 'dst/session' selected by policy 'Custom'.", "Resolving 'dst/session'.", "Sending message (version ${VERSION}) from client to 'dst/session'", "Message (type 1) received at 'dst' for session 'session'.", "Sending reply (version ${VERSION}) from 'dst'.", "Reply (type 0) received at client.", "Routing policy 'Custom' merging replies.", "Merged [dst/session].", "Source session received reply. 0 message(s) now pending."), 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 4 with CustomPolicyFactory

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

the class RoutingTestCase method requireThatIllegalSelectIsCaught.

@Test
public void requireThatIllegalSelectIsCaught() {
    SimpleProtocol protocol = new SimpleProtocol();
    protocol.addPolicyFactory("Custom", new CustomPolicyFactory());
    srcServer.mb.putProtocol(protocol);
    Route route = Route.parse("[Custom: ]");
    assertNotNull(route);
    assertTrue(srcSession.send(createMessage("msg"), route).isAccepted());
    Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
    assertNotNull(reply);
    System.out.println(reply.getTrace());
    assertEquals(1, reply.getNumErrors());
    assertEquals(ErrorCode.NO_SERVICES_FOR_ROUTE, reply.getError(0).getCode());
}
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)

Example 5 with CustomPolicyFactory

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

the class MessageBusTestCase method testRoutingPolicyCache.

@Test
public void testRoutingPolicyCache() throws ListenFailedException, UnknownHostException {
    Slobrok slobrok = new Slobrok();
    String config = "slobrok[1]\nslobrok[0].connectionspec \"" + new Spec("localhost", slobrok.port()).toString() + "\"\n";
    SimpleProtocol protocol = new SimpleProtocol();
    protocol.addPolicyFactory("Custom", new CustomPolicyFactory());
    MessageBus bus = new MessageBus(new RPCNetwork(new RPCNetworkParams().setSlobrokConfigId("raw:" + config)), new MessageBusParams().addProtocol(protocol));
    RoutingPolicy all = bus.getRoutingPolicy(SimpleProtocol.NAME, "Custom", null);
    assertNotNull(all);
    RoutingPolicy ref = bus.getRoutingPolicy(SimpleProtocol.NAME, "Custom", null);
    assertNotNull(ref);
    assertSame(all, ref);
    RoutingPolicy allArg = bus.getRoutingPolicy(SimpleProtocol.NAME, "Custom", "Arg");
    assertNotNull(allArg);
    assertNotSame(all, allArg);
    RoutingPolicy refArg = bus.getRoutingPolicy(SimpleProtocol.NAME, "Custom", "Arg");
    assertNotNull(refArg);
    assertSame(allArg, refArg);
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) RPCNetworkParams(com.yahoo.messagebus.network.rpc.RPCNetworkParams) RPCNetwork(com.yahoo.messagebus.network.rpc.RPCNetwork) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) RoutingPolicy(com.yahoo.messagebus.routing.RoutingPolicy) Spec(com.yahoo.jrt.Spec) 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