Search in sources :

Example 21 with SimpleMessage

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

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

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

the class ServerThreadingTestCase method requireThatServerIsThreadSafe.

@Test
public void requireThatServerIsThreadSafe() throws Exception {
    final LocalWire wire = new LocalWire();
    final Client client = new Client(wire);
    final Server server = new Server(wire);
    for (int i = 0; i < NUM_REQUESTS; ++i) {
        final Message msg = new SimpleMessage("foo");
        msg.setRoute(Route.parse(server.delegate.connectionSpec()));
        msg.pushHandler(client);
        assertThat(client.session.send(msg).isAccepted(), is(true));
    }
    for (int i = 0; i < NUM_REQUESTS; ++i) {
        final Reply reply = client.replies.poll(600, TimeUnit.SECONDS);
        assertThat(reply, instanceOf(EmptyReply.class));
        assertThat(reply.hasErrors(), is(false));
    }
    assertThat(client.close(), is(true));
    assertThat(server.close(), is(true));
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Message(com.yahoo.messagebus.Message) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) EmptyReply(com.yahoo.messagebus.EmptyReply) Reply(com.yahoo.messagebus.Reply) LocalWire(com.yahoo.messagebus.network.local.LocalWire) EmptyReply(com.yahoo.messagebus.EmptyReply) Test(org.junit.Test)

Example 24 with SimpleMessage

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

the class SharedIntermediateSessionTestCase method requireThatSessionRepliesIfMessageHandlerIsNull.

@Test
public void requireThatSessionRepliesIfMessageHandlerIsNull() throws InterruptedException {
    SharedIntermediateSession session = newIntermediateSession();
    Message msg = new SimpleMessage("foo");
    ReplyQueue queue = new ReplyQueue();
    msg.pushHandler(queue);
    session.handleMessage(msg);
    Reply reply = queue.awaitReply(60, TimeUnit.SECONDS);
    assertNotNull(reply);
    assertEquals(1, reply.getNumErrors());
    assertEquals(ErrorCode.SESSION_BUSY, reply.getError(0).getCode());
    session.release();
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) ReplyQueue(com.yahoo.messagebus.jdisc.test.ReplyQueue) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleReply(com.yahoo.messagebus.test.SimpleReply) Test(org.junit.Test)

Example 25 with SimpleMessage

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

the class SharedIntermediateSessionTestCase method requireThatSessionCanSendMessage.

@Test
public void requireThatSessionCanSendMessage() throws InterruptedException {
    RemoteServer server = RemoteServer.newInstanceWithInternSlobrok();
    SharedIntermediateSession session = newIntermediateSession(server.slobrokId(), new IntermediateSessionParams());
    ReplyQueue queue = new ReplyQueue();
    Message msg = new SimpleMessage("foo").setRoute(Route.parse(server.connectionSpec()));
    msg.setTimeReceivedNow();
    msg.setTimeRemaining(60000);
    msg.getTrace().setLevel(9);
    msg.pushHandler(queue);
    assertTrue(session.sendMessage(msg).isAccepted());
    assertNotNull(msg = server.awaitMessage(60, TimeUnit.SECONDS));
    server.ackMessage(msg);
    assertNotNull(queue.awaitReply(60, TimeUnit.SECONDS));
    session.release();
    server.close();
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) ReplyQueue(com.yahoo.messagebus.jdisc.test.ReplyQueue) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) RemoteServer(com.yahoo.messagebus.jdisc.test.RemoteServer) 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