Search in sources :

Example 6 with SimpleReply

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

the class MbusClientTestCase method requireThatClientReceivesGivenReply.

@Test
public void requireThatClientReceivesGivenReply() {
    ClientTestDriver driver = ClientTestDriver.newInstance();
    MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    assertTrue(driver.sendMessage(new SimpleMessage("foo"), responseHandler));
    // TODO: Timing sensitive
    Message msg = driver.awaitMessage();
    assertNotNull(msg);
    Reply reply = new SimpleReply("bar");
    reply.swapState(msg);
    driver.sendReply(reply);
    Response response = responseHandler.awaitResponse();
    assertTrue(response instanceof MbusResponse);
    reply = ((MbusResponse) response).getReply();
    assertTrue(reply instanceof SimpleReply);
    assertEquals("bar", ((SimpleReply) reply).getValue());
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) SimpleReply(com.yahoo.messagebus.test.SimpleReply) ClientTestDriver(com.yahoo.messagebus.jdisc.test.ClientTestDriver) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleReply(com.yahoo.messagebus.test.SimpleReply) Test(org.junit.Test)

Example 7 with SimpleReply

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

the class MbusServerTestCase method requireThatReplyInsideMbusResponseIsUsed.

@Test
public void requireThatReplyInsideMbusResponseIsUsed() {
    MyRequestHandler requestHandler = MyRequestHandler.newInstance();
    ServerTestDriver driver = ServerTestDriver.newInstance(requestHandler);
    assertTrue(driver.sendMessage(new SimpleMessage("foo")));
    assertNotNull(requestHandler.awaitRequest());
    Reply reply = new SimpleReply("bar");
    reply.swapState(((MbusRequest) requestHandler.request).getMessage());
    assertTrue(requestHandler.sendResponse(new MbusResponse(Response.Status.OK, reply)));
    reply = driver.awaitSuccess();
    assertTrue(reply instanceof SimpleReply);
    assertEquals("bar", ((SimpleReply) reply).getValue());
    assertTrue(driver.close());
}
Also used : SimpleReply(com.yahoo.messagebus.test.SimpleReply) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleReply(com.yahoo.messagebus.test.SimpleReply) ServerTestDriver(com.yahoo.messagebus.jdisc.test.ServerTestDriver) Test(org.junit.Test)

Example 8 with SimpleReply

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

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

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

the class SendAdapterTestCase method assertVersionedSend.

// //////////////////////////////////////////////////////////////////////////////
// 
// Utilities
// 
// //////////////////////////////////////////////////////////////////////////////
private void assertVersionedSend(Version srcVersion, Version itrVersion, Version dstVersion) {
    System.out.println("Sending from " + srcVersion + " through " + itrVersion + " to " + dstVersion + ":");
    srcServer.net.setVersion(srcVersion);
    itrServer.net.setVersion(itrVersion);
    dstServer.net.setVersion(dstVersion);
    Message msg = new SimpleMessage("foo");
    msg.getTrace().setLevel(9);
    assertTrue(srcSession.send(msg, Route.parse("itr/session dst/session")).isAccepted());
    assertNotNull(msg = ((Receptor) itrSession.getMessageHandler()).getMessage(300));
    System.out.println("\tMessage version " + srcProtocol.lastVersion + " serialized at source.");
    Version minVersion = srcVersion.compareTo(itrVersion) < 0 ? srcVersion : itrVersion;
    assertEquals(minVersion, srcProtocol.lastVersion);
    System.out.println("\tMessage version " + itrProtocol.lastVersion + " reached intermediate.");
    assertEquals(minVersion, itrProtocol.lastVersion);
    itrSession.forward(msg);
    assertNotNull(msg = ((Receptor) dstSession.getMessageHandler()).getMessage(300));
    System.out.println("\tMessage version " + itrProtocol.lastVersion + " serialized at intermediate.");
    minVersion = itrVersion.compareTo(dstVersion) < 0 ? itrVersion : dstVersion;
    assertEquals(minVersion, itrProtocol.lastVersion);
    System.out.println("\tMessage version " + dstProtocol.lastVersion + " reached destination.");
    assertEquals(minVersion, dstProtocol.lastVersion);
    Reply reply = new SimpleReply("bar");
    reply.swapState(msg);
    dstSession.reply(reply);
    assertNotNull(reply = ((Receptor) itrSession.getReplyHandler()).getReply(300));
    System.out.println("\tReply version " + dstProtocol.lastVersion + " serialized at destination.");
    assertEquals(minVersion, dstProtocol.lastVersion);
    System.out.println("\tReply version " + itrProtocol.lastVersion + " reached intermediate.");
    assertEquals(minVersion, itrProtocol.lastVersion);
    itrSession.forward(reply);
    assertNotNull(((Receptor) srcSession.getReplyHandler()).getReply(300));
    System.out.println("\tReply version " + itrProtocol.lastVersion + " serialized at intermediate.");
    minVersion = srcVersion.compareTo(itrVersion) < 0 ? srcVersion : itrVersion;
    assertEquals(minVersion, itrProtocol.lastVersion);
    System.out.println("\tReply version " + srcProtocol.lastVersion + " reached source.");
    assertEquals(minVersion, srcProtocol.lastVersion);
}
Also used : SimpleReply(com.yahoo.messagebus.test.SimpleReply) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) Version(com.yahoo.component.Version) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleReply(com.yahoo.messagebus.test.SimpleReply)

Aggregations

SimpleReply (com.yahoo.messagebus.test.SimpleReply)14 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)13 Test (org.junit.Test)6 Receptor (com.yahoo.messagebus.test.Receptor)5 Route (com.yahoo.messagebus.routing.Route)4 MessageQueue (com.yahoo.messagebus.jdisc.test.MessageQueue)2 RemoteClient (com.yahoo.messagebus.jdisc.test.RemoteClient)2 ServerTestDriver (com.yahoo.messagebus.jdisc.test.ServerTestDriver)2 Version (com.yahoo.component.Version)1 Response (com.yahoo.jdisc.Response)1 Slobrok (com.yahoo.jrt.slobrok.server.Slobrok)1 com.yahoo.messagebus (com.yahoo.messagebus)1 Error (com.yahoo.messagebus.Error)1 ClientTestDriver (com.yahoo.messagebus.jdisc.test.ClientTestDriver)1 Identity (com.yahoo.messagebus.network.Identity)1 RPCNetworkParams (com.yahoo.messagebus.network.rpc.RPCNetworkParams)1 TestServer (com.yahoo.messagebus.network.rpc.test.TestServer)1 SimpleProtocol (com.yahoo.messagebus.test.SimpleProtocol)1 LinkedList (java.util.LinkedList)1