Search in sources :

Example 31 with Receptor

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

the class PolicyFactoryTestCase method testFactory.

// //////////////////////////////////////////////////////////////////////////////
// 
// Tests
// 
// //////////////////////////////////////////////////////////////////////////////
public void testFactory() {
    Route route = Route.parse("[MyPolicy]");
    assertTrue(src.send(createMessage(), route).isAccepted());
    Reply reply = ((Receptor) src.getReplyHandler()).getReply(60);
    assertNotNull(reply);
    System.out.println(reply.getTrace());
    assertEquals(1, reply.getNumErrors());
    assertEquals(ErrorCode.UNKNOWN_POLICY, reply.getError(0).getCode());
    Protocol obj = srv.mb.getProtocol(DocumentProtocol.NAME);
    assertTrue(obj instanceof DocumentProtocol);
    DocumentProtocol protocol = (DocumentProtocol) obj;
    protocol.putRoutingPolicyFactory("MyPolicy", new MyFactory());
    assertTrue(src.send(createMessage(), route).isAccepted());
    assertNotNull(reply = ((Receptor) src.getReplyHandler()).getReply(60));
    System.out.println(reply.getTrace());
    assertEquals(1, reply.getNumErrors());
    assertEquals(DocumentProtocol.ERROR_POLICY_FAILURE, reply.getError(0).getCode());
}
Also used : Receptor(com.yahoo.messagebus.test.Receptor) DocumentProtocol(com.yahoo.documentapi.messagebus.protocol.DocumentProtocol) Route(com.yahoo.messagebus.routing.Route) DocumentProtocol(com.yahoo.documentapi.messagebus.protocol.DocumentProtocol)

Example 32 with Receptor

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

the class PolicyTestCase method testExternMultipleSlobroks.

@Test
public void testExternMultipleSlobroks() throws ListenFailedException {
    Slobrok local = new Slobrok();
    TestServer srcServer = new TestServer("src", null, local, new DocumentProtocol(manager));
    SourceSession srcSession = srcServer.mb.createSourceSession(new Receptor(), new SourceSessionParams().setTimeout(TIMEOUT));
    Slobrok extern = new Slobrok();
    String spec = "tcp/localhost:" + extern.port();
    TestServer dstServer = new TestServer("dst", null, extern, new DocumentProtocol(manager));
    Receptor dstHandler = new Receptor();
    DestinationSession dstSession = dstServer.mb.createDestinationSession("session", true, dstHandler);
    Message msg = new RemoveDocumentMessage(new DocumentId("doc:scheme:"));
    msg.setRoute(Route.parse("[Extern:" + spec + ";dst/session]"));
    assertTrue(srcSession.send(msg).isAccepted());
    assertNotNull(msg = dstHandler.getMessage(TIMEOUT));
    dstSession.acknowledge(msg);
    Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(TIMEOUT);
    assertNotNull(reply);
    extern.stop();
    dstSession.destroy();
    dstServer.destroy();
    dstHandler.reset();
    assertNull(dstHandler.getMessage(0));
    extern = new Slobrok();
    spec += ",tcp/localhost:" + extern.port();
    dstServer = new TestServer("dst", null, extern, new DocumentProtocol(manager));
    dstHandler = new Receptor();
    dstSession = dstServer.mb.createDestinationSession("session", true, dstHandler);
    msg = new RemoveDocumentMessage(new DocumentId("doc:scheme:"));
    msg.setRoute(Route.parse("[Extern:" + spec + ";dst/session]"));
    assertTrue(srcSession.send(msg).isAccepted());
    assertNotNull(msg = dstHandler.getMessage(TIMEOUT));
    dstSession.acknowledge(msg);
    reply = ((Receptor) srcSession.getReplyHandler()).getReply(TIMEOUT);
    assertNotNull(reply);
    extern.stop();
    dstSession.destroy();
    dstServer.destroy();
    local.stop();
    srcSession.destroy();
    srcServer.destroy();
}
Also used : Receptor(com.yahoo.messagebus.test.Receptor) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer) Test(org.junit.Test)

Example 33 with Receptor

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

the class SendAdapterTestCase method assertVersionedSend.

// //////////////////////////////////////////////////////////////////////////////
// 
// Utilities
// 
// //////////////////////////////////////////////////////////////////////////////
private void assertVersionedSend(Version srcVersion, Version itrVersion, Version dstVersion) {
    System.out.println("Sending from " + srcVersion + " through " + itrVersion + " to " + dstVersion + ":");
    srcServer.net.setVersion(srcVersion);
    itrServer.net.setVersion(itrVersion);
    dstServer.net.setVersion(dstVersion);
    Message msg = new SimpleMessage("foo");
    msg.getTrace().setLevel(9);
    assertTrue(srcSession.send(msg, Route.parse("itr/session dst/session")).isAccepted());
    assertNotNull(msg = ((Receptor) itrSession.getMessageHandler()).getMessage(300));
    System.out.println("\tMessage version " + srcProtocol.lastVersion + " serialized at source.");
    Version minVersion = srcVersion.compareTo(itrVersion) < 0 ? srcVersion : itrVersion;
    assertEquals(minVersion, srcProtocol.lastVersion);
    System.out.println("\tMessage version " + itrProtocol.lastVersion + " reached intermediate.");
    assertEquals(minVersion, itrProtocol.lastVersion);
    itrSession.forward(msg);
    assertNotNull(msg = ((Receptor) dstSession.getMessageHandler()).getMessage(300));
    System.out.println("\tMessage version " + itrProtocol.lastVersion + " serialized at intermediate.");
    minVersion = itrVersion.compareTo(dstVersion) < 0 ? itrVersion : dstVersion;
    assertEquals(minVersion, itrProtocol.lastVersion);
    System.out.println("\tMessage version " + dstProtocol.lastVersion + " reached destination.");
    assertEquals(minVersion, dstProtocol.lastVersion);
    Reply reply = new SimpleReply("bar");
    reply.swapState(msg);
    dstSession.reply(reply);
    assertNotNull(reply = ((Receptor) itrSession.getReplyHandler()).getReply(300));
    System.out.println("\tReply version " + dstProtocol.lastVersion + " serialized at destination.");
    assertEquals(minVersion, dstProtocol.lastVersion);
    System.out.println("\tReply version " + itrProtocol.lastVersion + " reached intermediate.");
    assertEquals(minVersion, itrProtocol.lastVersion);
    itrSession.forward(reply);
    assertNotNull(((Receptor) srcSession.getReplyHandler()).getReply(300));
    System.out.println("\tReply version " + itrProtocol.lastVersion + " serialized at intermediate.");
    minVersion = srcVersion.compareTo(itrVersion) < 0 ? srcVersion : itrVersion;
    assertEquals(minVersion, itrProtocol.lastVersion);
    System.out.println("\tReply version " + srcProtocol.lastVersion + " reached source.");
    assertEquals(minVersion, srcProtocol.lastVersion);
}
Also used : SimpleReply(com.yahoo.messagebus.test.SimpleReply) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) Version(com.yahoo.component.Version) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleReply(com.yahoo.messagebus.test.SimpleReply)

Example 34 with Receptor

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

the class SendAdapterTestCase method setUp.

@Before
public void setUp() throws ListenFailedException, UnknownHostException {
    slobrok = new Slobrok();
    dstServer = new TestServer(new MessageBusParams().addProtocol(dstProtocol = new TestProtocol()), new RPCNetworkParams().setIdentity(new Identity("dst")).setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
    dstSession = dstServer.mb.createDestinationSession(new DestinationSessionParams().setName("session").setMessageHandler(new Receptor()));
    itrServer = new TestServer(new MessageBusParams().addProtocol(itrProtocol = new TestProtocol()), new RPCNetworkParams().setIdentity(new Identity("itr")).setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
    itrSession = itrServer.mb.createIntermediateSession(new IntermediateSessionParams().setName("session").setMessageHandler(new Receptor()).setReplyHandler(new Receptor()));
    srcServer = new TestServer(new MessageBusParams().addProtocol(srcProtocol = new TestProtocol()), new RPCNetworkParams().setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
    srcSession = srcServer.mb.createSourceSession(new SourceSessionParams().setTimeout(600.0).setReplyHandler(new Receptor()));
    assertTrue(srcServer.waitSlobrok("*/session", 2));
}
Also used : Receptor(com.yahoo.messagebus.test.Receptor) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) Identity(com.yahoo.messagebus.network.Identity) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer) Before(org.junit.Before)

Example 35 with Receptor

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

the class ResenderTestCase method testRequestRetryDelay.

public void testRequestRetryDelay() {
    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) {
        replyFromDestination(msg, ErrorCode.APP_TRANSIENT_ERROR, i / 50.0);
        assertNotNull(msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60));
    }
    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));
    String trace = reply.getTrace().toString();
    System.out.println(trace);
    assertTrue(trace.contains("retry 1 in 0"));
    assertTrue(trace.contains("retry 2 in 0.02"));
    assertTrue(trace.contains("retry 3 in 0.04"));
    assertTrue(trace.contains("retry 4 in 0.06"));
    assertTrue(trace.contains("retry 5 in 0.08"));
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor)

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