Search in sources :

Example 1 with VersionSpecification

use of com.yahoo.component.VersionSpecification 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

VersionSpecification (com.yahoo.component.VersionSpecification)1 DocumentMessage (com.yahoo.documentapi.messagebus.protocol.DocumentMessage)1 DocumentReply (com.yahoo.documentapi.messagebus.protocol.DocumentReply)1 Route (com.yahoo.messagebus.routing.Route)1 Receptor (com.yahoo.messagebus.test.Receptor)1