Search in sources :

Example 6 with SimpleProtocol

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

the class RoutingTestCase method requireThatSelectExceptionIsCaught.

@Test
public void requireThatSelectExceptionIsCaught() {
    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);
    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) Receptor(com.yahoo.messagebus.test.Receptor) Test(org.junit.Test)

Example 7 with SimpleProtocol

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

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

the class RoutingTestCase method setUp.

@Before
public void setUp() throws ListenFailedException, UnknownHostException {
    slobrok = new Slobrok();
    dstServer = new TestServer(new MessageBusParams().addProtocol(new SimpleProtocol()), new RPCNetworkParams().setIdentity(new Identity("dst")).setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
    dstSession = dstServer.mb.createDestinationSession(new DestinationSessionParams().setName("session").setMessageHandler(new Receptor()));
    retryPolicy = new RetryTransientErrorsPolicy();
    retryPolicy.setBaseDelay(0);
    srcServer = new TestServer(new MessageBusParams().setRetryPolicy(retryPolicy).addProtocol(new SimpleProtocol()), new RPCNetworkParams().setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
    srcSession = srcServer.mb.createSourceSession(new SourceSessionParams().setTimeout(600.0).setThrottlePolicy(null).setReplyHandler(new Receptor()));
    assertTrue(srcServer.waitSlobrok("dst/session", 1));
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) Receptor(com.yahoo.messagebus.test.Receptor) RPCNetworkParams(com.yahoo.messagebus.network.rpc.RPCNetworkParams) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) Identity(com.yahoo.messagebus.network.Identity) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer) Before(org.junit.Before)

Example 9 with SimpleProtocol

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

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

the class RoutingTestCase method requireThatReplyCanBeRemovedFromChildNodes.

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

        @Override
        public RoutingPolicy create(String param) {
            return new RemoveReplyPolicy(true, Arrays.asList(ErrorCode.NO_ADDRESS_FOR_SERVICE), CustomPolicyFactory.parseRoutes(param), 0);
        }
    });
    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());
    assertFalse(reply.hasErrors());
    assertTrace(Arrays.asList("[NO_ADDRESS_FOR_SERVICE @ localhost]", "-[NO_ADDRESS_FOR_SERVICE @ localhost]", "Sending message", "-Sending message"), 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)

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