Search in sources :

Example 41 with Response

use of com.yahoo.jdisc.Response in project vespa by vespa-engine.

the class MbusClientTestCase method requireThatStateIsTransferredToResponse.

@Test
public void requireThatStateIsTransferredToResponse() {
    ClientTestDriver driver = ClientTestDriver.newInstance();
    MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    Message msg = new SimpleMessage("foo");
    Object pushedCtx = new Object();
    msg.setContext(pushedCtx);
    ReplyHandler pushedHandler = new MyReplyHandler();
    msg.pushHandler(pushedHandler);
    Object currentCtx = new Object();
    msg.setContext(currentCtx);
    msg.getTrace().setLevel(6);
    assertTrue(driver.sendMessage(msg, responseHandler));
    assertTrue(driver.awaitMessageAndSendReply(new EmptyReply()));
    Response response = responseHandler.awaitResponse();
    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) SimpleReply(com.yahoo.messagebus.test.SimpleReply) Test(org.junit.Test)

Example 42 with Response

use of com.yahoo.jdisc.Response in project vespa by vespa-engine.

the class MbusClientTestCase method requireThatStateIsTransferredToSyncMbusSendFailureResponse.

@Test
public void requireThatStateIsTransferredToSyncMbusSendFailureResponse() {
    ClientTestDriver driver = ClientTestDriver.newInstance();
    driver.sourceSession().close();
    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);
    MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    driver.sendMessage(msg, responseHandler);
    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) SimpleReply(com.yahoo.messagebus.test.SimpleReply) Test(org.junit.Test)

Example 43 with Response

use of com.yahoo.jdisc.Response in project vespa by vespa-engine.

the class MbusClientTestCase method requireThatSyncMbusSendFailureRespondsWithError.

@Test
public void requireThatSyncMbusSendFailureRespondsWithError() {
    ClientTestDriver driver = ClientTestDriver.newInstance();
    driver.sourceSession().close();
    MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    driver.sendMessage(new SimpleMessage("foo"), responseHandler);
    Response response = responseHandler.awaitResponse();
    assertNotNull(response);
    assertTrue(response.getClass().getName(), response instanceof MbusResponse);
    Reply reply = ((MbusResponse) response).getReply();
    assertEquals(1, reply.getNumErrors());
    assertEquals(ErrorCode.SEND_QUEUE_CLOSED, reply.getError(0).getCode());
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) ClientTestDriver(com.yahoo.messagebus.jdisc.test.ClientTestDriver) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleReply(com.yahoo.messagebus.test.SimpleReply) Test(org.junit.Test)

Example 44 with Response

use of com.yahoo.jdisc.Response 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 45 with Response

use of com.yahoo.jdisc.Response 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)

Aggregations

Response (com.yahoo.jdisc.Response)52 Test (org.junit.Test)39 Request (com.yahoo.jdisc.Request)17 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)14 ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)11 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)11 TestDriver (com.yahoo.jdisc.test.TestDriver)10 ClientTestDriver (com.yahoo.messagebus.jdisc.test.ClientTestDriver)7 ResponseHandler (com.yahoo.jdisc.handler.ResponseHandler)6 SimpleReply (com.yahoo.messagebus.test.SimpleReply)6 ByteBuffer (java.nio.ByteBuffer)6 ServerTestDriver (com.yahoo.messagebus.jdisc.test.ServerTestDriver)5 Chain (com.yahoo.component.chain.Chain)3 HttpRequest (com.yahoo.jdisc.http.HttpRequest)3 HttpResponse (com.yahoo.jdisc.http.HttpResponse)3 NonWorkingRequest (com.yahoo.jdisc.test.NonWorkingRequest)3 Reply (com.yahoo.messagebus.Reply)3 Processor (com.yahoo.processing.Processor)3 Callable (java.util.concurrent.Callable)3 Test (org.testng.annotations.Test)3