Search in sources :

Example 11 with SimpleReply

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

the class SendProxyTestCase method sendMessage.

private void sendMessage(int traceLevel, Error err) {
    Message msg = new SimpleMessage("foo");
    msg.getTrace().setLevel(traceLevel);
    assertTrue(srcSession.send(msg, Route.parse("dst/session")).isAccepted());
    assertNotNull(msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60));
    if (err != null) {
        Reply reply = new SimpleReply("bar");
        reply.swapState(msg);
        reply.addError(err);
        dstSession.reply(reply);
    } else {
        dstSession.acknowledge(msg);
    }
    Reply reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
    assertNotNull(reply);
}
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 12 with SimpleReply

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

the class SimpleTripTestCase method testSimpleTrip.

public void testSimpleTrip() throws ListenFailedException, UnknownHostException {
    Slobrok slobrok = new Slobrok();
    TestServer server = new TestServer(new MessageBusParams().addProtocol(new SimpleProtocol()), new RPCNetworkParams().setIdentity(new Identity("srv")).setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
    DestinationSession dst = server.mb.createDestinationSession(new DestinationSessionParams().setName("session").setMessageHandler(new Receptor()));
    SourceSession src = server.mb.createSourceSession(new SourceSessionParams().setTimeout(600.0).setReplyHandler(new Receptor()));
    assertTrue(server.waitSlobrok("srv/session", 1));
    assertTrue(src.send(new SimpleMessage("msg"), Route.parse("srv/session")).isAccepted());
    Message msg = ((Receptor) dst.getMessageHandler()).getMessage(60);
    assertNotNull(msg);
    assertEquals(SimpleProtocol.NAME, msg.getProtocol());
    assertEquals(SimpleProtocol.MESSAGE, msg.getType());
    assertEquals("msg", ((SimpleMessage) msg).getValue());
    Reply reply = new SimpleReply("reply");
    reply.swapState(msg);
    dst.reply(reply);
    assertNotNull(reply = ((Receptor) src.getReplyHandler()).getReply(60));
    assertEquals(SimpleProtocol.NAME, reply.getProtocol());
    assertEquals(SimpleProtocol.REPLY, reply.getType());
    assertEquals("reply", ((SimpleReply) reply).getValue());
    src.destroy();
    dst.destroy();
    server.destroy();
}
Also used : SimpleReply(com.yahoo.messagebus.test.SimpleReply) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer) 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) SimpleReply(com.yahoo.messagebus.test.SimpleReply) Identity(com.yahoo.messagebus.network.Identity)

Example 13 with SimpleReply

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

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

the class PolicyTestFrame method assertMerge.

/**
 * Ensures that the current setup generates as many leaf nodes as there are members of the errors argument. Each
 * error is then given one of these errors, and the method then ensures that the single returned reply contains the
 * given list of expected errors. Finally, if the expected value argument is non-null, this method ensures that the
 * reply is a SimpleReply whose string value exists in the allowed list.
 *
 * @param replies        The errors to set in the leaf node replies.
 * @param expectedErrors The list of expected errors in the merged reply.
 * @param allowedValues  The list of allowed values in the final reply.
 */
public void assertMerge(Map<String, Integer> replies, List<Integer> expectedErrors, List<String> allowedValues) {
    List<RoutingNode> selected = select(replies.size());
    for (RoutingNode node : selected) {
        String route = node.getRoute().toString();
        assertTrue(replies.containsKey(route));
        Reply ret = new SimpleReply(route);
        if (replies.get(route) != ErrorCode.NONE) {
            ret.addError(new com.yahoo.messagebus.Error(replies.get(route), route));
        }
        node.handleReply(ret);
    }
    Reply reply = handler.getReply(60);
    assertNotNull(reply);
    if (expectedErrors != null) {
        assertEquals(expectedErrors.size(), reply.getNumErrors());
        for (int i = 0; i < expectedErrors.size(); ++i) {
            assertTrue(expectedErrors.contains(reply.getError(i).getCode()));
        }
    } else if (reply.hasErrors()) {
        StringBuilder err = new StringBuilder("Got unexpected error(s):\n");
        for (int i = 0; i < reply.getNumErrors(); ++i) {
            err.append("\t").append(reply.getError(i).toString());
            if (i < reply.getNumErrors() - 1) {
                err.append("\n");
            }
        }
        fail(err.toString());
    }
    if (allowedValues != null) {
        assertEquals(SimpleProtocol.REPLY, reply.getType());
        assertTrue(allowedValues.contains(((SimpleReply) reply).getValue()));
    } else {
        assertEquals(0, reply.getType());
    }
}
Also used : com.yahoo.messagebus(com.yahoo.messagebus) SimpleReply(com.yahoo.messagebus.test.SimpleReply) SimpleReply(com.yahoo.messagebus.test.SimpleReply)

Aggregations

SimpleReply (com.yahoo.messagebus.test.SimpleReply)14 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)13 Test (org.junit.Test)6 Receptor (com.yahoo.messagebus.test.Receptor)5 Route (com.yahoo.messagebus.routing.Route)4 MessageQueue (com.yahoo.messagebus.jdisc.test.MessageQueue)2 RemoteClient (com.yahoo.messagebus.jdisc.test.RemoteClient)2 ServerTestDriver (com.yahoo.messagebus.jdisc.test.ServerTestDriver)2 Version (com.yahoo.component.Version)1 Response (com.yahoo.jdisc.Response)1 Slobrok (com.yahoo.jrt.slobrok.server.Slobrok)1 com.yahoo.messagebus (com.yahoo.messagebus)1 Error (com.yahoo.messagebus.Error)1 ClientTestDriver (com.yahoo.messagebus.jdisc.test.ClientTestDriver)1 Identity (com.yahoo.messagebus.network.Identity)1 RPCNetworkParams (com.yahoo.messagebus.network.rpc.RPCNetworkParams)1 TestServer (com.yahoo.messagebus.network.rpc.test.TestServer)1 SimpleProtocol (com.yahoo.messagebus.test.SimpleProtocol)1 LinkedList (java.util.LinkedList)1