Search in sources :

Example 16 with Receptor

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

the class ResenderTestCase method testFatalError.

public void testFatalError() {
    assertTrue(srcSession.send(createMessage("msg"), Route.parse("dst/session")).isAccepted());
    Message msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60);
    assertNotNull(msg);
    replyFromDestination(msg, ErrorCode.APP_FATAL_ERROR, 0);
    Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
    assertNotNull(reply);
    assertTrue(reply.hasFatalErrors());
    assertNull(((Receptor) dstSession.getMessageHandler()).getMessage(0));
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor)

Example 17 with Receptor

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

the class ResenderTestCase method setUp.

@Override
public void setUp() throws ListenFailedException, UnknownHostException {
    slobrok = new Slobrok();
    dstServer = new TestServer(new MessageBusParams().addProtocol(new SimpleProtocol()), new RPCNetworkParams().setIdentity(new Identity("dst")).setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
    dstSession = dstServer.mb.createDestinationSession(new DestinationSessionParams().setName("session").setMessageHandler(new Receptor()));
    retryPolicy = new RetryTransientErrorsPolicy();
    retryPolicy.setBaseDelay(0);
    srcServer = new TestServer(new MessageBusParams().setRetryPolicy(retryPolicy).addProtocol(new SimpleProtocol()), new RPCNetworkParams().setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
    srcSession = srcServer.mb.createSourceSession(new SourceSessionParams().setTimeout(600.0).setReplyHandler(new Receptor()));
    assertTrue(srcServer.waitSlobrok("dst/session", 1));
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) Receptor(com.yahoo.messagebus.test.Receptor) RPCNetworkParams(com.yahoo.messagebus.network.rpc.RPCNetworkParams) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) Identity(com.yahoo.messagebus.network.Identity) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer)

Example 18 with Receptor

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

the class ResenderTestCase method testRetryTag.

// //////////////////////////////////////////////////////////////////////////////
// 
// Tests
// 
// //////////////////////////////////////////////////////////////////////////////
public void testRetryTag() {
    assertTrue(srcSession.send(createMessage("msg"), Route.parse("dst/session")).isAccepted());
    Message msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60);
    assertNotNull(msg);
    for (int i = 0; i < 5; ++i) {
        assertEquals(i, msg.getRetry());
        assertEquals(true, msg.getRetryEnabled());
        replyFromDestination(msg, ErrorCode.APP_TRANSIENT_ERROR, 0);
        assertNotNull(msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60));
    }
    dstSession.acknowledge(msg);
    Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
    assertNotNull(reply);
    assertFalse(reply.hasErrors());
    assertNull(((Receptor) dstSession.getMessageHandler()).getMessage(0));
    System.out.println(reply.getTrace());
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor)

Example 19 with Receptor

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

the class ResenderTestCase method testRetryEnabledTag.

public void testRetryEnabledTag() {
    Message msg = createMessage("msg");
    msg.setRetryEnabled(false);
    assertTrue(srcSession.send(msg, Route.parse("dst/session")).isAccepted());
    assertNotNull(msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60));
    assertEquals(false, msg.getRetryEnabled());
    replyFromDestination(msg, ErrorCode.APP_TRANSIENT_ERROR, 0);
    Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
    assertNotNull(reply);
    assertTrue(reply.hasErrors());
    assertNull(((Receptor) dstSession.getMessageHandler()).getMessage(0));
    System.out.println(reply.getTrace());
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor)

Example 20 with Receptor

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

the class ChokeTestCase method testMaxCount.

@Test
public void testMaxCount() {
    int max = 10;
    dstServer.mb.setMaxPendingCount(max);
    List<Message> lst = new ArrayList<>();
    for (int i = 0; i < max * 2; ++i) {
        if (i < max) {
            assertEquals(i, dstServer.mb.getPendingCount());
        } else {
            assertEquals(max, dstServer.mb.getPendingCount());
        }
        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(lst.size(), dstServer.mb.getPendingCount());
        Message msg = lst.remove(0);
        dstSession.acknowledge(msg);
        Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
        assertNotNull(reply);
        assertFalse(reply.hasErrors());
    }
    assertEquals(0, dstServer.mb.getPendingCount());
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) ArrayList(java.util.ArrayList) Test(org.junit.Test)

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