segment entity testcase
This commit is contained in:
parent
d772b95ce5
commit
15684ea934
|
|
@ -0,0 +1,29 @@
|
|||
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"));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
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());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
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());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
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());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
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));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue