Search in sources :

Example 11 with CustomPolicyFactory

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

the class RoutingTestCase method requireThatEmptySelectIsCaught.

@Test
public void requireThatEmptySelectIsCaught() {
    SimpleProtocol protocol = new SimpleProtocol();
    protocol.addPolicyFactory("Custom", new CustomPolicyFactory());
    srcServer.mb.putProtocol(protocol);
    assertTrue(srcSession.send(createMessage("msg"), Route.parse("[Custom]")).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 12 with CustomPolicyFactory

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

the class RoutingTestCase method requireThatOnlyActiveNodesAreAborted.

@Test
public void requireThatOnlyActiveNodesAreAborted() {
    SimpleProtocol protocol = new SimpleProtocol();
    protocol.addPolicyFactory("Custom", new CustomPolicyFactory(false));
    protocol.addPolicyFactory("SetReply", new SimpleProtocol.PolicyFactory() {

        @Override
        public RoutingPolicy create(String param) {
            return new SetReplyPolicy(false, Arrays.asList(ErrorCode.APP_TRANSIENT_ERROR, ErrorCode.APP_TRANSIENT_ERROR, ErrorCode.APP_FATAL_ERROR), param);
        }
    });
    srcServer.mb.putProtocol(protocol);
    assertTrue(srcSession.send(createMessage("msg"), Route.parse("[Custom:[SetReply:foo],?bar,dst/session]")).isAccepted());
    Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
    assertNotNull(reply);
    System.out.println(reply.getTrace());
    assertEquals(2, reply.getNumErrors());
    assertEquals(ErrorCode.APP_FATAL_ERROR, reply.getError(0).getCode());
    assertEquals(ErrorCode.SEND_ABORTED, reply.getError(1).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 13 with CustomPolicyFactory

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

the class RoutingTestCase method requireThatSetReplyWorks.

@Test
public void requireThatSetReplyWorks() {
    SimpleProtocol protocol = new SimpleProtocol();
    protocol.addPolicyFactory("Select", new CustomPolicyFactory(true, ErrorCode.APP_FATAL_ERROR));
    protocol.addPolicyFactory("SetReply", new SimpleProtocol.PolicyFactory() {

        @Override
        public RoutingPolicy create(String param) {
            return new SetReplyPolicy(true, Arrays.asList(ErrorCode.APP_FATAL_ERROR), param);
        }
    });
    srcServer.mb.putProtocol(protocol);
    retryPolicy.setEnabled(false);
    assertTrue(srcSession.send(createMessage("msg"), Route.parse("[Select:[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());
}
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)

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