Search in sources :

Example 1 with SimpleMessage

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

the class RoutingContextTestCase method createMessage.

// //////////////////////////////////////////////////////////////////////////////
// 
// Utilities
// 
// //////////////////////////////////////////////////////////////////////////////
private Message createMessage(String msg) {
    Message ret = new SimpleMessage(msg);
    ret.getTrace().setLevel(9);
    return ret;
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage)

Example 2 with SimpleMessage

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

the class RoutingTestCase method createMessage.

// //////////////////////////////////////////////////////////////////////////////
// 
// Utilities
// 
// //////////////////////////////////////////////////////////////////////////////
private static Message createMessage(String msg) {
    SimpleMessage ret = new SimpleMessage(msg);
    ret.getTrace().setLevel(9);
    return ret;
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage)

Example 3 with SimpleMessage

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

Example 4 with SimpleMessage

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

the class RoutableTestCase method testMessageContext.

public void testMessageContext() throws ListenFailedException, UnknownHostException {
    Slobrok slobrok = new Slobrok();
    TestServer srcServer = new TestServer("src", null, slobrok, null);
    TestServer dstServer = new TestServer("dst", null, slobrok, null);
    SourceSession srcSession = srcServer.mb.createSourceSession(new Receptor(), new SourceSessionParams().setTimeout(600.0));
    DestinationSession dstSession = dstServer.mb.createDestinationSession("session", true, new Receptor());
    assertTrue(srcServer.waitSlobrok("dst/session", 1));
    Object context = new Object();
    Message msg = new SimpleMessage("msg");
    msg.setContext(context);
    assertTrue(srcSession.send(msg, "dst/session", true).isAccepted());
    assertNotNull(msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60));
    dstSession.acknowledge(msg);
    Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
    assertNotNull(reply);
    assertSame(reply.getContext(), context);
    srcSession.destroy();
    srcServer.destroy();
    dstSession.destroy();
    dstServer.destroy();
    slobrok.stop();
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) SimpleReply(com.yahoo.messagebus.test.SimpleReply) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer)

Example 5 with SimpleMessage

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

the class RoutableTestCase method testReplyDiscard.

public void testReplyDiscard() {
    Receptor handler = new Receptor();
    Message msg = new SimpleMessage("foo");
    msg.pushHandler(handler);
    Reply reply = new SimpleReply("bar");
    reply.swapState(msg);
    reply.discard();
    assertNull(handler.getReply(0));
}
Also used : SimpleReply(com.yahoo.messagebus.test.SimpleReply) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleReply(com.yahoo.messagebus.test.SimpleReply)

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