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());
}
Aggregations