新增清理ContextPool的方法,方便测试
This commit is contained in:
parent
9464d94689
commit
1a6ec531ce
|
|
@ -45,11 +45,8 @@ redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 1
|
|||
```
|
||||
|
||||
## 启动测试 Run test case
|
||||
启动测试用例时,VM参数中需要添加以下的vm参数。**注意**:由于buffer在JVM是独一份,为了避免测试结果不一致,测试类不能一起测试,
|
||||
只能单独运行测试方法,测试中的环境参数可能跟随机器变化,所以可能需要进行修改。
|
||||
When you start the test case, VM parameters need to add the following parameters vm. **Notice**
|
||||
Because the buffer is the only one in JVM , in order to avoid inconsistent results, test class can not be tested together,
|
||||
Can only run a single test method, the test environment parameters may change following the machine, it may need to be modified.
|
||||
启动测试用例时,VM参数中需要添加以下的vm参数。**注意**:测试中的环境参数可能跟随机器变化,所以可能需要进行修改。
|
||||
When you start the test case, VM parameters need to add the following parameters vm. **Notice** :The test environment parameters may change following the machine, it may need to be modified.
|
||||
```
|
||||
-javaagent:${SKYWALKING_AGENT_TEST_PROJECT_PATH}/lib/skywalking-agent-1.0-Final.jar
|
||||
```
|
||||
|
|
@ -1,17 +1,24 @@
|
|||
package com.ai.cloud.skywalking.agent.test;
|
||||
|
||||
import com.ai.skywalking.testframework.api.TraceTreeAssert;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
public class RedisClusterPluginTest {
|
||||
|
||||
@After
|
||||
public void clearData(){
|
||||
TraceTreeAssert.clearTraceData();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSetData() {
|
||||
RedisClusterOperator.setData("key1", "value1");
|
||||
TraceTreeAssert.assertEquals(new String[][]{
|
||||
// 根据实际情况进行修改
|
||||
{"0.0", "127.0.0.1:7001 set", "key=key1"},
|
||||
{"0", "127.0.0.1:7002;127.0.0.1:7001;127.0.0.1:7000;127.0.0.1:7005;127.0.0.1:7004;127.0.0.1:7003; set", "key=key1"},
|
||||
{"0", "127.0.0.1:7001;127.0.0.1:7000; set", "key=key1"},
|
||||
});
|
||||
|
||||
}
|
||||
|
|
@ -22,7 +29,7 @@ public class RedisClusterPluginTest {
|
|||
TraceTreeAssert.assertEquals(new String[][]{
|
||||
// 根据实际情况进行修改
|
||||
{"0.0", "127.0.0.1:7001 get", "key=key1"},
|
||||
{"0", "127.0.0.1:7002;127.0.0.1:7001;127.0.0.1:7000;127.0.0.1:7005;127.0.0.1:7004;127.0.0.1:7003; get", "key=key1"},
|
||||
{"0", "127.0.0.1:7001;127.0.0.1:7000; get", "key=key1"},
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,22 @@
|
|||
package com.ai.cloud.skywalking.agent.test;
|
||||
|
||||
import com.ai.skywalking.testframework.api.TraceTreeAssert;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
public class RedisPluginTest {
|
||||
|
||||
@After
|
||||
public void clearData(){
|
||||
TraceTreeAssert.clearTraceData();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetData() {
|
||||
RedisOperator.setData("key1", "value1");
|
||||
TraceTreeAssert.assertEquals(new String[][]{
|
||||
{"0", "127.0.0.1:6379 set", "key=key1"},
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ import java.lang.reflect.Field;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TraceTreeDataAcquirer {
|
||||
public static List<Span> acquireCurrentTraceSpanData() {
|
||||
public class ContextPoolOperator {
|
||||
public static List<Span> acquireSpanData() {
|
||||
List<Span> resultSpan = new ArrayList<Span>();
|
||||
Object[] bufferGroupObjectArray = acquireBufferGroupObjectArrayByClassLoader();
|
||||
|
||||
|
|
@ -24,6 +24,17 @@ public class TraceTreeDataAcquirer {
|
|||
return resultSpan;
|
||||
}
|
||||
|
||||
public static void clearSpanData() {
|
||||
Object[] bufferGroupObjectArray = acquireBufferGroupObjectArrayByClassLoader();
|
||||
|
||||
for (Object bufferGroup : bufferGroupObjectArray) {
|
||||
Span[] spanList = acquireSpanData(bufferGroup);
|
||||
for (int i = 0; i < spanList.length; i++) {
|
||||
spanList[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Span[] acquireSpanData(Object bufferGroup) {
|
||||
try {
|
||||
Class bufferGroupClass = Thread.currentThread().getContextClassLoader()
|
||||
|
|
@ -32,7 +43,7 @@ public class TraceTreeDataAcquirer {
|
|||
spanArrayField.setAccessible(true);
|
||||
return (Span[]) spanArrayField.get(bufferGroup);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to acquire span array",e);
|
||||
throw new RuntimeException("Failed to acquire span array", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -43,7 +54,7 @@ public class TraceTreeDataAcquirer {
|
|||
Field field = fetchBufferPoolObject(bufferPoolClass);
|
||||
return (Object[]) field.get(bufferPoolClass);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to acquire buffer group object array",e);
|
||||
throw new RuntimeException("Failed to acquire buffer group object array", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ import java.util.List;
|
|||
public class TraceTreeAssert {
|
||||
|
||||
public static void assertEquals(String[][] expectedTraceTree) {
|
||||
List<Span> spanDataInBuffer = TraceTreeDataAcquirer.acquireCurrentTraceSpanData();
|
||||
List<Span> spanDataInBuffer = ContextPoolOperator.acquireSpanData();
|
||||
|
||||
validateTraceId(spanDataInBuffer);
|
||||
|
||||
|
|
@ -25,6 +25,10 @@ public class TraceTreeAssert {
|
|||
validateSpanData(expectedSpanData, assertSpanData);
|
||||
}
|
||||
|
||||
public static void clearTraceData() {
|
||||
ContextPoolOperator.clearSpanData();
|
||||
}
|
||||
|
||||
private static List<String> convertSpanDataToCompareStr(List<Span> assertSpanData) {
|
||||
List<String> resultSpanData = new ArrayList<String>();
|
||||
for (Span span : assertSpanData) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue