Search in sources :

Example 1 with QueueAdapter

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

the class LoadBalanceTestCase method testLoadBalance.

public void testLoadBalance() throws ListenFailedException, UnknownHostException {
    Slobrok slobrok = new Slobrok();
    TestServer src = new TestServer("src", null, slobrok, null);
    TestServer dst1 = new TestServer("dst/1", null, slobrok, null);
    TestServer dst2 = new TestServer("dst/2", null, slobrok, null);
    TestServer dst3 = new TestServer("dst/3", null, slobrok, null);
    // set up handlers
    final QueueAdapter sq = new QueueAdapter();
    SourceSession ss = src.mb.createSourceSession(new SourceSessionParams().setTimeout(600.0).setThrottlePolicy(null).setReplyHandler(new ReplyHandler() {

        @Override
        public void handleReply(Reply reply) {
            System.out.println(Thread.currentThread().getName() + ": Reply '" + ((SimpleMessage) reply.getMessage()).getValue() + "' received at source.");
            sq.handleReply(reply);
        }
    }));
    SimpleDestination h1 = new SimpleDestination(dst1.mb, dst1.net.getIdentity());
    SimpleDestination h2 = new SimpleDestination(dst2.mb, dst2.net.getIdentity());
    SimpleDestination h3 = new SimpleDestination(dst3.mb, dst3.net.getIdentity());
    assertTrue(src.waitSlobrok("dst/*/session", 3));
    // send messages
    // should be divisible by 3
    int msgCnt = 30;
    for (int i = 0; i < msgCnt; ++i) {
        ss.send(new SimpleMessage("msg" + i), Route.parse("dst/*/session"));
    }
    // wait for replies
    assertTrue(sq.waitSize(msgCnt, 60));
    // check handler message distribution
    assertEquals(msgCnt / 3, h1.getCount());
    assertEquals(msgCnt / 3, h2.getCount());
    assertEquals(msgCnt / 3, h3.getCount());
    ss.destroy();
    h1.session.destroy();
    h2.session.destroy();
    h3.session.destroy();
    dst3.destroy();
    dst2.destroy();
    dst1.destroy();
    src.destroy();
    slobrok.stop();
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) QueueAdapter(com.yahoo.messagebus.test.QueueAdapter) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer)

Aggregations

Slobrok (com.yahoo.jrt.slobrok.server.Slobrok)1 TestServer (com.yahoo.messagebus.network.rpc.test.TestServer)1 QueueAdapter (com.yahoo.messagebus.test.QueueAdapter)1 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)1