adding some tests

This commit is contained in:
Guillaume Polaert 2017-04-27 18:45:20 +02:00
parent 6ef772b7ac
commit df4e0eb76f
3 changed files with 3 additions and 80 deletions

View File

@ -2,7 +2,6 @@ package com.datadoghq.trace.impl;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import io.opentracing.Span;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -11,7 +10,6 @@ import java.util.Map;
public class DDSpanContext implements io.opentracing.SpanContext { public class DDSpanContext implements io.opentracing.SpanContext {
private static final String SPAN_TYPE_DEFAULT = "custom";
// Opentracing attributes // Opentracing attributes
private final long traceId; private final long traceId;
private final long spanId; private final long spanId;
@ -21,11 +19,9 @@ public class DDSpanContext implements io.opentracing.SpanContext {
private final String serviceName; private final String serviceName;
private final String resourceName; private final String resourceName;
private final boolean errorFlag; private final boolean errorFlag;
private final Map<String, Object> metrics;
private final String spanType; private final String spanType;
private final List<DDSpan> trace; private final List<DDSpan> trace;
// Others attributes // Others attributes
private boolean sampled;
private DDTracer tracer; private DDTracer tracer;
@ -37,9 +33,7 @@ public class DDSpanContext implements io.opentracing.SpanContext {
String resourceName, String resourceName,
Map<String, String> baggageItems, Map<String, String> baggageItems,
boolean errorFlag, boolean errorFlag,
Map<String, Object> metrics,
String spanType, String spanType,
boolean sampled,
List<DDSpan> trace, List<DDSpan> trace,
DDTracer tracer) { DDTracer tracer) {
@ -55,9 +49,7 @@ public class DDSpanContext implements io.opentracing.SpanContext {
this.serviceName = serviceName; this.serviceName = serviceName;
this.resourceName = resourceName; this.resourceName = resourceName;
this.errorFlag = errorFlag; this.errorFlag = errorFlag;
this.metrics = metrics;
this.spanType = spanType; this.spanType = spanType;
this.sampled = sampled;
if (trace == null) { if (trace == null) {
this.trace = new ArrayList<DDSpan>(); this.trace = new ArrayList<DDSpan>();
@ -68,22 +60,6 @@ public class DDSpanContext implements io.opentracing.SpanContext {
this.tracer = tracer; this.tracer = tracer;
} }
protected static DDSpanContext newContext(long generateId, String serviceName, String resourceName) {
DDSpanContext context = new DDSpanContext(
// Opentracing attributes
generateId, generateId, 0L,
// DD attributes
serviceName, resourceName,
// Other stuff
null, false, null,
DDSpanContext.SPAN_TYPE_DEFAULT, true,
null, null
);
return context;
}
public long getTraceId() { public long getTraceId() {
return this.traceId; return this.traceId;
} }
@ -108,18 +84,11 @@ public class DDSpanContext implements io.opentracing.SpanContext {
return errorFlag; return errorFlag;
} }
public Map<String, Object> getMetrics() {
return metrics;
}
public String getSpanType() { public String getSpanType() {
return spanType; return spanType;
} }
public boolean getSampled() {
return sampled;
}
public void setBaggageItem(String key, String value) { public void setBaggageItem(String key, String value) {
this.baggageItems.put(key, value); this.baggageItems.put(key, value);
} }

View File

@ -159,9 +159,7 @@ public class DDTracer implements io.opentracing.Tracer {
this.resourceName, this.resourceName,
this.parent == null ? null : p.getBaggageItems(), this.parent == null ? null : p.getBaggageItems(),
errorFlag, errorFlag,
null,
this.spanType, this.spanType,
true,
this.parent == null ? null : p.getTrace(), this.parent == null ? null : p.getTrace(),
DDTracer.this DDTracer.this
); );

View File

@ -8,53 +8,9 @@ import static org.assertj.core.api.Assertions.assertThat;
public class DDSpanTest { public class DDSpanTest {
@Test @Test(expected = IllegalArgumentException.class)
public void testBaggageItem() { public void shouldHaveServiceName() {
new DDTracer().buildSpan("operationName").start();
/*
DDSpanContext context = new DDSpanContext();
final String expectedBaggageItemKey = "fakeKey";
final String expectedBaggageItemValue = "fakeValue";
DDSpan span = new DDSpan(
null,
"fakeName",
null,
null,
null,
context
);
assertThat(span.context().baggageItems()).isEmpty();
span.setBaggageItem(expectedBaggageItemKey, expectedBaggageItemValue);
assertThat(span.getBaggageItem(expectedBaggageItemKey)).isEqualTo(expectedBaggageItemValue);*/
}
@Test
public void testGetSetOperationName() {
/* final String expectedOperationName1 = "fake";
final String expectedOperationName2 = "fake";
DDSpan span = new DDSpan(
null,
expectedOperationName1,
null,
null,
null,
null
);
assertThat(span.getOperationName()).isEqualTo(expectedOperationName1);
span.setOperationName(expectedOperationName2);
assertThat(span.getOperationName()).isEqualTo(expectedOperationName1);
*/
} }
} }