Make MilliSpan.getTimelineAnnotations read only

This commit is contained in:
Spencer Gibb
2015-08-18 11:03:25 -06:00
parent b5f63e0cac
commit 8841d4186e
2 changed files with 17 additions and 4 deletions

View File

@@ -40,7 +40,7 @@ public class MilliSpan implements Span {
private List<String> parents;
private final String spanId;
private boolean remote = false;
private final Map<String, String> kVAnnotations = new LinkedHashMap<>();
private final Map<String, String> annotations = new LinkedHashMap<>();
private final String processId;
@Singular
private final List<TimelineAnnotation> timelineAnnotations = new ArrayList<>();
@@ -96,7 +96,7 @@ public class MilliSpan implements Span {
@Override
public void addAnnotation(String key, String value) {
this.kVAnnotations.put(key, value);
this.annotations.put(key, value);
}
@Override
@@ -107,7 +107,12 @@ public class MilliSpan implements Span {
@Override
public Map<String, String> getAnnotations() {
return Collections.unmodifiableMap(kVAnnotations);
return Collections.unmodifiableMap(this.annotations);
}
@Override
public List<TimelineAnnotation> getTimelineAnnotations() {
return Collections.unmodifiableList(this.timelineAnnotations);
}
}

View File

@@ -22,14 +22,22 @@ import org.junit.Test;
/**
* @author Rob Winch
* @author Spencer Gibb
*/
public class MilliSpanTests {
@Test(expected = UnsupportedOperationException.class)
public void getAnnotationsReadOnly() {
MilliSpan span = new MilliSpan(1, 2, "name", "traceId", Collections.<String>emptyList(), "spanId", true, "processId");
span.getAnnotations().put("a", "b");
}
@Test(expected = UnsupportedOperationException.class)
public void getTimelineAnnotationsReadOnly() {
MilliSpan span = new MilliSpan(1, 2, "name", "traceId", Collections.<String>emptyList(), "spanId", true, "processId");
span.getTimelineAnnotations().add(new TimelineAnnotation(1, "1"));
}
}