1. solve compile issue. 2. remove test-api module
This commit is contained in:
parent
2f057f8bef
commit
b0839d2440
|
|
@ -3,7 +3,6 @@ package com.a.eye.skywalking.network;
|
|||
import com.a.eye.skywalking.network.grpc.server.AsyncTraceSearchServer;
|
||||
import com.a.eye.skywalking.network.grpc.server.SpanStorageServer;
|
||||
import com.a.eye.skywalking.network.grpc.server.TraceSearchServer;
|
||||
import com.a.eye.skywalking.network.listener.server.AsyncTraceSearchServerListener;
|
||||
import com.a.eye.skywalking.network.listener.server.SpanStorageServerListener;
|
||||
import com.a.eye.skywalking.network.listener.server.TraceSearchListener;
|
||||
import io.grpc.netty.NettyServerBuilder;
|
||||
|
|
@ -61,8 +60,8 @@ public class Server {
|
|||
return this;
|
||||
}
|
||||
|
||||
public TransferServiceBuilder addAsyncTraceSearchService(AsyncTraceSearchServerListener asyncTraceSearchServerListener){
|
||||
serverBuilder.addService(new AsyncTraceSearchServer(asyncTraceSearchServerListener));
|
||||
public TransferServiceBuilder addAsyncTraceSearchService(TraceSearchListener traceSearchListener){
|
||||
serverBuilder.addService(new AsyncTraceSearchServer(traceSearchListener));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
<module>skywalking-agent</module>
|
||||
<module>skywalking-api</module>
|
||||
<module>skywalking-sdk-plugin</module>
|
||||
<module>skywalking-test-api</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-sniffer</artifactId>
|
||||
<version>2.0-2016</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>skywalking-test-api</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>skywalking-test-api</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-network</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
package com.a.eye.skywalking.testframework.api;
|
||||
|
||||
import com.a.eye.skywalking.testframework.api.config.Config;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ContextPoolOperator {
|
||||
public static List<Object> acquireBufferData() {
|
||||
List<Object> resultSpan = new ArrayList<Object>();
|
||||
Object[] bufferGroupObjectArray = acquireBufferGroupObjectArrayByClassLoader();
|
||||
|
||||
for (Object bufferGroup : bufferGroupObjectArray) {
|
||||
Object[] spanList = acquireBufferData(bufferGroup);
|
||||
for (Object span : spanList) {
|
||||
if (span != null) {
|
||||
resultSpan.add(span);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resultSpan;
|
||||
}
|
||||
|
||||
public static void clearSpanData() {
|
||||
Object[] bufferGroupObjectArray = acquireBufferGroupObjectArrayByClassLoader();
|
||||
|
||||
for (Object bufferGroup : bufferGroupObjectArray) {
|
||||
Object[] spanList = acquireBufferData(bufferGroup);
|
||||
for (int i = 0; i < spanList.length; i++) {
|
||||
spanList[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Object[] acquireBufferData(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 (Object[]) 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 data 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
package com.a.eye.skywalking.testframework.api;
|
||||
|
||||
import com.a.eye.skywalking.network.grpc.RequestSpan;
|
||||
import com.a.eye.skywalking.network.grpc.TraceId;
|
||||
import com.a.eye.skywalking.testframework.api.exception.SpanDataNotEqualsException;
|
||||
import com.a.eye.skywalking.testframework.api.exception.SpanDataFormatException;
|
||||
import com.a.eye.skywalking.testframework.api.exception.TraceIdNotSameException;
|
||||
import com.a.eye.skywalking.testframework.api.exception.TraceNodeSizeNotEqualException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RequestSpanAssert {
|
||||
|
||||
public static void assertEquals(String[][] expectedRequestSpan) {
|
||||
assertEquals(expectedRequestSpan, false);
|
||||
}
|
||||
|
||||
public static void assertEquals(String[][] expectedRequestSpan, boolean skipValidateTraceId) {
|
||||
List<RequestSpan> requestSpan = acquiredRequestSpanFromBuffer();
|
||||
|
||||
if (!skipValidateTraceId) {
|
||||
validateTraceId(requestSpan);
|
||||
}
|
||||
|
||||
List<String> assertSpanData = convertSpanDataToCompareStr(requestSpan);
|
||||
|
||||
List<String> expectedSpanData = convertSpanDataToCompareStr(expectedRequestSpan);
|
||||
|
||||
validateTraceSpanSize(expectedSpanData.size(), assertSpanData.size());
|
||||
|
||||
validateSpanData(expectedSpanData, assertSpanData);
|
||||
|
||||
}
|
||||
|
||||
private static List<RequestSpan> acquiredRequestSpanFromBuffer() {
|
||||
List<Object> spans = ContextPoolOperator.acquireBufferData();
|
||||
|
||||
List<RequestSpan> result = new ArrayList<RequestSpan>();
|
||||
for (Object span : spans) {
|
||||
if (span instanceof RequestSpan) {
|
||||
result.add((RequestSpan) span);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void clearTraceData() {
|
||||
ContextPoolOperator.clearSpanData();
|
||||
}
|
||||
|
||||
private static List<String> convertSpanDataToCompareStr(List<RequestSpan> assertSpanData) {
|
||||
List<String> resultSpanData = new ArrayList<String>();
|
||||
for (RequestSpan span : assertSpanData) {
|
||||
StringBuffer tmpSpanDataStr = new StringBuffer(jointTraceLevelId(span.getParentLevel(), span.getLevelId() + " "));
|
||||
tmpSpanDataStr.append(span.getViewPointId().trim() + " ");
|
||||
tmpSpanDataStr.append(span.getBusinessKey() == null ? " " : span.getBusinessKey() + " ");
|
||||
|
||||
resultSpanData.add(tmpSpanDataStr.toString().trim());
|
||||
}
|
||||
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 List<String> convertSpanDataToCompareStr(String[][] assertTraceTree) {
|
||||
List<String> resultSpanData = new ArrayList<String>();
|
||||
for (String[] spanDataArray : assertTraceTree) {
|
||||
if (spanDataArray.length != 3) {
|
||||
throw new SpanDataFormatException("assert trace tree is illegal, " + "Format :\ttraceLevelId\t|\tviewPoint\t|\tbusinesskey");
|
||||
}
|
||||
|
||||
StringBuffer tmpSpanDataStr = new StringBuffer(spanDataArray[0] + " ");
|
||||
tmpSpanDataStr.append(spanDataArray[1] == null ? " " : spanDataArray[1].trim() + " ").append(spanDataArray[2] == null ? " " : spanDataArray[2].trim() + " ");
|
||||
|
||||
resultSpanData.add(tmpSpanDataStr.toString().trim());
|
||||
}
|
||||
|
||||
return resultSpanData;
|
||||
}
|
||||
|
||||
|
||||
private static void validateTraceSpanSize(int expectedSpanSize, int actualSpanSize) {
|
||||
if (actualSpanSize != expectedSpanSize) {
|
||||
throw new TraceNodeSizeNotEqualException("expected span size : " + expectedSpanSize +
|
||||
"\n actual span size : " + actualSpanSize);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateSpanData(List<String> expectedSpanData, List<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 SpanDataNotEqualsException("actual trace tree is not contain those span as follow:\n" + stringBuffer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void validateTraceId(List<RequestSpan> traceSpanList) {
|
||||
String traceId = null;
|
||||
for (RequestSpan span : traceSpanList) {
|
||||
if (traceId == null) {
|
||||
traceId = toLiteralLTraceId(span.getTraceId());
|
||||
}
|
||||
|
||||
if (!traceId.equals(toLiteralLTraceId(span.getTraceId()))) {
|
||||
throw new TraceIdNotSameException("trace id is not all the same.trace id :" +
|
||||
traceId + ",Error trace id :" + span.getTraceId());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static String toLiteralLTraceId(TraceId traceId){
|
||||
StringBuilder tid = new StringBuilder();
|
||||
for (Long segment : traceId.getSegmentsList()) {
|
||||
tid.append(segment).append(".");
|
||||
}
|
||||
return tid.substring(0, tid.length() - 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
package com.a.eye.skywalking.testframework.api.config;
|
||||
|
||||
public class Config {
|
||||
|
||||
public static String BUFFER_POOL_CLASS_NAME = "com.a.eye.skywalking.data.BufferPool";
|
||||
|
||||
public static String BUFFER_GROUP_FIELD_NAME = "bufferGroups";
|
||||
|
||||
public static String BUFFER_GROUP_CLASS_NAME = "com.a.eye.skywalking.data.BufferGroup";
|
||||
|
||||
public static String SPAN_ARRAY_FIELD_NAME = "dataBuffer";
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
package com.a.eye.skywalking.testframework.api.exception;
|
||||
|
||||
public class SpanDataFormatException extends RuntimeException {
|
||||
public SpanDataFormatException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
package com.a.eye.skywalking.testframework.api.exception;
|
||||
|
||||
public class SpanDataNotEqualsException extends RuntimeException {
|
||||
public SpanDataNotEqualsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
package com.a.eye.skywalking.testframework.api.exception;
|
||||
|
||||
public class TraceIdNotSameException extends RuntimeException {
|
||||
public TraceIdNotSameException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
package com.a.eye.skywalking.testframework.api.exception;
|
||||
|
||||
public class TraceNodeSizeNotEqualException extends RuntimeException {
|
||||
public TraceNodeSizeNotEqualException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
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