Search in sources :

Example 26 with SimpleProtocol

use of com.yahoo.messagebus.test.SimpleProtocol 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 27 with SimpleProtocol

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

the class RoutingTestCase method requireThatReplyCanBeReusedOnRetry.

@Test
public void requireThatReplyCanBeReusedOnRetry() {
    SimpleProtocol protocol = new SimpleProtocol();
    protocol.addPolicyFactory("ReuseReply", new SimpleProtocol.PolicyFactory() {

        @Override
        public RoutingPolicy create(String param) {
            return new ReuseReplyPolicy(false, Arrays.asList(ErrorCode.APP_FATAL_ERROR), CustomPolicyFactory.parseRoutes(param));
        }
    });
    protocol.addPolicyFactory("SetReply", new SimpleProtocol.PolicyFactory() {

        @Override
        public RoutingPolicy create(String param) {
            return new SetReplyPolicy(false, Arrays.asList(ErrorCode.APP_FATAL_ERROR), param);
        }
    });
    srcServer.mb.putProtocol(protocol);
    assertTrue(srcSession.send(createMessage("msg"), Route.parse("[ReuseReply:[SetReply:foo],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, "dst"));
    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());
}
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) Test(org.junit.Test)

Example 28 with SimpleProtocol

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

the class RoutingTestCase method requireThatReplyCanBeRemovedAndRetried.

@Test
public void requireThatReplyCanBeRemovedAndRetried() {
    SimpleProtocol protocol = new SimpleProtocol();
    protocol.addPolicyFactory("RemoveReply", new SimpleProtocol.PolicyFactory() {

        @Override
        public RoutingPolicy create(String param) {
            return new RemoveReplyPolicy(false, Arrays.asList(ErrorCode.APP_TRANSIENT_ERROR), CustomPolicyFactory.parseRoutes(param), 0);
        }
    });
    protocol.addPolicyFactory("SetReply", new SimpleProtocol.PolicyFactory() {

        @Override
        public RoutingPolicy create(String param) {
            return new SetReplyPolicy(false, Arrays.asList(ErrorCode.APP_TRANSIENT_ERROR, ErrorCode.APP_FATAL_ERROR), param);
        }
    });
    srcServer.mb.putProtocol(protocol);
    assertTrue(srcSession.send(createMessage("msg"), Route.parse("[RemoveReply:[SetReply:foo],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());
    assertEquals(1, reply.getNumErrors());
    assertEquals(ErrorCode.APP_FATAL_ERROR, reply.getError(0).getCode());
    assertEquals("foo", reply.getError(0).getMessage());
    assertTrace(Arrays.asList("Resolving '[SetReply:foo]'.", "Resolving 'dst/session'.", "Resender resending message.", "Resolving 'dst/session'.", "Resolving '[SetReply:foo]'."), reply.getTrace());
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) Test(org.junit.Test)

Example 29 with SimpleProtocol

use of com.yahoo.messagebus.test.SimpleProtocol 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 30 with SimpleProtocol

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

Aggregations

SimpleProtocol (com.yahoo.messagebus.test.SimpleProtocol)44 Receptor (com.yahoo.messagebus.test.Receptor)30 Test (org.junit.Test)26 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)15 CustomPolicyFactory (com.yahoo.messagebus.routing.test.CustomPolicyFactory)13 RPCNetworkParams (com.yahoo.messagebus.network.rpc.RPCNetworkParams)12 Slobrok (com.yahoo.jrt.slobrok.server.Slobrok)11 TestServer (com.yahoo.messagebus.network.rpc.test.TestServer)8 Identity (com.yahoo.messagebus.network.Identity)7 Error (com.yahoo.messagebus.Error)5 RoutingPolicy (com.yahoo.messagebus.routing.RoutingPolicy)4 MessageBusParams (com.yahoo.messagebus.MessageBusParams)3 MessageBus (com.yahoo.messagebus.MessageBus)2 LocalNetwork (com.yahoo.messagebus.network.local.LocalNetwork)2 SharedMessageBus (com.yahoo.messagebus.shared.SharedMessageBus)2 Before (org.junit.Before)2 NonWorkingRequestHandler (com.yahoo.jdisc.test.NonWorkingRequestHandler)1 Spec (com.yahoo.jrt.Spec)1 DestinationSessionParams (com.yahoo.messagebus.DestinationSessionParams)1 SourceSessionParams (com.yahoo.messagebus.SourceSessionParams)1