Search in sources :

Example 16 with Route

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

the class ClientThreadingTestCase method requireThatClientIsThreadSafe.

@Test
@Ignore
public void requireThatClientIsThreadSafe() throws Exception {
    final LocalWire wire = new LocalWire();
    final Client client = new Client(wire);
    final Server server = new Server(wire);
    final List<Callable<Boolean>> lst = new LinkedList<>();
    final Route route = Route.parse(server.session.getConnectionSpec());
    for (int i = 0; i < NUM_THREADS; ++i) {
        lst.add(new RequestTask(client, route));
    }
    final ExecutorService executor = Executors.newFixedThreadPool(NUM_THREADS);
    for (final Future<Boolean> res : executor.invokeAll(lst, 60, TimeUnit.SECONDS)) {
        assertThat(res.get(), is(true));
    }
    assertThat(client.close(), is(true));
    assertThat(server.close(), is(true));
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) LocalWire(com.yahoo.messagebus.network.local.LocalWire) Callable(java.util.concurrent.Callable) LinkedList(java.util.LinkedList) Route(com.yahoo.messagebus.routing.Route) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 17 with Route

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

the class LocalNetworkTest method requireThatLocalNetworkCanSendAndReceive.

@Test
public void requireThatLocalNetworkCanSendAndReceive() throws InterruptedException {
    final LocalWire wire = new LocalWire();
    final Server serverA = new Server(wire);
    final SourceSession source = serverA.newSourceSession();
    final Server serverB = new Server(wire);
    final IntermediateSession intermediate = serverB.newIntermediateSession();
    final Server serverC = new Server(wire);
    final DestinationSession destination = serverC.newDestinationSession();
    Message msg = new SimpleMessage("foo");
    msg.setRoute(new Route().addHop(Hop.parse(intermediate.getConnectionSpec())).addHop(Hop.parse(destination.getConnectionSpec())));
    assertThat(source.send(msg).isAccepted(), is(true));
    msg = serverB.messages.poll(60, TimeUnit.SECONDS);
    assertThat(msg, instanceOf(SimpleMessage.class));
    assertThat(((SimpleMessage) msg).getValue(), is("foo"));
    intermediate.forward(msg);
    msg = serverC.messages.poll(60, TimeUnit.SECONDS);
    assertThat(msg, instanceOf(SimpleMessage.class));
    assertThat(((SimpleMessage) msg).getValue(), is("foo"));
    Reply reply = new SimpleReply("bar");
    reply.swapState(msg);
    destination.reply(reply);
    reply = serverB.replies.poll(60, TimeUnit.SECONDS);
    assertThat(reply, instanceOf(SimpleReply.class));
    assertThat(((SimpleReply) reply).getValue(), is("bar"));
    intermediate.forward(reply);
    reply = serverA.replies.poll(60, TimeUnit.SECONDS);
    assertThat(reply, instanceOf(SimpleReply.class));
    assertThat(((SimpleReply) reply).getValue(), is("bar"));
    serverA.mbus.destroy();
    serverB.mbus.destroy();
    serverC.mbus.destroy();
}
Also used : SimpleReply(com.yahoo.messagebus.test.SimpleReply) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleReply(com.yahoo.messagebus.test.SimpleReply) Route(com.yahoo.messagebus.routing.Route) Test(org.junit.Test)

Example 18 with Route

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

the class LocalNetworkTest method requireThatBlockingSendTimeOutInSendQ.

@Test
public void requireThatBlockingSendTimeOutInSendQ() throws InterruptedException {
    final LocalWire wire = new LocalWire();
    final Server serverA = new Server(wire);
    final SourceSession source = serverA.newSourceSession(new StaticThrottlePolicy().setMaxPendingCount(1));
    final Server serverB = new Server(wire);
    final IntermediateSession intermediate = serverB.newIntermediateSession();
    final Server serverC = new Server(wire);
    final DestinationSession destination = serverC.newDestinationSession();
    Message msg = new SimpleMessage("foo");
    msg.setRoute(new Route().addHop(Hop.parse(intermediate.getConnectionSpec())).addHop(Hop.parse(destination.getConnectionSpec())));
    assertThat(source.sendBlocking(msg).isAccepted(), is(true));
    long start = SystemTimer.INSTANCE.milliTime();
    Message msg2 = new SimpleMessage("foo2");
    msg2.setRoute(new Route().addHop(Hop.parse(intermediate.getConnectionSpec())).addHop(Hop.parse(destination.getConnectionSpec())));
    long TIMEOUT = 1000;
    msg2.setTimeRemaining(TIMEOUT);
    Result res = source.sendBlocking(msg2);
    assertThat(res.isAccepted(), is(false));
    assertEquals(ErrorCode.TIMEOUT, res.getError().getCode());
    assertTrue(res.getError().getMessage().endsWith("Timed out in sendQ"));
    long end = SystemTimer.INSTANCE.milliTime();
    assertThat(end, greaterThanOrEqualTo(start + TIMEOUT));
    assertThat(end, lessThan(start + 5 * TIMEOUT));
    msg = serverB.messages.poll(60, TimeUnit.SECONDS);
    assertThat(msg, instanceOf(SimpleMessage.class));
    assertThat(((SimpleMessage) msg).getValue(), is("foo"));
    intermediate.forward(msg);
    msg = serverC.messages.poll(60, TimeUnit.SECONDS);
    assertThat(msg, instanceOf(SimpleMessage.class));
    assertThat(((SimpleMessage) msg).getValue(), is("foo"));
    Reply reply = new SimpleReply("bar");
    reply.swapState(msg);
    destination.reply(reply);
    reply = serverB.replies.poll(60, TimeUnit.SECONDS);
    assertThat(reply, instanceOf(SimpleReply.class));
    assertThat(((SimpleReply) reply).getValue(), is("bar"));
    intermediate.forward(reply);
    reply = serverA.replies.poll(60, TimeUnit.SECONDS);
    assertEquals(ErrorCode.TIMEOUT, reply.getError(0).getCode());
    assertTrue(reply.getError(0).getMessage().endsWith("Timed out in sendQ"));
    reply = serverA.replies.poll(60, TimeUnit.SECONDS);
    assertThat(reply, instanceOf(SimpleReply.class));
    assertThat(((SimpleReply) reply).getValue(), is("bar"));
    serverA.mbus.destroy();
    serverB.mbus.destroy();
    serverC.mbus.destroy();
}
Also used : SimpleReply(com.yahoo.messagebus.test.SimpleReply) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleReply(com.yahoo.messagebus.test.SimpleReply) Route(com.yahoo.messagebus.routing.Route) Test(org.junit.Test)

Example 19 with Route

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

the class RPCSend method send.

@Override
public final void send(RoutingNode recipient, Version version, byte[] payload, long timeRemaining) {
    SendContext ctx = new SendContext(recipient, timeRemaining);
    RPCServiceAddress address = (RPCServiceAddress) recipient.getServiceAddress();
    Message msg = recipient.getMessage();
    Route route = new Route(recipient.getRoute());
    Hop hop = route.removeHop(0);
    Request req = encodeRequest(version, route, address, msg, timeRemaining, payload, ctx.trace.getLevel());
    if (ctx.trace.shouldTrace(TraceLevel.SEND_RECEIVE)) {
        ctx.trace.trace(TraceLevel.SEND_RECEIVE, "Sending message (version " + version + ") from " + clientIdent + " to '" + address.getServiceName() + "' with " + ctx.timeout + " seconds timeout.");
    }
    if (hop.getIgnoreResult()) {
        address.getTarget().getJRTTarget().invokeVoid(req);
        if (ctx.trace.shouldTrace(TraceLevel.SEND_RECEIVE)) {
            ctx.trace.trace(TraceLevel.SEND_RECEIVE, "Not waiting for a reply from '" + address.getServiceName() + "'.");
        }
        Reply reply = new EmptyReply();
        reply.getTrace().swap(ctx.trace);
        net.getOwner().deliverReply(reply, recipient);
    } else {
        req.setContext(ctx);
        address.getTarget().getJRTTarget().invokeAsync(req, ctx.timeout, this);
    }
    // allow garbage collection of request parameters
    req.discardParameters();
}
Also used : Message(com.yahoo.messagebus.Message) Hop(com.yahoo.messagebus.routing.Hop) Request(com.yahoo.jrt.Request) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) Route(com.yahoo.messagebus.routing.Route) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 20 with Route

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

the class CustomPolicyFactory method parseRoutes.

public static List<Route> parseRoutes(String routes) {
    List<Route> ret = new ArrayList<Route>();
    if (routes != null && !routes.isEmpty()) {
        for (String route : routes.split(",")) {
            Route r = Route.parse(route);
            assert (route.equals(r.toString()));
            ret.add(r);
        }
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) Route(com.yahoo.messagebus.routing.Route)

Aggregations

Route (com.yahoo.messagebus.routing.Route)27 Test (org.junit.Test)11 Hop (com.yahoo.messagebus.routing.Hop)5 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)5 RoutingTable (com.yahoo.messagebus.routing.RoutingTable)4 SimpleReply (com.yahoo.messagebus.test.SimpleReply)4 Message (com.yahoo.messagebus.Message)3 Utf8String (com.yahoo.text.Utf8String)3 DocumentMessage (com.yahoo.documentapi.messagebus.protocol.DocumentMessage)2 DocumentProtocol (com.yahoo.documentapi.messagebus.protocol.DocumentProtocol)2 PutDocumentMessage (com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)2 RemoveDocumentMessage (com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage)2 UpdateDocumentMessage (com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage)2 EmptyReply (com.yahoo.messagebus.EmptyReply)2 Reply (com.yahoo.messagebus.Reply)2 MessageQueue (com.yahoo.messagebus.jdisc.test.MessageQueue)2 RemoteClient (com.yahoo.messagebus.jdisc.test.RemoteClient)2 ErrorDirective (com.yahoo.messagebus.routing.ErrorDirective)2 RouteSpec (com.yahoo.messagebus.routing.RouteSpec)2 RoutingTableSpec (com.yahoo.messagebus.routing.RoutingTableSpec)2