Search in sources :

Example 6 with ServerTestDriver

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

the class MbusServerTestCase method requireThatNoBindingSetSelectedExceptionIsCaught.

@Test
public void requireThatNoBindingSetSelectedExceptionIsCaught() {
    ServerTestDriver driver = ServerTestDriver.newUnboundInstance(new MySelector(null));
    assertTrue(driver.sendMessage(new SimpleMessage("foo")));
    assertNotNull(driver.awaitErrors(ErrorCode.APP_FATAL_ERROR));
    assertTrue(driver.close());
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) ServerTestDriver(com.yahoo.messagebus.jdisc.test.ServerTestDriver) Test(org.junit.Test)

Example 7 with ServerTestDriver

use of com.yahoo.messagebus.jdisc.test.ServerTestDriver 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 8 with ServerTestDriver

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

use of com.yahoo.messagebus.jdisc.test.ServerTestDriver 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)

Example 10 with ServerTestDriver

use of com.yahoo.messagebus.jdisc.test.ServerTestDriver 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)

Aggregations

ServerTestDriver (com.yahoo.messagebus.jdisc.test.ServerTestDriver)12 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)12 Test (org.junit.Test)11 Response (com.yahoo.jdisc.Response)5 SimpleReply (com.yahoo.messagebus.test.SimpleReply)2 Request (com.yahoo.jdisc.Request)1 Error (com.yahoo.messagebus.Error)1 LinkedList (java.util.LinkedList)1