提交 c2319bcc 编写于 作者: wu-sheng's avatar wu-sheng

Add three test utils, prepare for removing the “get” method from the Tag classes.

上级 77d43ca1
...@@ -24,5 +24,12 @@ public abstract class AbstractTag<T> { ...@@ -24,5 +24,12 @@ public abstract class AbstractTag<T> {
protected abstract void set(Span span, T tagValue); 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); public abstract T get(Span span);
} }
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 { ...@@ -40,15 +40,4 @@ public class TagsTest {
tag.set(span, 123); tag.set(span, 123);
Assert.assertEquals(123, tag.get(span).intValue()); 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());
}
} }
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());
}
}
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());
}
}
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());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册