Give a sample code of the first Mock trace.

This commit is contained in:
wusheng 2017-02-20 22:52:26 +08:00
parent a4d2f23791
commit 69877b80fd
3 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,10 @@
package com.a.eye.skywalking.sniffer.mock.trace;
import com.a.eye.skywalking.trace.TraceSegment;
/**
* Created by wusheng on 2017/2/20.
*/
public interface TraceSegmentBuilder {
TraceSegment build();
}

View File

@ -0,0 +1,35 @@
package com.a.eye.skywalking.sniffer.mock.trace;
import com.a.eye.skywalking.sniffer.mock.trace.builders.SingleTomcat200TraceBuilder;
import com.a.eye.skywalking.trace.TraceSegment;
import java.util.HashMap;
import java.util.Map;
/**
* The <code>TraceSegmentBuilderFactory</code> contains all {@link TraceSegmentBuilder} implementations.
* All the implementations can build a true {@link TraceSegment} object, and contain all necessary spans, with all tags/events, all refs.
*
* Created by wusheng on 2017/2/20.
*/
public enum TraceSegmentBuilderFactory {
INSTANCE;
private Map<String, TraceSegmentBuilder> allBuilders;
TraceSegmentBuilderFactory(){
allBuilders = new HashMap<String, TraceSegmentBuilder>();
initialize();
}
public TraceSegment singleTomcat200Trace(){
return allBuilders.get(SingleTomcat200TraceBuilder.INSTANCE).build();
}
private void initialize(){
initBuilder(SingleTomcat200TraceBuilder.INSTANCE);
}
private void initBuilder(TraceSegmentBuilder builder){
allBuilders.put(builder.toString(), builder);
}
}

View File

@ -0,0 +1,27 @@
package com.a.eye.skywalking.sniffer.mock.trace.builders;
import com.a.eye.skywalking.api.context.ContextManager;
import com.a.eye.skywalking.sniffer.mock.trace.TraceSegmentBuilder;
import com.a.eye.skywalking.trace.Span;
import com.a.eye.skywalking.trace.TraceSegment;
import com.a.eye.skywalking.trace.tag.Tags;
/**
* A Trace contains only one span, which represent a tomcat server side span.
*
* Created by wusheng on 2017/2/20.
*/
public enum SingleTomcat200TraceBuilder implements TraceSegmentBuilder {
INSTANCE;
@Override public TraceSegment build() {
Span webSpan = ContextManager.INSTANCE.createSpan("/web/serviceA");
{
Tags.COMPONENT.set(webSpan, "tomcat");
Tags.URL.set(webSpan, "http://10.21.9.35/web/serviceA");
Tags.SPAN_KIND.set(webSpan, Tags.SPAN_KIND_SERVER);
Tags.STATUS_CODE.set(webSpan, 200);
}
return null;
}
}