Add skywalking-sniffer-mock module. For testing sdk-plugin and collector(not merged yet) modules.
This commit is contained in:
parent
75d8aba0f4
commit
a4d2f23791
|
|
@ -17,6 +17,7 @@
|
|||
<module>skywalking-api</module>
|
||||
<module>skywalking-sdk-plugin</module>
|
||||
<module>skywalking-toolkit-activation</module>
|
||||
<module>skywalking-sniffer-mock</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
|
|
|||
|
|
@ -51,26 +51,6 @@
|
|||
<artifactId>disruptor</artifactId>
|
||||
<version>3.3.6</version>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies section -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>1.6.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>1.6.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>
|
||||
<artifactId>skywalking-sniffer</artifactId>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<version>3.0-2017</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>skywalking-sniffer-mock</artifactId>
|
||||
<description>This is a sniffer mock module, test for test-dependency, only.</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- direct dependency junit, based on this is a mock module. -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package com.a.eye.skywalking.sniffer.mock.context;
|
||||
|
||||
import com.a.eye.skywalking.api.context.TracerContext;
|
||||
import com.a.eye.skywalking.api.context.TracerContextListener;
|
||||
import com.a.eye.skywalking.trace.TraceSegment;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.junit.Assert;
|
||||
|
||||
/**
|
||||
* This is mock tracer context listener, which should be added by calling {@link TracerContext.ListenerManager#add(TracerContextListener)}.
|
||||
* This mock listener will hold all finished trace, which all are generated by {@link TracerContext#finish()}.
|
||||
*
|
||||
* Created by wusheng on 2017/2/20.
|
||||
*/
|
||||
public class MockTracerContextListener implements TracerContextListener {
|
||||
private List<TraceSegment> finishedTraceSegments = Collections.synchronizedList(new ArrayList<TraceSegment>());
|
||||
|
||||
@Override public void afterFinished(TraceSegment traceSegment) {
|
||||
finishedTraceSegments.add(traceSegment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert all finished {@link #finishedTraceSegments} match the given size.
|
||||
*
|
||||
* @param size the give size.
|
||||
*/
|
||||
public void assertSize(int size){
|
||||
Assert.assertEquals(size, finishedTraceSegments.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the {@link TraceSegment} at the given index of {@link #finishedTraceSegments},
|
||||
* and run the given {@link SegmentAssert#call(TraceSegment)} to assert.
|
||||
*
|
||||
* @param index the given index.
|
||||
* @param segmentAssert the given assert.
|
||||
*/
|
||||
public void assertTraceSegment(int index, SegmentAssert segmentAssert){
|
||||
assertSize(index + 1);
|
||||
segmentAssert.call(finishedTraceSegments.get(index));
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all hold data.
|
||||
*/
|
||||
public void clear(){
|
||||
finishedTraceSegments.clear();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.a.eye.skywalking.sniffer.mock.context;
|
||||
|
||||
import com.a.eye.skywalking.trace.TraceSegment;
|
||||
|
||||
/**
|
||||
* The <code>SegmentAssert</code> interface should be implemented by any
|
||||
* class whose instances are intended to assert a trace segment data.
|
||||
*
|
||||
* Created by wusheng on 2017/2/20.
|
||||
*/
|
||||
public interface SegmentAssert{
|
||||
void call(TraceSegment finishedSegment);
|
||||
}
|
||||
Loading…
Reference in New Issue