Add three test utils, prepare for removing the “get” method from the Tag classes.
This commit is contained in:
parent
77d43ca1b3
commit
c2319bcceb
|
|
@ -24,5 +24,12 @@ public abstract class AbstractTag<T> {
|
|||
|
||||
protected abstract void set(Span span, T tagValue);
|
||||
|
||||
/**
|
||||
* @return the key of this tag.
|
||||
*/
|
||||
public String key() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public abstract T get(Span span);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
package org.skywalking.apm.trace.tag;
|
||||
|
||||
import org.skywalking.apm.trace.Span;
|
||||
|
||||
/**
|
||||
* Do the same thing as {@link StringTag}, just with a {@link Short} value.
|
||||
* <p>
|
||||
* Created by wusheng on 2017/2/17.
|
||||
*/
|
||||
public class ShortTag extends AbstractTag<Short> {
|
||||
public ShortTag(String key) {
|
||||
super(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(Span span, Short tagValue) {
|
||||
span.setTag(super.key, (int) tagValue.shortValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a tag value, type of {@link Short}.
|
||||
* After akka-message/serialize, all tags values are type of {@link String}, convert to {@link Short}, if necessary.
|
||||
*
|
||||
* @param span
|
||||
* @return tag value
|
||||
*/
|
||||
@Override
|
||||
public Short get(Span span) {
|
||||
Integer tagValue = span.getIntTag(super.key);
|
||||
if (tagValue == null) {
|
||||
return null;
|
||||
} else {
|
||||
return Short.valueOf(tagValue.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -40,15 +40,4 @@ public class TagsTest {
|
|||
tag.set(span, 123);
|
||||
Assert.assertEquals(123, tag.get(span).intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShortTag() {
|
||||
ShortTag tag = new ShortTag("test.key");
|
||||
Span span = new Span(1, "/test");
|
||||
Assert.assertNull(tag.get(span));
|
||||
|
||||
short value = 123;
|
||||
tag.set(span, value);
|
||||
Assert.assertEquals(value, tag.get(span).intValue());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
package org.skywalking.apm.sniffer.mock.trace.tag;
|
||||
|
||||
import org.skywalking.apm.trace.Span;
|
||||
import org.skywalking.apm.trace.tag.BooleanTag;
|
||||
|
||||
/**
|
||||
* Test case util for getting the {@link Boolean} type of the tag value.
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
public class BooleanTagGetter {
|
||||
public static Boolean get(Span span, BooleanTag tag) {
|
||||
return span.getBoolTag(tag.key());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.skywalking.apm.sniffer.mock.trace.tag;
|
||||
|
||||
import org.skywalking.apm.trace.Span;
|
||||
import org.skywalking.apm.trace.tag.IntTag;
|
||||
|
||||
/**
|
||||
* Test case util for getting the {@link Integer} type of the tag value.
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
public class IntTagGetter {
|
||||
public static Integer get(Span span, IntTag tag) {
|
||||
return span.getIntTag(tag.key());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.skywalking.apm.sniffer.mock.trace.tag;
|
||||
|
||||
import org.skywalking.apm.trace.Span;
|
||||
import org.skywalking.apm.trace.tag.StringTag;
|
||||
|
||||
/**
|
||||
* Test case util for getting the {@link String} type of the tag value.
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
public class StringTagGetter {
|
||||
public static String get(Span span, StringTag tag) {
|
||||
return span.getStrTag(tag.key());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue