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