Search in sources :

Example 56 with Receptor

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

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

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

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

Example 60 with Receptor

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

the class RoutingTestCase method requireThatTransientErrorsAreRetried.

@Test
public void requireThatTransientErrorsAreRetried() {
    assertTrue(srcSession.send(createMessage("msg"), Route.parse("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("[APP_TRANSIENT_ERROR @ localhost]: err1", "-[APP_TRANSIENT_ERROR @ localhost]: err1", "[APP_TRANSIENT_ERROR @ localhost]: err2", "-[APP_TRANSIENT_ERROR @ localhost]: err2"), reply.getTrace());
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) Error(com.yahoo.messagebus.Error) Test(org.junit.Test)

Aggregations

Receptor (com.yahoo.messagebus.test.Receptor)69 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)46 Test (org.junit.Test)35 SimpleProtocol (com.yahoo.messagebus.test.SimpleProtocol)30 TestServer (com.yahoo.messagebus.network.rpc.test.TestServer)18 Slobrok (com.yahoo.jrt.slobrok.server.Slobrok)17 CustomPolicyFactory (com.yahoo.messagebus.routing.test.CustomPolicyFactory)12 RPCNetworkParams (com.yahoo.messagebus.network.rpc.RPCNetworkParams)10 Error (com.yahoo.messagebus.Error)9 Identity (com.yahoo.messagebus.network.Identity)9 SimpleReply (com.yahoo.messagebus.test.SimpleReply)6 DocumentProtocol (com.yahoo.documentapi.messagebus.protocol.DocumentProtocol)3 ArrayList (java.util.ArrayList)3 Before (org.junit.Before)3 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)2 Route (com.yahoo.messagebus.routing.Route)2 Version (com.yahoo.component.Version)1 VersionSpecification (com.yahoo.component.VersionSpecification)1 DocumentMessage (com.yahoo.documentapi.messagebus.protocol.DocumentMessage)1 DocumentReply (com.yahoo.documentapi.messagebus.protocol.DocumentReply)1