TracePlugin dPlugin = new TracePlugin(conf);
// Responders
Responder bRes = new RecursingResponder(advancedProtocol, bPlugin);
bRes.addRPCPlugin(bPlugin);
HttpServer server1 = new HttpServer(bRes, 21005);
server1.start();
Responder cRes = new EndpointResponder(advancedProtocol);
cRes.addRPCPlugin(cPlugin);
HttpServer server2 = new HttpServer(cRes, 21006);
server2.start();
Responder dRes = new EndpointResponder(advancedProtocol);
dRes.addRPCPlugin(dPlugin);
HttpServer server3 = new HttpServer(dRes, 21007);
server3.start();
// Root requestor
HttpTransceiver trans = new HttpTransceiver(
new URL("http://localhost:21005"));
GenericRequestor r = new GenericRequestor(advancedProtocol, trans);
r.addRPCPlugin(aPlugin);
GenericRecord params = new GenericData.Record(
advancedProtocol.getMessages().get("w").getRequest());
params.put("req", 1);
r.request("w", params);
// Verify counts
assertEquals(1, aPlugin.storage.getAllSpans().size());
assertEquals(3, bPlugin.storage.getAllSpans().size());
assertEquals(1, cPlugin.storage.getAllSpans().size());
assertEquals(1, dPlugin.storage.getAllSpans().size());
ID traceID = aPlugin.storage.getAllSpans().get(0).traceID;
ID rootSpanID = null;
// Verify event counts and trace ID propagation
for (Span s: aPlugin.storage.getAllSpans()) {
assertEquals(2, s.events.size());
assertTrue(Util.idsEqual(traceID, s.traceID));
assertFalse(s.complete);
rootSpanID = s.spanID;
}
for (Span s: bPlugin.storage.getAllSpans()) {
assertEquals(2, s.events.size());
assertEquals(traceID, s.traceID);
assertFalse(s.complete);
}
for (Span s: cPlugin.storage.getAllSpans()) {
assertEquals(2, s.events.size());
assertEquals(traceID, s.traceID);
assertFalse(s.complete);
}
for (Span s: dPlugin.storage.getAllSpans()) {
assertEquals(2, s.events.size());
assertEquals(traceID, s.traceID);
assertFalse(s.complete);
}
// Verify span propagation.
ID firstSpanID = aPlugin.storage.getAllSpans().get(0).spanID;
ID secondSpanID = cPlugin.storage.getAllSpans().get(0).spanID;
ID thirdSpanID = dPlugin.storage.getAllSpans().get(0).spanID;
boolean firstFound = false, secondFound = false, thirdFound = false;
for (Span s: bPlugin.storage.getAllSpans()) {
if (Util.idsEqual(s.spanID, firstSpanID)) {
firstFound = true;
}
else if (Util.idsEqual(s.spanID, secondSpanID)) {
secondFound = true;
}
else if (Util.idsEqual(s.spanID, thirdSpanID)) {
thirdFound = true;
}
}
assertTrue(firstFound);
assertTrue(secondFound);
assertTrue(thirdFound);
server1.close();
server2.close();
server3.close();
aPlugin.httpServer.close();
aPlugin.clientFacingServer.stop();
bPlugin.httpServer.close();
bPlugin.clientFacingServer.stop();
cPlugin.httpServer.close();