|
@@ -25,11 +25,8 @@ import org.apache.hadoop.fs.Path;
|
|
|
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
|
import org.apache.hadoop.hdfs.DistributedFileSystem;
|
|
|
import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
|
-import org.apache.hadoop.test.GenericTestUtils;
|
|
|
-import org.apache.htrace.HTraceConfiguration;
|
|
|
import org.apache.htrace.Sampler;
|
|
|
import org.apache.htrace.Span;
|
|
|
-import org.apache.htrace.SpanReceiver;
|
|
|
import org.apache.htrace.Trace;
|
|
|
import org.apache.htrace.TraceScope;
|
|
|
import org.junit.After;
|
|
@@ -37,17 +34,10 @@ import org.junit.Assert;
|
|
|
import org.junit.Before;
|
|
|
import org.junit.BeforeClass;
|
|
|
import org.junit.Test;
|
|
|
-
|
|
|
import java.io.IOException;
|
|
|
import java.nio.ByteBuffer;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.concurrent.ConcurrentHashMap;
|
|
|
-import java.util.concurrent.TimeoutException;
|
|
|
-
|
|
|
-import com.google.common.base.Supplier;
|
|
|
|
|
|
public class TestTracing {
|
|
|
|
|
@@ -60,9 +50,9 @@ public class TestTracing {
|
|
|
// write and read without tracing started
|
|
|
String fileName = "testTracingDisabled.dat";
|
|
|
writeTestFile(fileName);
|
|
|
- Assert.assertTrue(SetSpanReceiver.SetHolder.size() == 0);
|
|
|
+ Assert.assertTrue(SetSpanReceiver.size() == 0);
|
|
|
readTestFile(fileName);
|
|
|
- Assert.assertTrue(SetSpanReceiver.SetHolder.size() == 0);
|
|
|
+ Assert.assertTrue(SetSpanReceiver.size() == 0);
|
|
|
|
|
|
writeWithTracing();
|
|
|
readWithTracing();
|
|
@@ -91,10 +81,10 @@ public class TestTracing {
|
|
|
"org.apache.hadoop.hdfs.protocol.ClientProtocol.addBlock",
|
|
|
"ClientNamenodeProtocol#addBlock"
|
|
|
};
|
|
|
- assertSpanNamesFound(expectedSpanNames);
|
|
|
+ SetSpanReceiver.assertSpanNamesFound(expectedSpanNames);
|
|
|
|
|
|
// The trace should last about the same amount of time as the test
|
|
|
- Map<String, List<Span>> map = SetSpanReceiver.SetHolder.getMap();
|
|
|
+ Map<String, List<Span>> map = SetSpanReceiver.getMap();
|
|
|
Span s = map.get("testWriteTraceHooks").get(0);
|
|
|
Assert.assertNotNull(s);
|
|
|
long spanStart = s.getStartTimeMillis();
|
|
@@ -127,7 +117,7 @@ public class TestTracing {
|
|
|
.get(0).getTimelineAnnotations()
|
|
|
.get(0).getMessage());
|
|
|
|
|
|
- SetSpanReceiver.SetHolder.spans.clear();
|
|
|
+ SetSpanReceiver.clear();
|
|
|
}
|
|
|
|
|
|
public void readWithTracing() throws Exception {
|
|
@@ -145,10 +135,10 @@ public class TestTracing {
|
|
|
"ClientNamenodeProtocol#getBlockLocations",
|
|
|
"OpReadBlockProto"
|
|
|
};
|
|
|
- assertSpanNamesFound(expectedSpanNames);
|
|
|
+ SetSpanReceiver.assertSpanNamesFound(expectedSpanNames);
|
|
|
|
|
|
// The trace should last about the same amount of time as the test
|
|
|
- Map<String, List<Span>> map = SetSpanReceiver.SetHolder.getMap();
|
|
|
+ Map<String, List<Span>> map = SetSpanReceiver.getMap();
|
|
|
Span s = map.get("testReadTraceHooks").get(0);
|
|
|
Assert.assertNotNull(s);
|
|
|
|
|
@@ -159,10 +149,10 @@ public class TestTracing {
|
|
|
|
|
|
// There should only be one trace id as it should all be homed in the
|
|
|
// top trace.
|
|
|
- for (Span span : SetSpanReceiver.SetHolder.spans.values()) {
|
|
|
+ for (Span span : SetSpanReceiver.getSpans()) {
|
|
|
Assert.assertEquals(ts.getSpan().getTraceId(), span.getTraceId());
|
|
|
}
|
|
|
- SetSpanReceiver.SetHolder.spans.clear();
|
|
|
+ SetSpanReceiver.clear();
|
|
|
}
|
|
|
|
|
|
private void writeTestFile(String testFileName) throws Exception {
|
|
@@ -211,7 +201,7 @@ public class TestTracing {
|
|
|
.build();
|
|
|
cluster.waitActive();
|
|
|
dfs = cluster.getFileSystem();
|
|
|
- SetSpanReceiver.SetHolder.spans.clear();
|
|
|
+ SetSpanReceiver.clear();
|
|
|
}
|
|
|
|
|
|
@After
|
|
@@ -219,68 +209,4 @@ public class TestTracing {
|
|
|
cluster.shutdown();
|
|
|
}
|
|
|
|
|
|
- static void assertSpanNamesFound(final String[] expectedSpanNames) {
|
|
|
- try {
|
|
|
- GenericTestUtils.waitFor(new Supplier<Boolean>() {
|
|
|
- @Override
|
|
|
- public Boolean get() {
|
|
|
- Map<String, List<Span>> map = SetSpanReceiver.SetHolder.getMap();
|
|
|
- for (String spanName : expectedSpanNames) {
|
|
|
- if (!map.containsKey(spanName)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
- }, 100, 1000);
|
|
|
- } catch (TimeoutException e) {
|
|
|
- Assert.fail("timed out to get expected spans: " + e.getMessage());
|
|
|
- } catch (InterruptedException e) {
|
|
|
- Assert.fail("interrupted while waiting spans: " + e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Span receiver that puts all spans into a single set.
|
|
|
- * This is useful for testing.
|
|
|
- * <p/>
|
|
|
- * We're not using HTrace's POJOReceiver here so as that doesn't
|
|
|
- * push all the metrics to a static place, and would make testing
|
|
|
- * SpanReceiverHost harder.
|
|
|
- */
|
|
|
- public static class SetSpanReceiver implements SpanReceiver {
|
|
|
-
|
|
|
- public SetSpanReceiver(HTraceConfiguration conf) {
|
|
|
- }
|
|
|
-
|
|
|
- public void receiveSpan(Span span) {
|
|
|
- SetHolder.spans.put(span.getSpanId(), span);
|
|
|
- }
|
|
|
-
|
|
|
- public void close() {
|
|
|
- }
|
|
|
-
|
|
|
- public static class SetHolder {
|
|
|
- public static ConcurrentHashMap<Long, Span> spans =
|
|
|
- new ConcurrentHashMap<Long, Span>();
|
|
|
-
|
|
|
- public static int size() {
|
|
|
- return spans.size();
|
|
|
- }
|
|
|
-
|
|
|
- public static Map<String, List<Span>> getMap() {
|
|
|
- Map<String, List<Span>> map = new HashMap<String, List<Span>>();
|
|
|
-
|
|
|
- for (Span s : spans.values()) {
|
|
|
- List<Span> l = map.get(s.getDescription());
|
|
|
- if (l == null) {
|
|
|
- l = new LinkedList<Span>();
|
|
|
- map.put(s.getDescription(), l);
|
|
|
- }
|
|
|
- l.add(s);
|
|
|
- }
|
|
|
- return map;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|