提交 15684ea9 编写于 作者: P pengys5

segment entity testcase

上级 d772b95c
package com.a.eye.skywalking.collector.worker.segment.entity;
import com.google.gson.stream.JsonReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
/**
* @author pengys5
*/
public class LogDataTestCase {
@Test
public void deserialize() throws IOException {
LogData logData = new LogData();
JsonReader reader = new JsonReader(new StringReader("{\"tm\":1, \"fi\": {\"test1\":\"test1\",\"test2\":\"test2\"}, \"skip\":\"skip\"}"));
logData.deserialize(reader);
Assert.assertEquals(1L, logData.getTime());
Map<String, String> fields = logData.getFields();
Assert.assertEquals("test1", fields.get("test1"));
Assert.assertEquals("test2", fields.get("test2"));
Assert.assertEquals(false, fields.containsKey("skip"));
}
}
package com.a.eye.skywalking.collector.worker.segment.entity;
import org.junit.Assert;
import org.junit.Test;
/**
* @author pengys5
*/
public class SpanViewTestCase {
@Test
public void test() {
SpanView spanView = new SpanView();
spanView.setSpanId(1);
Assert.assertEquals(1, spanView.getSpanId());
spanView.setSegId("1");
Assert.assertEquals("1", spanView.getSegId());
spanView.setAppCode("2");
Assert.assertEquals("2", spanView.getAppCode());
spanView.setRelativeStartTime(10L);
Assert.assertEquals(10L, spanView.getRelativeStartTime());
spanView.setCost(20L);
Assert.assertEquals(20L, spanView.getCost());
spanView.setOperationName("3");
Assert.assertEquals("3", spanView.getOperationName());
SpanView child = new SpanView();
spanView.addChild(child);
spanView.compareTo(child);
}
}
package com.a.eye.skywalking.collector.worker.segment.entity;
import com.google.gson.stream.JsonReader;
import java.io.IOException;
import java.io.StringReader;
import org.junit.Assert;
import org.junit.Test;
/**
* @author pengys5
*/
public class TraceSegmentRefTestCase {
@Test
public void deserialize() throws IOException {
TraceSegmentRef traceSegmentRef = new TraceSegmentRef();
JsonReader reader = new JsonReader(new StringReader("{\"ts\" :\"ts\",\"si\":0,\"ac\":\"ac\",\"ph\":\"ph\", \"skip\":\"skip\"}"));
traceSegmentRef.deserialize(reader);
Assert.assertEquals("ts", traceSegmentRef.getTraceSegmentId());
Assert.assertEquals("ac", traceSegmentRef.getApplicationCode());
Assert.assertEquals("ph", traceSegmentRef.getPeerHost());
Assert.assertEquals(0, traceSegmentRef.getSpanId());
}
}
package com.a.eye.skywalking.collector.worker.segment.entity.tag;
import com.a.eye.skywalking.collector.worker.segment.entity.Span;
import java.lang.reflect.Field;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
/**
* @author pengys5
*/
public class BooleanTagTestCase {
@Test
public void test() throws NoSuchFieldException, IllegalAccessException {
BooleanTag booleanTag = new BooleanTag("test", false);
Map<String, Boolean> tagsWithInt = new LinkedHashMap<>();
Span span = new Span();
Field testAField = span.getClass().getDeclaredField("tagsWithBool");
testAField.setAccessible(true);
testAField.set(span, tagsWithInt);
Assert.assertEquals(false, booleanTag.get(span));
tagsWithInt.put("test", true);
Assert.assertEquals(true, booleanTag.get(span));
}
}
package com.a.eye.skywalking.collector.worker.segment.entity.tag;
import com.a.eye.skywalking.collector.worker.segment.entity.Span;
import java.lang.reflect.Field;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
/**
* @author pengys5
*/
public class IntTagTestCase {
@Test
public void test() throws NoSuchFieldException, IllegalAccessException {
IntTag intTag = new IntTag("test");
Map<String, Integer> tagsWithInt = new LinkedHashMap<>();
Span span = new Span();
Field testAField = span.getClass().getDeclaredField("tagsWithInt");
testAField.setAccessible(true);
testAField.set(span, tagsWithInt);
Assert.assertEquals(null, intTag.get(span));
tagsWithInt.put("test", 10);
Assert.assertEquals(10, intTag.get(span).intValue());
}
}
package com.a.eye.skywalking.collector.worker.segment.entity.tag;
import com.a.eye.skywalking.collector.worker.segment.entity.Span;
import com.a.eye.skywalking.collector.worker.storage.SegmentData;
import com.a.eye.skywalking.collector.worker.storage.WindowData;
import java.lang.reflect.Field;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
/**
* @author pengys5
*/
public class ShortTagTestCase {
@Test
public void test() throws NoSuchFieldException, IllegalAccessException {
ShortTag shortTag = new ShortTag("short");
Map<String, Integer> tagsWithInt = new LinkedHashMap<>();
Span span = new Span();
Field testAField = span.getClass().getDeclaredField("tagsWithInt");
testAField.setAccessible(true);
testAField.set(span, tagsWithInt);
Short tag = shortTag.get(span);
Assert.assertEquals(null, tag);
tagsWithInt.put("short", 10);
tag = shortTag.get(span);
Assert.assertEquals(10, tag.intValue());
}
}
package com.a.eye.skywalking.collector.worker.segment.entity.tag;
import com.a.eye.skywalking.collector.worker.segment.entity.Span;
import java.lang.reflect.Field;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
/**
* @author pengys5
*/
public class TagsTestCase {
@Test
public void test() throws NoSuchFieldException, IllegalAccessException {
Span span = new Span();
Map<String, String> tagsWithStr = new LinkedHashMap<>();
tagsWithStr.put("span.layer", "db");
Field testAField = span.getClass().getDeclaredField("tagsWithStr");
testAField.setAccessible(true);
testAField.set(span, tagsWithStr);
Assert.assertEquals("db", Tags.SPAN_LAYER.get(span));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册