Trace.removeReceiver(rcvr);
}
@Test
public void testTraceCreateTable() throws Exception {
TraceScope tableCreationSpan = Trace.startSpan("creating table", Sampler.ALWAYS);
Table table;
try {
table = TEST_UTIL.createTable("table".getBytes(),
FAMILY_BYTES);
} finally {
tableCreationSpan.close();
}
// Some table creation is async. Need to make sure that everything is full in before
// checking to see if the spans are there.
TEST_UTIL.waitFor(1000, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return rcvr.getSpans().size() >= 5;
}
});
Collection<Span> spans = rcvr.getSpans();
TraceTree traceTree = new TraceTree(spans);
Collection<Span> roots = traceTree.getRoots();
assertEquals(1, roots.size());
Span createTableRoot = roots.iterator().next();
assertEquals("creating table", createTableRoot.getDescription());
Multimap<Long, Span> spansByParentIdMap = traceTree
.getSpansByParentIdMap();
int createTableCount = 0;
for (Span s : spansByParentIdMap.get(createTableRoot.getSpanId())) {
if (s.getDescription().startsWith("MasterService.CreateTable")) {
createTableCount++;
}
}
assertTrue(createTableCount >= 1);
assertTrue(spansByParentIdMap.get(createTableRoot.getSpanId()).size() > 3);
assertTrue(spans.size() > 5);
Put put = new Put("row".getBytes());
put.add(FAMILY_BYTES, "col".getBytes(), "value".getBytes());
TraceScope putSpan = Trace.startSpan("doing put", Sampler.ALWAYS);
try {
table.put(put);
} finally {
putSpan.close();
}
spans = rcvr.getSpans();
traceTree = new TraceTree(spans);
roots = traceTree.getRoots();