提交 6deb4bb8 编写于 作者: wu-sheng's avatar wu-sheng

Alter the TraceSegement build mechanism in sniffer-mock module.

上级 6e2ccfab
package com.a.eye.skywalking.sniffer.mock.trace.builders.span;
/**
* Created by wusheng on 2017/2/28.
*/
public abstract class SpanGeneration {
private SpanGeneration next;
public SpanGeneration build(SpanGeneration next){
this.next = next;
return next;
}
public SpanGeneration build(){
return this;
}
protected abstract void before();
protected abstract void after();
public void generate(){
this.before();
if(next != null){
next.generate();
}
this.after();
}
}
......@@ -9,45 +9,57 @@ import com.a.eye.skywalking.trace.tag.Tags;
*
* Created by wusheng on 2017/2/20.
*/
public enum TomcatSpanGenerator {
INSTANCE;
/**
* When tomcat response 200.
*/
public void on200(){
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);
ContextManager.INSTANCE.stopSpan(webSpan);
public class TomcatSpanGenerator{
public static class ON200 extends SpanGeneration{
public static final ON200 INSTANCE = new ON200();
@Override protected void before() {
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);
}
@Override protected void after() {
Span webSpan = ContextManager.INSTANCE.activeSpan();
Tags.STATUS_CODE.set(webSpan, 200);
ContextManager.INSTANCE.stopSpan();
}
}
/**
* When tomcat response 404.
*/
public void on404(){
Span webSpan = ContextManager.INSTANCE.createSpan("/web/service/unknown");
Tags.COMPONENT.set(webSpan, "tomcat");
Tags.URL.set(webSpan, "http://10.21.9.35/web/unknown");
Tags.SPAN_KIND.set(webSpan, Tags.SPAN_KIND_SERVER);
Tags.STATUS_CODE.set(webSpan, 404);
Tags.ERROR.set(webSpan,true);
ContextManager.INSTANCE.stopSpan(webSpan);
public static class ON404 extends SpanGeneration{
public static final ON404 INSTANCE = new ON404();
@Override protected void before() {
Span webSpan = ContextManager.INSTANCE.createSpan("/web/service/unknown");
Tags.COMPONENT.set(webSpan, "tomcat");
Tags.URL.set(webSpan, "http://10.21.9.35/web/unknown");
Tags.SPAN_KIND.set(webSpan, Tags.SPAN_KIND_SERVER);
}
@Override protected void after() {
Span webSpan = ContextManager.INSTANCE.activeSpan();
Tags.STATUS_CODE.set(webSpan, 404);
Tags.ERROR.set(webSpan,true);
ContextManager.INSTANCE.stopSpan();
}
}
public static class ON500 extends SpanGeneration{
public static final ON500 INSTANCE = new ON500();
@Override protected void before() {
Span webSpan = ContextManager.INSTANCE.createSpan("/web/error/service");
Tags.COMPONENT.set(webSpan, "tomcat");
Tags.URL.set(webSpan, "http://10.21.9.35/web/error/service");
Tags.SPAN_KIND.set(webSpan, Tags.SPAN_KIND_SERVER);
}
/**
* When tomcat response 500.
*/
public void on500(){
Span webSpan = ContextManager.INSTANCE.createSpan("/web/error/service");
Tags.COMPONENT.set(webSpan, "tomcat");
Tags.URL.set(webSpan, "http://10.21.9.35/web/error/service");
Tags.SPAN_KIND.set(webSpan, Tags.SPAN_KIND_SERVER);
Tags.STATUS_CODE.set(webSpan, 500);
Tags.ERROR.set(webSpan,true);
webSpan.log(new NumberFormatException("Can't convert 'abc' to int."));
ContextManager.INSTANCE.stopSpan(webSpan);
@Override protected void after() {
Span webSpan = ContextManager.INSTANCE.activeSpan();
Tags.STATUS_CODE.set(webSpan, 500);
Tags.ERROR.set(webSpan,true);
webSpan.log(new NumberFormatException("Can't convert 'abc' to int."));
ContextManager.INSTANCE.stopSpan();
}
}
}
......@@ -14,7 +14,7 @@ public enum SingleTomcat200TraceBuilder implements TraceSegmentBuilder {
INSTANCE;
@Override public TraceSegment build(MockTracerContextListener listener) {
TomcatSpanGenerator.INSTANCE.on200();
TomcatSpanGenerator.ON200.INSTANCE.build().generate();
return listener.getFinished(0);
}
}
......@@ -14,7 +14,7 @@ public enum SingleTomcat404TraceBuilder implements TraceSegmentBuilder {
INSTANCE;
@Override public TraceSegment build(MockTracerContextListener listener) {
TomcatSpanGenerator.INSTANCE.on404();
TomcatSpanGenerator.ON404.INSTANCE.build().generate();
return listener.getFinished(0);
}
}
......@@ -14,7 +14,7 @@ public enum SingleTomcat500TraceBuilder implements TraceSegmentBuilder {
INSTANCE;
@Override public TraceSegment build(MockTracerContextListener listener) {
TomcatSpanGenerator.INSTANCE.on500();
TomcatSpanGenerator.ON500.INSTANCE.build().generate();
return listener.getFinished(0);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册