Search in sources :

Example 11 with SimpleProtocol

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

the class ResenderTestCase method setUp.

@Override
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).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)

Example 12 with SimpleProtocol

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

the class MessageBusTestCase method testRoutingPolicyCache.

@Test
public void testRoutingPolicyCache() throws ListenFailedException, UnknownHostException {
    Slobrok slobrok = new Slobrok();
    String config = "slobrok[1]\nslobrok[0].connectionspec \"" + new Spec("localhost", slobrok.port()).toString() + "\"\n";
    SimpleProtocol protocol = new SimpleProtocol();
    protocol.addPolicyFactory("Custom", new CustomPolicyFactory());
    MessageBus bus = new MessageBus(new RPCNetwork(new RPCNetworkParams().setSlobrokConfigId("raw:" + config)), new MessageBusParams().addProtocol(protocol));
    RoutingPolicy all = bus.getRoutingPolicy(SimpleProtocol.NAME, "Custom", null);
    assertNotNull(all);
    RoutingPolicy ref = bus.getRoutingPolicy(SimpleProtocol.NAME, "Custom", null);
    assertNotNull(ref);
    assertSame(all, ref);
    RoutingPolicy allArg = bus.getRoutingPolicy(SimpleProtocol.NAME, "Custom", "Arg");
    assertNotNull(allArg);
    assertNotSame(all, allArg);
    RoutingPolicy refArg = bus.getRoutingPolicy(SimpleProtocol.NAME, "Custom", "Arg");
    assertNotNull(refArg);
    assertSame(allArg, refArg);
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) RPCNetworkParams(com.yahoo.messagebus.network.rpc.RPCNetworkParams) RPCNetwork(com.yahoo.messagebus.network.rpc.RPCNetwork) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) RoutingPolicy(com.yahoo.messagebus.routing.RoutingPolicy) Spec(com.yahoo.jrt.Spec) CustomPolicyFactory(com.yahoo.messagebus.routing.test.CustomPolicyFactory) Test(org.junit.Test)

Example 13 with SimpleProtocol

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

the class AdvancedRoutingTestCase method setUp.

@Override
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)));
    dstFoo = dstServer.mb.createDestinationSession(new DestinationSessionParams().setName("foo").setMessageHandler(new Receptor()));
    dstBar = dstServer.mb.createDestinationSession(new DestinationSessionParams().setName("bar").setMessageHandler(new Receptor()));
    dstBaz = dstServer.mb.createDestinationSession(new DestinationSessionParams().setName("baz").setMessageHandler(new Receptor()));
    srcServer = new TestServer(new MessageBusParams().setRetryPolicy(new RetryTransientErrorsPolicy().setBaseDelay(0)).addProtocol(new SimpleProtocol()), new RPCNetworkParams().setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
    srcSession = srcServer.mb.createSourceSession(new SourceSessionParams().setTimeout(600.0).setReplyHandler(new Receptor()));
    assertTrue(srcServer.waitSlobrok("dst/*", 3));
}
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)

Example 14 with SimpleProtocol

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

the class AdvancedRoutingTestCase method testAdvanced.

// //////////////////////////////////////////////////////////////////////////////
// 
// Tests
// 
// //////////////////////////////////////////////////////////////////////////////
public void testAdvanced() {
    SimpleProtocol protocol = new SimpleProtocol();
    protocol.addPolicyFactory("Custom", new CustomPolicyFactory(false, ErrorCode.NO_ADDRESS_FOR_SERVICE));
    srcServer.mb.putProtocol(protocol);
    srcServer.setupRouting(new RoutingTableSpec(SimpleProtocol.NAME).addHop(new HopSpec("bar", "dst/bar")).addHop(new HopSpec("baz", "dst/baz")).addRoute(new RouteSpec("baz").addHop("baz")));
    Message msg = new SimpleMessage("msg");
    msg.getTrace().setLevel(9);
    assertTrue(srcSession.send(msg, Route.parse("[Custom:" + dstFoo.getConnectionSpec() + ",bar,route:baz,dst/cox,?dst/unknown]")).isAccepted());
    // Initial send.
    assertNotNull(msg = ((Receptor) dstFoo.getMessageHandler()).getMessage(60));
    dstFoo.acknowledge(msg);
    assertNotNull(msg = ((Receptor) dstBar.getMessageHandler()).getMessage(60));
    Reply reply = new EmptyReply();
    reply.swapState(msg);
    reply.addError(new Error(ErrorCode.TRANSIENT_ERROR, "bar"));
    dstBar.reply(reply);
    assertNotNull(msg = ((Receptor) dstBaz.getMessageHandler()).getMessage(60));
    reply = new EmptyReply();
    reply.swapState(msg);
    reply.addError(new Error(ErrorCode.TRANSIENT_ERROR, "baz1"));
    dstBaz.reply(reply);
    // First retry.
    assertNull(((Receptor) dstFoo.getMessageHandler()).getMessage(0));
    assertNotNull(msg = ((Receptor) dstBar.getMessageHandler()).getMessage(60));
    dstBar.acknowledge(msg);
    assertNotNull(msg = ((Receptor) dstBaz.getMessageHandler()).getMessage(60));
    reply = new EmptyReply();
    reply.swapState(msg);
    reply.addError(new Error(ErrorCode.TRANSIENT_ERROR, "baz2"));
    dstBaz.reply(reply);
    // Second retry.
    assertNull(((Receptor) dstFoo.getMessageHandler()).getMessage(0));
    assertNull(((Receptor) dstBar.getMessageHandler()).getMessage(0));
    assertNotNull(msg = ((Receptor) dstBaz.getMessageHandler()).getMessage(60));
    reply = new EmptyReply();
    reply.swapState(msg);
    reply.addError(new Error(ErrorCode.FATAL_ERROR, "baz3"));
    dstBaz.reply(reply);
    // Done.
    reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
    assertNotNull(reply);
    System.out.println(reply.getTrace());
    assertEquals(2, reply.getNumErrors());
    assertEquals(ErrorCode.FATAL_ERROR, reply.getError(0).getCode());
    assertEquals(ErrorCode.NO_ADDRESS_FOR_SERVICE, reply.getError(1).getCode());
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Error(com.yahoo.messagebus.Error) CustomPolicyFactory(com.yahoo.messagebus.routing.test.CustomPolicyFactory)

Example 15 with SimpleProtocol

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

the class SharedDestinationSessionTestCase method newDestinationSession.

private static SharedDestinationSession newDestinationSession(String slobrokId, DestinationSessionParams params) {
    RPCNetworkParams netParams = new RPCNetworkParams().setSlobrokConfigId(slobrokId);
    MessageBusParams mbusParams = new MessageBusParams().addProtocol(new SimpleProtocol());
    SharedMessageBus mbus = SharedMessageBus.newInstance(mbusParams, netParams);
    SharedDestinationSession session = mbus.newDestinationSession(params);
    mbus.release();
    return session;
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) RPCNetworkParams(com.yahoo.messagebus.network.rpc.RPCNetworkParams)

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