Search in sources :

Example 36 with SimpleMessage

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

the class MbusClientTestCase method requireThatServerReceivesGivenMessage.

@Test
public void requireThatServerReceivesGivenMessage() {
    ClientTestDriver driver = ClientTestDriver.newInstance();
    MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    assertTrue(driver.sendMessage(new SimpleMessage("foo"), responseHandler));
    Message msg = driver.awaitMessage();
    assertTrue(msg instanceof SimpleMessage);
    assertEquals("foo", ((SimpleMessage) msg).getValue());
    Reply reply = new EmptyReply();
    reply.swapState(msg);
    driver.sendReply(reply);
    assertNotNull(responseHandler.awaitResponse());
    assertTrue(driver.close());
}
Also used : 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 37 with SimpleMessage

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

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

the class MbusClientTestCase method requireThatStateIsTransferredToTimeoutResponse.

@Test
public void requireThatStateIsTransferredToTimeoutResponse() throws InterruptedException {
    ClientTestDriver driver = ClientTestDriver.newInstance();
    MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    Message msg = new SimpleMessage("foo");
    ReplyHandler pushedHandler = new MyReplyHandler();
    Object pushedCtx = new Object();
    msg.setContext(pushedCtx);
    msg.pushHandler(pushedHandler);
    Object currentCtx = new Object();
    msg.setContext(currentCtx);
    msg.getTrace().setLevel(6);
    Request request = driver.newClientRequest(msg);
    request.setTimeout(1, TimeUnit.MILLISECONDS);
    assertTrue(driver.sendRequest(request, responseHandler));
    request.release();
    Response response = responseHandler.awaitResponse();
    assertNotNull(response);
    assertTrue(response.getClass().getName(), response instanceof MbusResponse);
    Reply reply = ((MbusResponse) response).getReply();
    assertSame(currentCtx, reply.getContext());
    assertEquals(6, reply.getTrace().getLevel());
    assertSame(pushedHandler, reply.popHandler());
    assertSame(pushedCtx, reply.getContext());
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) ClientTestDriver(com.yahoo.messagebus.jdisc.test.ClientTestDriver) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Request(com.yahoo.jdisc.Request) SimpleReply(com.yahoo.messagebus.test.SimpleReply) Test(org.junit.Test)

Example 39 with SimpleMessage

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

the class MbusServerTestCase method requireThatRequestResponseWorks.

@Test
public void requireThatRequestResponseWorks() {
    MyRequestHandler requestHandler = MyRequestHandler.newInstance();
    ServerTestDriver driver = ServerTestDriver.newInstance(requestHandler);
    assertTrue(driver.sendMessage(new SimpleMessage("foo")));
    assertNotNull(requestHandler.awaitRequest());
    assertTrue(requestHandler.sendResponse(new Response(Response.Status.OK)));
    assertNotNull(driver.awaitSuccess());
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) ServerTestDriver(com.yahoo.messagebus.jdisc.test.ServerTestDriver) Test(org.junit.Test)

Example 40 with SimpleMessage

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

the class MbusServerTestCase method requireThatResponseContentDoesNotSupportWrite.

@Test
public void requireThatResponseContentDoesNotSupportWrite() throws InterruptedException {
    MyRequestHandler requestHandler = MyRequestHandler.newInstance();
    ServerTestDriver driver = ServerTestDriver.newInstance(requestHandler);
    assertTrue(driver.sendMessage(new SimpleMessage("foo")));
    assertNotNull(requestHandler.awaitRequest());
    ContentChannel content = requestHandler.responseHandler.handleResponse(new Response(Response.Status.OK));
    assertNotNull(content);
    try {
        content.write(ByteBuffer.allocate(69), null);
        fail();
    } catch (UnsupportedOperationException e) {
    }
    content.close(null);
    assertNotNull(driver.awaitSuccess());
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) ServerTestDriver(com.yahoo.messagebus.jdisc.test.ServerTestDriver) Test(org.junit.Test)

Aggregations

SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)58 Test (org.junit.Test)38 SimpleReply (com.yahoo.messagebus.test.SimpleReply)23 Response (com.yahoo.jdisc.Response)14 Receptor (com.yahoo.messagebus.test.Receptor)13 ServerTestDriver (com.yahoo.messagebus.jdisc.test.ServerTestDriver)12 ClientTestDriver (com.yahoo.messagebus.jdisc.test.ClientTestDriver)9 TestServer (com.yahoo.messagebus.network.rpc.test.TestServer)7 Slobrok (com.yahoo.jrt.slobrok.server.Slobrok)6 Route (com.yahoo.messagebus.routing.Route)5 MessageQueue (com.yahoo.messagebus.jdisc.test.MessageQueue)4 ReplyQueue (com.yahoo.messagebus.jdisc.test.ReplyQueue)4 Request (com.yahoo.jdisc.Request)3 TestDriver (com.yahoo.jdisc.test.TestDriver)3 EmptyReply (com.yahoo.messagebus.EmptyReply)3 Reply (com.yahoo.messagebus.Reply)3 SimpleProtocol (com.yahoo.messagebus.test.SimpleProtocol)3 Error (com.yahoo.messagebus.Error)2 Message (com.yahoo.messagebus.Message)2 RemoteClient (com.yahoo.messagebus.jdisc.test.RemoteClient)2