Search in sources :

Example 31 with SimpleProtocol

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

the class RoutingTestCase method requireThatMergeExceptionIsCaught.

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

        @Override
        public RoutingPolicy create(String param) {
            return new RoutingPolicy() {

                @Override
                public void select(RoutingContext context) {
                    context.addChild(Route.parse("dst/session"));
                }

                @Override
                public void merge(RoutingContext context) {
                    throw new RuntimeException("69");
                }

                @Override
                public void destroy() {
                }
            };
        }
    });
    srcServer.mb.putProtocol(protocol);
    assertTrue(srcSession.send(createMessage("msg"), Route.parse("[Custom]")).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.POLICY_ERROR, reply.getError(0).getCode());
    assertTrue(reply.getError(0).getMessage().contains("69"));
}
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 32 with SimpleProtocol

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

the class RoutingTestCase method setupPolicy.

private void setupPolicy(String policyName, SimpleProtocol.PolicyFactory policyFactory) {
    SimpleProtocol protocol = new SimpleProtocol();
    protocol.addPolicyFactory(policyName, policyFactory);
    srcServer.mb.putProtocol(protocol);
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol)

Example 33 with SimpleProtocol

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

Example 34 with SimpleProtocol

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

the class RoutingTestCase method selectExceptionIncludesStackTraceInMessage.

@Test
public void selectExceptionIncludesStackTraceInMessage() {
    SimpleProtocol protocol = new SimpleProtocol();
    protocol.addPolicyFactory("Custom", exceptionOnSelectThrowingMockFactory());
    srcServer.mb.putProtocol(protocol);
    assertTrue(srcSession.send(createMessage("msg"), Route.parse("[Custom]")).isAccepted());
    Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
    assertEquals(ErrorCode.POLICY_ERROR, reply.getError(0).getCode());
    // Attempting any sort of full matching of the stack trace is brittle, so
    // simplify by assuming any message which mentions the source file of the
    // originating exception is good to go.
    assertTrue(reply.getError(0).getMessage().contains("RoutingTestCase"));
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) Receptor(com.yahoo.messagebus.test.Receptor) Test(org.junit.Test)

Example 35 with SimpleProtocol

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

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