Search in sources :

Example 1 with LocalWire

use of com.yahoo.messagebus.network.local.LocalWire 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 2 with LocalWire

use of com.yahoo.messagebus.network.local.LocalWire in project vespa by vespa-engine.

the class ClientThreadingTestCase method requireThatClientIsThreadSafe.

@Test
@Ignore
public void requireThatClientIsThreadSafe() throws Exception {
    final LocalWire wire = new LocalWire();
    final Client client = new Client(wire);
    final Server server = new Server(wire);
    final List<Callable<Boolean>> lst = new LinkedList<>();
    final Route route = Route.parse(server.session.getConnectionSpec());
    for (int i = 0; i < NUM_THREADS; ++i) {
        lst.add(new RequestTask(client, route));
    }
    final ExecutorService executor = Executors.newFixedThreadPool(NUM_THREADS);
    for (final Future<Boolean> res : executor.invokeAll(lst, 60, TimeUnit.SECONDS)) {
        assertThat(res.get(), is(true));
    }
    assertThat(client.close(), is(true));
    assertThat(server.close(), is(true));
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) LocalWire(com.yahoo.messagebus.network.local.LocalWire) Callable(java.util.concurrent.Callable) LinkedList(java.util.LinkedList) Route(com.yahoo.messagebus.routing.Route) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

LocalWire (com.yahoo.messagebus.network.local.LocalWire)2 Test (org.junit.Test)2 EmptyReply (com.yahoo.messagebus.EmptyReply)1 Message (com.yahoo.messagebus.Message)1 Reply (com.yahoo.messagebus.Reply)1 Route (com.yahoo.messagebus.routing.Route)1 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)1 LinkedList (java.util.LinkedList)1 Callable (java.util.concurrent.Callable)1 ExecutorService (java.util.concurrent.ExecutorService)1 Ignore (org.junit.Ignore)1