Search in sources :

Example 21 with Receptor

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

the class ChokeTestCase method testMaxSize.

@Test
public void testMaxSize() {
    int size = createMessage("msg").getApproxSize();
    int max = size * 10;
    dstServer.mb.setMaxPendingSize(max);
    List<Message> lst = new ArrayList<>();
    for (int i = 0; i < max * 2; i += size) {
        if (i < max) {
            assertEquals(i, dstServer.mb.getPendingSize());
        } else {
            assertEquals(max, dstServer.mb.getPendingSize());
        }
        assertTrue(srcSession.send(createMessage("msg"), Route.parse("dst/session")).isAccepted());
        if (i < max) {
            Message msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60);
            assertNotNull(msg);
            lst.add(msg);
        } else {
            Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
            assertNotNull(reply);
            assertEquals(1, reply.getNumErrors());
            assertEquals(ErrorCode.SESSION_BUSY, reply.getError(0).getCode());
        }
    }
    for (int i = 0; i < 5; ++i) {
        Message msg = lst.remove(0);
        dstSession.acknowledge(msg);
        Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
        assertNotNull(reply);
        assertFalse(reply.hasErrors());
        assertNotNull(msg = reply.getMessage());
        assertTrue(srcSession.send(msg, Route.parse("dst/session")).isAccepted());
        assertNotNull(msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60));
        lst.add(msg);
    }
    while (!lst.isEmpty()) {
        assertEquals(size * lst.size(), dstServer.mb.getPendingSize());
        Message msg = lst.remove(0);
        dstSession.acknowledge(msg);
        Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
        assertNotNull(reply);
        assertFalse(reply.hasErrors());
    }
    assertEquals(0, dstServer.mb.getPendingSize());
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 22 with Receptor

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

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

Example 24 with Receptor

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

the class RoutableTestCase method testMessageDiscard.

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

Example 25 with Receptor

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

the class BasicNetworkTestCase method testTimeoutsFollowMessage.

public void testTimeoutsFollowMessage() {
    SourceSessionParams params = new SourceSessionParams().setTimeout(600.0);
    SourceSession ss = src.mb.createSourceSession(new Receptor(), params);
    DestinationSession ds = dst.mb.createDestinationSession("session", true, new Receptor());
    assertTrue(src.waitSlobrok("test/dst/session", 1));
    // Test default timeouts being set.
    Message msg = new SimpleMessage("msg");
    msg.getTrace().setLevel(9);
    long now = SystemTimer.INSTANCE.milliTime();
    assertTrue(ss.send(msg, Route.parse("dst")).isAccepted());
    assertNotNull(msg = ((Receptor) ds.getMessageHandler()).getMessage(60));
    assertTrue(msg.getTimeReceived() >= now);
    assertTrue(params.getTimeout() * 1000 >= msg.getTimeRemaining());
    ds.acknowledge(msg);
    assertNotNull(((Receptor) ss.getReplyHandler()).getReply(60));
    // Test default timeouts being overwritten.
    msg = new SimpleMessage("msg");
    msg.getTrace().setLevel(9);
    msg.setTimeRemaining(2 * (long) (params.getTimeout() * 1000));
    assertTrue(ss.send(msg, Route.parse("dst")).isAccepted());
    assertNotNull(msg = ((Receptor) ds.getMessageHandler()).getMessage(60));
    assertTrue(params.getTimeout() * 1000 < msg.getTimeRemaining());
    ds.acknowledge(msg);
    assertNotNull(((Receptor) ss.getReplyHandler()).getReply(60));
    ss.destroy();
    ds.destroy();
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage)

Aggregations

Receptor (com.yahoo.messagebus.test.Receptor)69 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)46 Test (org.junit.Test)35 SimpleProtocol (com.yahoo.messagebus.test.SimpleProtocol)30 TestServer (com.yahoo.messagebus.network.rpc.test.TestServer)18 Slobrok (com.yahoo.jrt.slobrok.server.Slobrok)17 CustomPolicyFactory (com.yahoo.messagebus.routing.test.CustomPolicyFactory)12 RPCNetworkParams (com.yahoo.messagebus.network.rpc.RPCNetworkParams)10 Error (com.yahoo.messagebus.Error)9 Identity (com.yahoo.messagebus.network.Identity)9 SimpleReply (com.yahoo.messagebus.test.SimpleReply)6 DocumentProtocol (com.yahoo.documentapi.messagebus.protocol.DocumentProtocol)3 ArrayList (java.util.ArrayList)3 Before (org.junit.Before)3 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)2 Route (com.yahoo.messagebus.routing.Route)2 Version (com.yahoo.component.Version)1 VersionSpecification (com.yahoo.component.VersionSpecification)1 DocumentMessage (com.yahoo.documentapi.messagebus.protocol.DocumentMessage)1 DocumentReply (com.yahoo.documentapi.messagebus.protocol.DocumentReply)1