Search in sources :

Example 66 with Receptor

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

the class BasicNetworkTestCase method testNetwork.

public void testNetwork() {
    // set up receptors
    Receptor src_rr = new Receptor();
    Receptor pxy_mr = new Receptor();
    Receptor pxy_rr = new Receptor();
    Receptor dst_mr = new Receptor();
    // set up sessions
    SourceSessionParams sp = new SourceSessionParams();
    sp.setTimeout(30.0);
    SourceSession ss = src.mb.createSourceSession(src_rr, sp);
    IntermediateSession is = pxy.mb.createIntermediateSession("session", true, pxy_mr, pxy_rr);
    DestinationSession ds = dst.mb.createDestinationSession("session", true, dst_mr);
    // wait for slobrok registration
    assertTrue(src.waitSlobrok("test/pxy/session", 1));
    assertTrue(src.waitSlobrok("test/dst/session", 1));
    assertTrue(pxy.waitSlobrok("test/dst/session", 1));
    // send message on client
    ss.send(new SimpleMessage("test message"), "test");
    // check message on proxy
    Message msg = pxy_mr.getMessage(60);
    assertTrue(msg != null);
    assertEquals(SimpleProtocol.MESSAGE, msg.getType());
    SimpleMessage sm = (SimpleMessage) msg;
    assertEquals("test message", sm.getValue());
    // forward message on proxy
    sm.setValue(sm.getValue() + " pxy");
    is.forward(sm);
    // check message on server
    msg = dst_mr.getMessage(60);
    assertTrue(msg != null);
    assertEquals(SimpleProtocol.MESSAGE, msg.getType());
    sm = (SimpleMessage) msg;
    assertEquals("test message pxy", sm.getValue());
    // send reply on server
    SimpleReply sr = new SimpleReply("test reply");
    sm.swapState(sr);
    ds.reply(sr);
    // check reply on proxy
    Reply reply = pxy_rr.getReply(60);
    assertTrue(reply != null);
    assertEquals(SimpleProtocol.REPLY, reply.getType());
    sr = (SimpleReply) reply;
    assertEquals("test reply", sr.getValue());
    // forward reply on proxy
    sr.setValue(sr.getValue() + " pxy");
    is.forward(sr);
    // check reply on client
    reply = src_rr.getReply(60);
    assertTrue(reply != null);
    assertEquals(SimpleProtocol.REPLY, reply.getType());
    sr = (SimpleReply) reply;
    assertEquals("test reply pxy", sr.getValue());
    ss.destroy();
    is.destroy();
    ds.destroy();
}
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 67 with Receptor

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

the class PolicyFactoryTestCase method setUp.

@Override
public void setUp() throws ListenFailedException {
    slobrok = new Slobrok();
    srv = new TestServer(new MessageBusParams().addProtocol(new DocumentProtocol(new DocumentTypeManager())), new RPCNetworkParams().setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
    src = srv.mb.createSourceSession(new SourceSessionParams().setReplyHandler(new Receptor()));
}
Also used : Receptor(com.yahoo.messagebus.test.Receptor) RPCNetworkParams(com.yahoo.messagebus.network.rpc.RPCNetworkParams) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer) DocumentProtocol(com.yahoo.documentapi.messagebus.protocol.DocumentProtocol)

Example 68 with Receptor

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

the class RoutableFactoryTestCase method setUp.

@Override
public void setUp() throws ListenFailedException {
    slobrok = new Slobrok();
    DocumentTypeManager docMan = new DocumentTypeManager();
    dstProtocol = new DocumentProtocol(docMan);
    dstServer = new TestServer(new MessageBusParams().addProtocol(dstProtocol), new RPCNetworkParams().setIdentity(new Identity("dst")).setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
    dstSession = dstServer.mb.createDestinationSession(new DestinationSessionParams().setName("session").setMessageHandler(new Receptor()));
    srcProtocol = new DocumentProtocol(docMan);
    srcServer = new TestServer(new MessageBusParams().addProtocol(srcProtocol), new RPCNetworkParams().setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
    srcSession = srcServer.mb.createSourceSession(new SourceSessionParams().setReplyHandler(new Receptor()));
    assertTrue(srcServer.waitSlobrok("dst/session", 1));
}
Also used : Receptor(com.yahoo.messagebus.test.Receptor) RPCNetworkParams(com.yahoo.messagebus.network.rpc.RPCNetworkParams) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) Identity(com.yahoo.messagebus.network.Identity) DocumentProtocol(com.yahoo.documentapi.messagebus.protocol.DocumentProtocol) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer)

Example 69 with Receptor

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

the class RoutableFactoryTestCase method testFactory.

// //////////////////////////////////////////////////////////////////////////////
// 
// Tests
// 
// //////////////////////////////////////////////////////////////////////////////
public void testFactory() {
    Route route = Route.parse("dst/session");
    // Source should fail to encode the message.
    assertTrue(srcSession.send(new MyMessage(), route).isAccepted());
    Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
    assertNotNull(reply);
    System.out.println(reply.getTrace());
    assertTrue(reply.hasErrors());
    assertEquals(ErrorCode.ENCODE_ERROR, reply.getError(0).getCode());
    assertNull(reply.getError(0).getService());
    // Destination should fail to decode the message.
    srcProtocol.putRoutableFactory(MyMessage.TYPE, new MyMessageFactory(), new VersionSpecification());
    assertTrue(srcSession.send(new MyMessage(), route).isAccepted());
    assertNotNull(reply = ((Receptor) srcSession.getReplyHandler()).getReply(60));
    System.out.println(reply.getTrace());
    assertTrue(reply.hasErrors());
    assertEquals(ErrorCode.DECODE_ERROR, reply.getError(0).getCode());
    assertEquals("dst/session", reply.getError(0).getService());
    // Destination should fail to encode the reply.
    dstProtocol.putRoutableFactory(MyMessage.TYPE, new MyMessageFactory(), new VersionSpecification());
    assertTrue(srcSession.send(new MyMessage(), route).isAccepted());
    Message msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60);
    assertNotNull(msg);
    reply = new MyReply();
    reply.swapState(msg);
    dstSession.reply(reply);
    assertNotNull(reply = ((Receptor) srcSession.getReplyHandler()).getReply(60));
    System.out.println(reply.getTrace());
    assertTrue(reply.hasErrors());
    assertEquals(ErrorCode.ENCODE_ERROR, reply.getError(0).getCode());
    assertEquals("dst/session", reply.getError(0).getService());
    // Source should fail to decode the reply.
    dstProtocol.putRoutableFactory(MyReply.TYPE, new MyReplyFactory(), new VersionSpecification());
    assertTrue(srcSession.send(new MyMessage(), route).isAccepted());
    assertNotNull(msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60));
    reply = new MyReply();
    reply.swapState(msg);
    dstSession.reply(reply);
    assertNotNull(reply = ((Receptor) srcSession.getReplyHandler()).getReply(60));
    System.out.println(reply.getTrace());
    assertTrue(reply.hasErrors());
    assertEquals(ErrorCode.DECODE_ERROR, reply.getError(0).getCode());
    assertNull(reply.getError(0).getService());
    // All should succeed.
    srcProtocol.putRoutableFactory(MyReply.TYPE, new MyReplyFactory(), new VersionSpecification());
    assertTrue(srcSession.send(new MyMessage(), route).isAccepted());
    assertNotNull(msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60));
    reply = new MyReply();
    reply.swapState(msg);
    dstSession.reply(reply);
    assertNotNull(reply = ((Receptor) srcSession.getReplyHandler()).getReply(60));
    System.out.println(reply.getTrace());
    assertFalse(reply.hasErrors());
}
Also used : VersionSpecification(com.yahoo.component.VersionSpecification) DocumentMessage(com.yahoo.documentapi.messagebus.protocol.DocumentMessage) Receptor(com.yahoo.messagebus.test.Receptor) DocumentReply(com.yahoo.documentapi.messagebus.protocol.DocumentReply) Route(com.yahoo.messagebus.routing.Route)

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