Search in sources :

Example 1 with TraceTree

use of org.apache.htrace.TraceTree in project hbase by apache.

the class TestHTraceHooks method testTraceCreateTable.

@Test
public void testTraceCreateTable() throws Exception {
    TraceScope tableCreationSpan = Trace.startSpan("creating table", Sampler.ALWAYS);
    Table table;
    try {
        table = TEST_UTIL.createTable(TableName.valueOf(name.getMethodName()), 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.getSpansByParent().find(ROOT_SPAN_ID);
    assertEquals(1, roots.size());
    Span createTableRoot = roots.iterator().next();
    assertEquals("creating table", createTableRoot.getDescription());
    int createTableCount = 0;
    for (Span s : traceTree.getSpansByParent().find(createTableRoot.getSpanId())) {
        if (s.getDescription().startsWith("MasterService.CreateTable")) {
            createTableCount++;
        }
    }
    assertTrue(createTableCount >= 1);
    assertTrue(traceTree.getSpansByParent().find(createTableRoot.getSpanId()).size() > 3);
    assertTrue(spans.size() > 5);
    Put put = new Put("row".getBytes());
    put.addColumn(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.getSpansByParent().find(ROOT_SPAN_ID);
    assertEquals(2, roots.size());
    Span putRoot = null;
    for (Span root : roots) {
        if (root.getDescription().equals("doing put")) {
            putRoot = root;
        }
    }
    assertNotNull(putRoot);
}
Also used : Table(org.apache.hadoop.hbase.client.Table) TraceScope(org.apache.htrace.TraceScope) Waiter(org.apache.hadoop.hbase.Waiter) Span(org.apache.htrace.Span) TraceTree(org.apache.htrace.TraceTree) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Aggregations

Waiter (org.apache.hadoop.hbase.Waiter)1 Put (org.apache.hadoop.hbase.client.Put)1 Table (org.apache.hadoop.hbase.client.Table)1 Span (org.apache.htrace.Span)1 TraceScope (org.apache.htrace.TraceScope)1 TraceTree (org.apache.htrace.TraceTree)1 Test (org.junit.Test)1