Search in sources :

Example 1 with SimpleReply

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

the class RoutableTestCase method testReplyDiscard.

public void testReplyDiscard() {
    Receptor handler = new Receptor();
    Message msg = new SimpleMessage("foo");
    msg.pushHandler(handler);
    Reply reply = new SimpleReply("bar");
    reply.swapState(msg);
    reply.discard();
    assertNull(handler.getReply(0));
}
Also used : SimpleReply(com.yahoo.messagebus.test.SimpleReply) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleReply(com.yahoo.messagebus.test.SimpleReply)

Example 2 with SimpleReply

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

the class RoutableTestCase method testReplySwapState.

public void testReplySwapState() {
    Reply foo = new SimpleReply("foo");
    Message fooMsg = new SimpleMessage("foo");
    foo.setMessage(fooMsg);
    foo.setRetryDelay(1);
    foo.addError(new Error(ErrorCode.APP_FATAL_ERROR, "fatal"));
    foo.addError(new Error(ErrorCode.APP_TRANSIENT_ERROR, "transient"));
    Reply bar = new SimpleReply("bar");
    Message barMsg = new SimpleMessage("bar");
    bar.setMessage(barMsg);
    bar.setRetryDelay(2);
    bar.addError(new Error(ErrorCode.ERROR_LIMIT, "err"));
    foo.swapState(bar);
    assertEquals(barMsg, foo.getMessage());
    assertEquals(fooMsg, bar.getMessage());
    assertEquals(2.0, foo.getRetryDelay());
    assertEquals(1.0, bar.getRetryDelay());
    assertEquals(1, foo.getNumErrors());
    assertEquals(2, bar.getNumErrors());
}
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)

Example 3 with SimpleReply

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

the class SharedDestinationSessionTestCase method requireThatSessionCanSendReply.

@Test
public void requireThatSessionCanSendReply() throws InterruptedException {
    RemoteClient client = RemoteClient.newInstanceWithInternSlobrok();
    MessageQueue queue = new MessageQueue();
    DestinationSessionParams params = new DestinationSessionParams().setMessageHandler(queue);
    SharedDestinationSession session = newDestinationSession(client.slobrokId(), params);
    Route route = Route.parse(session.connectionSpec());
    assertTrue(client.sendMessage(new SimpleMessage("foo").setRoute(route)).isAccepted());
    Message msg = queue.awaitMessage(60, TimeUnit.SECONDS);
    assertNotNull(msg);
    Reply reply = new SimpleReply("bar");
    reply.swapState(msg);
    session.sendReply(reply);
    assertNotNull(client.awaitReply(60, TimeUnit.SECONDS));
    session.release();
    client.close();
}
Also used : SimpleReply(com.yahoo.messagebus.test.SimpleReply) MessageQueue(com.yahoo.messagebus.jdisc.test.MessageQueue) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) RemoteClient(com.yahoo.messagebus.jdisc.test.RemoteClient) SimpleReply(com.yahoo.messagebus.test.SimpleReply) Route(com.yahoo.messagebus.routing.Route) Test(org.junit.Test)

Example 4 with SimpleReply

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

the class MbusServerTestCase method assertError.

private static void assertError(List<Integer> expectedErrors, int responseStatus, int... responseErrors) {
    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());
    for (int err : responseErrors) {
        reply.addError(new Error(err, "err"));
    }
    assertTrue(requestHandler.sendResponse(new MbusResponse(responseStatus, reply)));
    assertNotNull(reply = driver.awaitReply());
    List<Integer> actual = new LinkedList<>();
    for (int i = 0; i < reply.getNumErrors(); ++i) {
        actual.add(reply.getError(i).getCode());
    }
    assertEquals(expectedErrors, actual);
    assertTrue(driver.close());
}
Also used : SimpleReply(com.yahoo.messagebus.test.SimpleReply) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleReply(com.yahoo.messagebus.test.SimpleReply) Error(com.yahoo.messagebus.Error) ServerTestDriver(com.yahoo.messagebus.jdisc.test.ServerTestDriver) LinkedList(java.util.LinkedList)

Example 5 with SimpleReply

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

the class SharedIntermediateSessionTestCase method requireThatSessionCanSendReply.

@Test
public void requireThatSessionCanSendReply() throws InterruptedException {
    RemoteClient client = RemoteClient.newInstanceWithInternSlobrok();
    MessageQueue queue = new MessageQueue();
    IntermediateSessionParams params = new IntermediateSessionParams().setMessageHandler(queue);
    SharedIntermediateSession session = newIntermediateSession(client.slobrokId(), params);
    Route route = Route.parse(session.connectionSpec());
    assertTrue(client.sendMessage(new SimpleMessage("foo").setRoute(route)).isAccepted());
    Message msg = queue.awaitMessage(60, TimeUnit.SECONDS);
    assertNotNull(msg);
    Reply reply = new SimpleReply("bar");
    reply.swapState(msg);
    session.sendReply(reply);
    assertNotNull(client.awaitReply(60, TimeUnit.SECONDS));
    session.release();
    client.close();
}
Also used : SimpleReply(com.yahoo.messagebus.test.SimpleReply) MessageQueue(com.yahoo.messagebus.jdisc.test.MessageQueue) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) RemoteClient(com.yahoo.messagebus.jdisc.test.RemoteClient) SimpleReply(com.yahoo.messagebus.test.SimpleReply) Route(com.yahoo.messagebus.routing.Route) Test(org.junit.Test)

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