parent
7b741cc280
commit
060afcb56b
|
|
@ -46,9 +46,9 @@
|
|||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<groupId>com.ai.cloud</groupId>
|
||||
<artifactId>skywalking-test-api</artifactId>
|
||||
<version>1.0-Final</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import static com.ai.cloud.skywalking.conf.Config.Consumer.*;
|
|||
public class BufferGroup {
|
||||
private static Logger logger = LogManager.getLogger(BufferGroup.class);
|
||||
private String groupName;
|
||||
//注意: 修改这个变量名,需要修改test-api工程的Config类中的SPAN_ARRAY_FIELD_NAME变量
|
||||
private Span[] dataBuffer = new Span[BUFFER_MAX_SIZE];
|
||||
AtomicRangeInteger index = new AtomicRangeInteger(0, BUFFER_MAX_SIZE);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ public class ContextBuffer {
|
|||
|
||||
|
||||
static class BufferPool {
|
||||
// 注意: 这个变量名如果改变需要改变test-api工程中的Config变量
|
||||
private static BufferGroup[] bufferGroups = new BufferGroup[POOL_SIZE];
|
||||
static {
|
||||
for (int i = 0; i < POOL_SIZE; i++) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
package test.ai.cloud.assertspandata;
|
||||
|
||||
import com.ai.cloud.skywalking.buffer.ContextBuffer;
|
||||
import com.ai.cloud.skywalking.conf.Config;
|
||||
import com.ai.cloud.skywalking.protocol.Span;
|
||||
import org.junit.Test;
|
||||
import test.com.ai.skywalking.test.api.TraceTreeAssert;
|
||||
|
||||
/**
|
||||
* Created by xin on 16-6-6.
|
||||
*/
|
||||
public class TraceTreeAssertTest {
|
||||
|
||||
@Test
|
||||
public void traceTreeAssertTest() {
|
||||
Config.Consumer.MAX_CONSUMER = 0;
|
||||
Span testSpan = new Span("1.0b.1465224457414.7e57f54.22905.61.2691", "", 0, "test-application", "5");
|
||||
testSpan.setViewPointId("http://hire.asiainfo.com/Aisse-Mobile-Web/aisseWorkPage/submitReimbursement");
|
||||
ContextBuffer.save(testSpan);
|
||||
TraceTreeAssert.assertEquals(new String[][]{
|
||||
{null, "0", "http://hire.asiainfo.com/Aisse-Mobile-Web/aisseWorkPage/submitReimbursement", null}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ sender.is_off=false
|
|||
|
||||
|
||||
#最大消费线程数
|
||||
consumer.max_consumer=2
|
||||
consumer.max_consumer=0
|
||||
#消费者最大等待时间
|
||||
consumer.max_wait_time=5
|
||||
#发送失败等待时间
|
||||
|
|
|
|||
|
|
@ -1,38 +1,43 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.ai.cloud</groupId>
|
||||
<artifactId>skywalking-agent-test</artifactId>
|
||||
<version>1.0-Final</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.ai.cloud</groupId>
|
||||
<artifactId>skywalking-agent-test</artifactId>
|
||||
<version>1.0-Final</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>redis-test</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>redis-test</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>redis-test</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<name>redis-test</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.4.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>2.8.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.4.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ai.cloud</groupId>
|
||||
<artifactId>skywalking-test-api</artifactId>
|
||||
<version>1.0-Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>2.8.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
package com.ai.cloud.skywalking.agent.test;
|
||||
|
||||
import test.com.ai.skywalking.reflect.api.TraceTreeAssert;
|
||||
|
||||
public class RedisPluginTest {
|
||||
public static void main(String[] args) {
|
||||
RedisOperator.setData("key1", "value1");
|
||||
TraceTreeAssert.assertEquals(new String[][]{
|
||||
{null, "0", "127.0.0.1:6379 set", "key=key1"},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ buriedpoint.businesskey_max_length=300
|
|||
sender.retry_get_sender_wait_interval=2000
|
||||
buffer.pool_size=5
|
||||
senderchecker.check_polling_time=200
|
||||
sender.is_off=true
|
||||
sender.is_off=false
|
||||
sender.max_send_length=20000
|
||||
consumer.max_consumer=2
|
||||
consumer.max_consumer=0
|
||||
consumer.max_wait_time=5
|
||||
sender.max_copy_num=2
|
||||
skywalking.application_code=redis-plugin-test
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.ai.cloud</groupId>
|
||||
<artifactId>skywalking-api</artifactId>
|
||||
<artifactId>skywalking-protocol</artifactId>
|
||||
<version>${parent.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
package test.com.ai.skywalking.api;
|
||||
|
||||
import com.ai.cloud.skywalking.protocol.Span;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TraceTreeAssert {
|
||||
|
||||
public static void assertEquals(String[][] assertTraceTree) {
|
||||
List<Span> bufferTraceSpanList = TraceTreeDataAcquirer.acquireCurrentTraceSpanData();
|
||||
validateTraceId(bufferTraceSpanList);
|
||||
validateTraceSpanSize(bufferTraceSpanList.size(), assertTraceTree.length);
|
||||
validateSpanData(bufferTraceSpanList, assertTraceTree);
|
||||
}
|
||||
|
||||
private static void validateTraceSpanSize(int actualSpanSize, int expectedSpanSize) {
|
||||
if (actualSpanSize != expectedSpanSize) {
|
||||
throw new RuntimeException("expected span size : " + expectedSpanSize + "\n actual span size : " + actualSpanSize);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateSpanData(List<Span> traceSpanList, String[][] traceTree) {
|
||||
|
||||
}
|
||||
|
||||
private static void validateTraceId(List<Span> traceSpanList) {
|
||||
String traceId = null;
|
||||
for (Span span : traceSpanList) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
package test.com.ai.skywalking.api;
|
||||
|
||||
import com.ai.cloud.skywalking.protocol.Span;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TraceTreeDataAcquirer {
|
||||
public static List<Span> acquireCurrentTraceSpanData() {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
package test.com.ai.skywalking.test.api;
|
||||
|
||||
import com.ai.cloud.skywalking.protocol.Span;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TraceTreeAssert {
|
||||
|
||||
public static void assertEquals(String[][] expectedTraceTree) {
|
||||
List<Span> spanDataInBuffer = TraceTreeDataAcquirer.acquireCurrentTraceSpanData();
|
||||
|
||||
validateTraceId(spanDataInBuffer);
|
||||
|
||||
Set<String> assertSpanData = distinctAndConvertSpanData(spanDataInBuffer);
|
||||
Set<String> expectedSpanData = distinctAndConvertSpanData(expectedTraceTree);
|
||||
|
||||
validateTraceSpanSize(expectedSpanData.size(), assertSpanData.size());
|
||||
validateSpanData(expectedSpanData, assertSpanData);
|
||||
}
|
||||
|
||||
private static Set<String> distinctAndConvertSpanData(List<Span> assertSpanData) {
|
||||
Set<String> resultSpanData = new HashSet<>();
|
||||
for (Span span : assertSpanData) {
|
||||
StringBuffer tmpSpanDataStr = new StringBuffer(jointTraceLevelId(span.getParentLevel(), span.getLevelId() + " "));
|
||||
tmpSpanDataStr.append(span.getViewPointId().trim() + " ")
|
||||
.append(span.getBusinessKey().trim() + " ");
|
||||
|
||||
resultSpanData.add(tmpSpanDataStr.toString());
|
||||
}
|
||||
return resultSpanData;
|
||||
}
|
||||
|
||||
private static String jointTraceLevelId(String parentLevelId, String levelId) {
|
||||
String traceLevelId = "";
|
||||
if (parentLevelId != null && parentLevelId.length() > 0) {
|
||||
traceLevelId = parentLevelId + ".";
|
||||
}
|
||||
traceLevelId += levelId;
|
||||
return traceLevelId;
|
||||
}
|
||||
|
||||
private static Set<String> distinctAndConvertSpanData(String[][] assertTraceTree) {
|
||||
Set<String> resultSpanData = new HashSet<String>();
|
||||
for (String[] spanDataArray : assertTraceTree) {
|
||||
if (spanDataArray.length != 4) {
|
||||
throw new IllegalArgumentException("assert trace tree is illegal, " +
|
||||
"Format :\tParentLevelId\t|\tlevelId\t|\tviewPoint\t|\tbusinesskey");
|
||||
}
|
||||
|
||||
StringBuffer tmpSpanDataStr = new StringBuffer(jointTraceLevelId(spanDataArray[0], spanDataArray[1]) + " ");
|
||||
tmpSpanDataStr.append(spanDataArray[2] == null ? " " : spanDataArray[2].trim() + " ")
|
||||
.append(spanDataArray[3] == null ? " " : spanDataArray[3].trim() + " ");
|
||||
|
||||
resultSpanData.add(tmpSpanDataStr.toString());
|
||||
}
|
||||
|
||||
return resultSpanData;
|
||||
}
|
||||
|
||||
|
||||
private static void validateTraceSpanSize(int actualSpanSize, int expectedSpanSize) {
|
||||
if (actualSpanSize != expectedSpanSize) {
|
||||
throw new RuntimeException("expected span size : " + expectedSpanSize +
|
||||
"\n actual span size : " + actualSpanSize);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateSpanData(Set<String> expectedSpanData, Set<String> assertTraceTree) {
|
||||
for (String assertSpanDataStr : assertTraceTree) {
|
||||
if (expectedSpanData.contains(assertSpanDataStr)) {
|
||||
expectedSpanData.remove(assertSpanDataStr);
|
||||
}
|
||||
}
|
||||
|
||||
if (expectedSpanData.size() != 0) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
for (String expectedSpan : expectedSpanData) {
|
||||
stringBuffer.append(expectedSpan + "\n");
|
||||
}
|
||||
|
||||
throw new RuntimeException("actual trace tree is not contain those span as follow:\n" + stringBuffer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void validateTraceId(List<Span> traceSpanList) {
|
||||
String traceId = null;
|
||||
for (Span span : traceSpanList) {
|
||||
if (traceId == null) {
|
||||
traceId = span.getTraceId();
|
||||
}
|
||||
|
||||
if (!traceId.equals(span.getTraceId())) {
|
||||
throw new RuntimeException("trace id is not all the same.trace id :" +
|
||||
traceId + ",Error trace id :" + span.getTraceId());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package test.com.ai.skywalking.test.api;
|
||||
|
||||
import com.ai.cloud.skywalking.protocol.Span;
|
||||
import test.com.ai.skywalking.test.api.config.Config;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TraceTreeDataAcquirer {
|
||||
public static List<Span> acquireCurrentTraceSpanData() {
|
||||
List<Span> resultSpan = new ArrayList<Span>();
|
||||
Object[] bufferGroupObjectArray = acquireBufferGroupObjectArrayByClassLoader();
|
||||
|
||||
for (Object bufferGroup : bufferGroupObjectArray) {
|
||||
Span[] spanList = acquireSpanData(bufferGroup);
|
||||
for (Span span : spanList) {
|
||||
if (span != null) {
|
||||
resultSpan.add(span);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resultSpan;
|
||||
}
|
||||
|
||||
private static Span[] acquireSpanData(Object bufferGroup) {
|
||||
try {
|
||||
Class bufferGroupClass = Thread.currentThread().getContextClassLoader()
|
||||
.loadClass(Config.BUFFER_GROUP_CLASS_NAME);
|
||||
Field spanArrayField = bufferGroupClass.getDeclaredField(Config.SPAN_ARRAY_FIELD_NAME);
|
||||
spanArrayField.setAccessible(true);
|
||||
return (Span[]) spanArrayField.get(bufferGroup);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to acquire span array",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static Object[] acquireBufferGroupObjectArrayByClassLoader() {
|
||||
try {
|
||||
Class bufferPoolClass = fetchBufferPoolClass();
|
||||
Field field = fetchBufferPoolObject(bufferPoolClass);
|
||||
return (Object[]) field.get(bufferPoolClass);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to acquire buffer group object array",e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Field fetchBufferPoolObject(Class bufferPoolClass) throws NoSuchFieldException {
|
||||
Field field = bufferPoolClass.getDeclaredField(Config.BUFFER_GROUP_FIELD_NAME);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
}
|
||||
|
||||
private static Class fetchBufferPoolClass() throws ClassNotFoundException {
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
return classLoader.loadClass(Config.BUFFER_POOL_CLASS_NAME);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package test.com.ai.skywalking.test.api.config;
|
||||
|
||||
public class Config {
|
||||
|
||||
public static String BUFFER_POOL_CLASS_NAME = "com.ai.cloud.skywalking.buffer.ContextBuffer$BufferPool";
|
||||
|
||||
public static String BUFFER_GROUP_FIELD_NAME = "bufferGroups";
|
||||
|
||||
public static String BUFFER_GROUP_CLASS_NAME = "com.ai.cloud.skywalking.buffer.BufferGroup";
|
||||
|
||||
public static String SPAN_ARRAY_FIELD_NAME = "dataBuffer";
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package test.com.ai.skywalking.reflect;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* Created by xin on 16-6-6.
|
||||
*/
|
||||
public class SubClassReflect {
|
||||
|
||||
@Test
|
||||
public void fetchSubClassField() throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
|
||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
Class testSubClass = loader.loadClass("test.com.ai.skywalking.reflect.TestClass$TestSubClass");
|
||||
Field field = testSubClass.getDeclaredField("testStringArray");
|
||||
assertNotNull(field);
|
||||
field.setAccessible(true);
|
||||
Object[] objects = (Object[]) field.get(testSubClass);
|
||||
assertEquals(5, objects.length);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package test.com.ai.skywalking.reflect;
|
||||
|
||||
public class TestClass {
|
||||
|
||||
private static TestSubClass testSubClass = new TestSubClass();
|
||||
|
||||
static class TestSubClass {
|
||||
private static String[] testStringArray = new String[5];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue