Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿信在这里
SkyWalking
提交
431dd9b5
S
SkyWalking
项目概览
阿信在这里
/
SkyWalking
与 Fork 源项目一致
Fork自
山不在高_有仙则灵 / SkyWalking
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
431dd9b5
编写于
2月 19, 2017
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
increase test converage.
上级
47df503b
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
212 addition
and
19 deletion
+212
-19
skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/Span.java
...-trace/src/main/java/com/a/eye/skywalking/trace/Span.java
+10
-0
skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceSegment.java
...rc/main/java/com/a/eye/skywalking/trace/TraceSegment.java
+10
-0
skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceSegmentRef.java
...main/java/com/a/eye/skywalking/trace/TraceSegmentRef.java
+9
-1
skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/context/ContextCarrier.java
...ain/java/com/a/eye/skywalking/context/ContextCarrier.java
+10
-1
skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/context/TracerContext.java
...main/java/com/a/eye/skywalking/context/TracerContext.java
+9
-2
skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/bytebuddy/ConstructorInterceptor.java
...om/a/eye/skywalking/bytebuddy/ConstructorInterceptor.java
+1
-1
skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/bytebuddy/MethodInterceptor.java
...ava/com/a/eye/skywalking/bytebuddy/MethodInterceptor.java
+1
-1
skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/bytebuddy/SimulateMain.java
...est/java/com/a/eye/skywalking/bytebuddy/SimulateMain.java
+1
-1
skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/bytebuddy/SimulateMain2.java
...st/java/com/a/eye/skywalking/bytebuddy/SimulateMain2.java
+1
-1
skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/bytebuddy/TestClass.java
...c/test/java/com/a/eye/skywalking/bytebuddy/TestClass.java
+1
-1
skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/context/ContextCarrierTest.java
...java/com/a/eye/skywalking/context/ContextCarrierTest.java
+50
-0
skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/context/TracerContextTest.java
.../java/com/a/eye/skywalking/context/TracerContextTest.java
+101
-0
skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/plugin/BeInterceptedClass.java
.../java/com/a/eye/skywalking/plugin/BeInterceptedClass.java
+1
-1
skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/plugin/PluginMainTest.java
...test/java/com/a/eye/skywalking/plugin/PluginMainTest.java
+3
-5
skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/plugin/PluginResourceResoverTest.java
...om/a/eye/skywalking/plugin/PluginResourceResoverTest.java
+1
-1
skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/plugin/TestAroundInterceptor.java
...va/com/a/eye/skywalking/plugin/TestAroundInterceptor.java
+1
-1
skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/plugin/TestInterceptorDefine.java
...va/com/a/eye/skywalking/plugin/TestInterceptorDefine.java
+1
-1
skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/plugin/TestStaticAroundInterceptor.java
.../a/eye/skywalking/plugin/TestStaticAroundInterceptor.java
+1
-1
未找到文件。
skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/Span.java
浏览文件 @
431dd9b5
...
...
@@ -252,4 +252,14 @@ public class Span {
public
List
<
LogData
>
getLogs
()
{
return
Collections
.
unmodifiableList
(
logs
);
}
@Override
public
String
toString
()
{
return
"Span{"
+
"spanId="
+
spanId
+
", parentSpanId="
+
parentSpanId
+
", startTime="
+
startTime
+
", operationName='"
+
operationName
+
'\''
+
'}'
;
}
}
skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceSegment.java
浏览文件 @
431dd9b5
...
...
@@ -124,4 +124,14 @@ public class TraceSegment {
public
List
<
Span
>
getSpans
()
{
return
Collections
.
unmodifiableList
(
spans
);
}
@Override
public
String
toString
()
{
return
"TraceSegment{"
+
"traceSegmentId='"
+
traceSegmentId
+
'\''
+
", endTime="
+
endTime
+
", primaryRef="
+
primaryRef
+
", spans.size="
+
spans
.
size
()
+
'}'
;
}
}
skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceSegmentRef.java
浏览文件 @
431dd9b5
...
...
@@ -15,7 +15,7 @@ public class TraceSegmentRef {
/**
* {@link Span#spanId}
*/
private
int
spanId
;
private
int
spanId
=
-
1
;
/**
* Create a {@link TraceSegmentRef} instance, without any data.
...
...
@@ -38,4 +38,12 @@ public class TraceSegmentRef {
public
void
setSpanId
(
int
spanId
)
{
this
.
spanId
=
spanId
;
}
@Override
public
String
toString
()
{
return
"TraceSegmentRef{"
+
"traceSegmentId='"
+
traceSegmentId
+
'\''
+
", spanId="
+
spanId
+
'}'
;
}
}
skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/context/ContextCarrier.java
浏览文件 @
431dd9b5
...
...
@@ -29,7 +29,7 @@ public class ContextCarrier extends TraceSegmentRef implements Serializable {
*/
public
ContextCarrier
deserialize
(
String
text
)
{
if
(
text
!=
null
){
String
[]
parts
=
text
.
split
(
"|"
);
String
[]
parts
=
text
.
split
(
"
\\
|"
);
if
(
parts
.
length
==
2
){
try
{
setSpanId
(
Integer
.
parseInt
(
parts
[
1
]));
...
...
@@ -42,4 +42,13 @@ public class ContextCarrier extends TraceSegmentRef implements Serializable {
return
this
;
}
/**
* Make sure this {@link ContextCarrier} has been initialized.
*
* @return true for unbroken {@link ContextCarrier} or no-initialized. Otherwise, false;
*/
public
boolean
isValid
(){
return
!
StringUtil
.
isEmpty
(
getTraceSegmentId
())
&&
getSpanId
()
>
-
1
;
}
}
skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/context/TracerContext.java
浏览文件 @
431dd9b5
...
...
@@ -95,7 +95,7 @@ public final class TracerContext {
*
* @param carrier holds the snapshot
*/
p
rivate
void
inject
(
ContextCarrier
carrier
)
{
p
ublic
void
inject
(
ContextCarrier
carrier
)
{
carrier
.
setTraceSegmentId
(
this
.
segment
.
getTraceSegmentId
());
carrier
.
setSpanId
(
this
.
activeSpan
().
getSpanId
());
}
...
...
@@ -106,7 +106,7 @@ public final class TracerContext {
* @param carrier holds the snapshot, if get this {@link ContextCarrier} from remote, make sure {@link
* ContextCarrier#deserialize(String)} called.
*/
p
rivate
void
extract
(
ContextCarrier
carrier
)
{
p
ublic
void
extract
(
ContextCarrier
carrier
)
{
this
.
segment
.
ref
(
carrier
);
}
...
...
@@ -169,5 +169,12 @@ public final class TracerContext {
listener
.
afterFinished
(
finishedSegment
);
}
}
/**
* Clear the given {@link TracerContextListener}
*/
static
synchronized
void
remove
(
TracerContextListener
listener
){
listeners
.
remove
(
listener
);
}
}
}
skywalking-sniffer/skywalking-api/src/test/java/
test/a/eye/cloud
/bytebuddy/ConstructorInterceptor.java
→
skywalking-sniffer/skywalking-api/src/test/java/
com/a/eye/skywalking
/bytebuddy/ConstructorInterceptor.java
浏览文件 @
431dd9b5
package
test.a.eye.cloud
.bytebuddy
;
package
com.a.eye.skywalking
.bytebuddy
;
import
net.bytebuddy.implementation.bind.annotation.AllArguments
;
import
net.bytebuddy.implementation.bind.annotation.RuntimeType
;
...
...
skywalking-sniffer/skywalking-api/src/test/java/
test/a/eye/cloud
/bytebuddy/MethodInterceptor.java
→
skywalking-sniffer/skywalking-api/src/test/java/
com/a/eye/skywalking
/bytebuddy/MethodInterceptor.java
浏览文件 @
431dd9b5
package
test.a.eye.cloud
.bytebuddy
;
package
com.a.eye.skywalking
.bytebuddy
;
import
java.lang.reflect.Method
;
import
java.util.concurrent.Callable
;
...
...
skywalking-sniffer/skywalking-api/src/test/java/
test/a/eye/cloud
/bytebuddy/SimulateMain.java
→
skywalking-sniffer/skywalking-api/src/test/java/
com/a/eye/skywalking
/bytebuddy/SimulateMain.java
浏览文件 @
431dd9b5
package
test.a.eye.cloud
.bytebuddy
;
package
com.a.eye.skywalking
.bytebuddy
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
isConstructor
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
isMethod
;
...
...
skywalking-sniffer/skywalking-api/src/test/java/
test/a/eye/cloud
/bytebuddy/SimulateMain2.java
→
skywalking-sniffer/skywalking-api/src/test/java/
com/a/eye/skywalking
/bytebuddy/SimulateMain2.java
浏览文件 @
431dd9b5
package
test.a.eye.cloud
.bytebuddy
;
package
com.a.eye.skywalking
.bytebuddy
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
isConstructor
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
...
...
skywalking-sniffer/skywalking-api/src/test/java/
test/a/eye/cloud
/bytebuddy/TestClass.java
→
skywalking-sniffer/skywalking-api/src/test/java/
com/a/eye/skywalking
/bytebuddy/TestClass.java
浏览文件 @
431dd9b5
package
test.a.eye.cloud
.bytebuddy
;
package
com.a.eye.skywalking
.bytebuddy
;
public
class
TestClass
{
public
TestClass
(){
...
...
skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/context/ContextCarrierTest.java
0 → 100644
浏览文件 @
431dd9b5
package
com.a.eye.skywalking.context
;
import
org.junit.Assert
;
import
org.junit.Test
;
/**
* Created by wusheng on 2017/2/19.
*/
public
class
ContextCarrierTest
{
@Test
public
void
testSerialize
(){
ContextCarrier
carrier
=
new
ContextCarrier
();
carrier
.
setTraceSegmentId
(
"trace_id_A"
);
carrier
.
setSpanId
(
100
);
Assert
.
assertEquals
(
"trace_id_A|100"
,
carrier
.
serialize
());
}
@Test
public
void
testDeserialize
(){
ContextCarrier
carrier
=
new
ContextCarrier
();
carrier
.
deserialize
(
"trace_id_A|100"
);
Assert
.
assertEquals
(
"trace_id_A"
,
carrier
.
getTraceSegmentId
());
Assert
.
assertEquals
(
100
,
carrier
.
getSpanId
());
}
@Test
public
void
testIllegalDeserialize
(){
ContextCarrier
carrier
=
new
ContextCarrier
();
carrier
.
deserialize
(
"abcde"
);
Assert
.
assertFalse
(
carrier
.
isValid
());
carrier
=
new
ContextCarrier
();
carrier
.
deserialize
(
"trace_id|-100"
);
Assert
.
assertFalse
(
carrier
.
isValid
());
carrier
=
new
ContextCarrier
();
carrier
.
deserialize
(
"trace_id|illegal-spanid"
);
Assert
.
assertFalse
(
carrier
.
isValid
());
carrier
=
new
ContextCarrier
();
carrier
.
deserialize
(
"trace_id|100|other-illegal"
);
Assert
.
assertFalse
(
carrier
.
isValid
());
carrier
=
new
ContextCarrier
();
carrier
.
deserialize
(
"trace_id|100"
);
Assert
.
assertTrue
(
carrier
.
isValid
());
}
}
skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/context/TracerContextTest.java
0 → 100644
浏览文件 @
431dd9b5
package
com.a.eye.skywalking.context
;
import
com.a.eye.skywalking.trace.Span
;
import
com.a.eye.skywalking.trace.TraceSegment
;
import
org.junit.After
;
import
org.junit.Assert
;
import
org.junit.Test
;
/**
* Created by wusheng on 2017/2/19.
*/
public
class
TracerContextTest
{
@Test
public
void
testSpanLifeCycle
(){
TracerContext
context
=
new
TracerContext
();
Span
span
=
context
.
createSpan
(
"/serviceA"
);
Assert
.
assertEquals
(
span
,
context
.
activeSpan
());
TracerContext
.
ListenerManager
.
add
(
TestTracerContextListener
.
INSTANCE
);
final
TraceSegment
[]
finishedSegmentCarrier
=
TestTracerContextListener
.
INSTANCE
.
finishedSegmentCarrier
;
context
.
stopSpan
(
span
);
Assert
.
assertNotNull
(
finishedSegmentCarrier
[
0
]);
Assert
.
assertEquals
(
1
,
finishedSegmentCarrier
[
0
].
getSpans
().
size
());
Assert
.
assertEquals
(
span
,
finishedSegmentCarrier
[
0
].
getSpans
().
get
(
0
));
}
@Test
public
void
testChildOfSpan
(){
TracerContext
context
=
new
TracerContext
();
Span
serviceSpan
=
context
.
createSpan
(
"/serviceA"
);
Span
dbSpan
=
context
.
createSpan
(
"db/preparedStatement/execute"
);
Assert
.
assertEquals
(
dbSpan
,
context
.
activeSpan
());
TracerContext
.
ListenerManager
.
add
(
TestTracerContextListener
.
INSTANCE
);
final
TraceSegment
[]
finishedSegmentCarrier
=
TestTracerContextListener
.
INSTANCE
.
finishedSegmentCarrier
;
try
{
context
.
stopSpan
(
serviceSpan
);
}
catch
(
Throwable
t
){
Assert
.
assertTrue
(
t
instanceof
IllegalStateException
);
}
context
.
stopSpan
(
dbSpan
);
context
.
stopSpan
(
serviceSpan
);
Assert
.
assertNotNull
(
finishedSegmentCarrier
[
0
]);
Assert
.
assertEquals
(
2
,
finishedSegmentCarrier
[
0
].
getSpans
().
size
());
Assert
.
assertEquals
(
dbSpan
,
finishedSegmentCarrier
[
0
].
getSpans
().
get
(
0
));
}
@Test
public
void
testInject
(){
TracerContext
context
=
new
TracerContext
();
Span
serviceSpan
=
context
.
createSpan
(
"/serviceA"
);
Span
dbSpan
=
context
.
createSpan
(
"db/preparedStatement/execute"
);
ContextCarrier
carrier
=
new
ContextCarrier
();
context
.
inject
(
carrier
);
Assert
.
assertTrue
(
carrier
.
isValid
());
Assert
.
assertEquals
(
1
,
carrier
.
getSpanId
());
}
@Test
public
void
testExtract
(){
ContextCarrier
carrier
=
new
ContextCarrier
();
carrier
.
setTraceSegmentId
(
"trace_id_1"
);
carrier
.
setSpanId
(
5
);
Assert
.
assertTrue
(
carrier
.
isValid
());
TracerContext
context
=
new
TracerContext
();
context
.
extract
(
carrier
);
Span
span
=
context
.
createSpan
(
"/serviceC"
);
TracerContext
.
ListenerManager
.
add
(
TestTracerContextListener
.
INSTANCE
);
final
TraceSegment
[]
finishedSegmentCarrier
=
TestTracerContextListener
.
INSTANCE
.
finishedSegmentCarrier
;
context
.
stopSpan
(
span
);
Assert
.
assertEquals
(
"trace_id_1"
,
finishedSegmentCarrier
[
0
].
getPrimaryRef
().
getTraceSegmentId
());
Assert
.
assertEquals
(
5
,
finishedSegmentCarrier
[
0
].
getPrimaryRef
().
getSpanId
());
}
@After
public
void
reset
(){
TracerContext
.
ListenerManager
.
remove
(
TestTracerContextListener
.
INSTANCE
);
}
public
enum
TestTracerContextListener
implements
TracerContextListener
{
INSTANCE
;
final
TraceSegment
[]
finishedSegmentCarrier
=
{
null
};
@Override
public
void
afterFinished
(
TraceSegment
traceSegment
)
{
finishedSegmentCarrier
[
0
]
=
traceSegment
;
}
}
}
skywalking-sniffer/skywalking-api/src/test/java/
test/a/eye/cloud
/plugin/BeInterceptedClass.java
→
skywalking-sniffer/skywalking-api/src/test/java/
com/a/eye/skywalking
/plugin/BeInterceptedClass.java
浏览文件 @
431dd9b5
package
test.a.eye.cloud
.plugin
;
package
com.a.eye.skywalking
.plugin
;
public
class
BeInterceptedClass
{
public
BeInterceptedClass
(){
...
...
skywalking-sniffer/skywalking-api/src/test/java/
test/a/eye/cloud
/plugin/PluginMainTest.java
→
skywalking-sniffer/skywalking-api/src/test/java/
com/a/eye/skywalking
/plugin/PluginMainTest.java
浏览文件 @
431dd9b5
package
test.a.eye.cloud
.plugin
;
package
com.a.eye.skywalking
.plugin
;
import
com.a.eye.skywalking.plugin.PluginException
;
import
com.a.eye.skywalking.plugin.TracingBootstrap
;
import
org.junit.Test
;
import
java.lang.reflect.InvocationTargetException
;
...
...
@@ -9,7 +7,7 @@ import java.lang.reflect.InvocationTargetException;
public
class
PluginMainTest
{
@Test
public
void
testMain
()
throws
ClassNotFoundException
,
NoSuchMethodException
,
InvocationTargetException
,
IllegalAccessException
,
PluginException
{
TracingBootstrap
.
main
(
new
String
[]
{
"
test.a.eye.cloud.plugin.
PluginMainTest"
});
TracingBootstrap
.
main
(
new
String
[]
{
"PluginMainTest"
});
}
public
static
void
main
(
String
[]
args
)
...
...
@@ -17,7 +15,7 @@ public class PluginMainTest {
SecurityException
{
long
start
=
System
.
currentTimeMillis
();
BeInterceptedClass
inst
=
(
BeInterceptedClass
)
Class
.
forName
(
"
test.a.eye.cloud.plugin.
BeInterceptedClass"
).
newInstance
();
BeInterceptedClass
inst
=
(
BeInterceptedClass
)
Class
.
forName
(
"BeInterceptedClass"
).
newInstance
();
inst
.
printabc
();
long
end
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
end
-
start
+
"ms"
);
...
...
skywalking-sniffer/skywalking-api/src/test/java/
test/a/eye/cloud
/plugin/PluginResourceResoverTest.java
→
skywalking-sniffer/skywalking-api/src/test/java/
com/a/eye/skywalking
/plugin/PluginResourceResoverTest.java
浏览文件 @
431dd9b5
package
test.a.eye.cloud
.plugin
;
package
com.a.eye.skywalking
.plugin
;
import
java.io.IOException
;
...
...
skywalking-sniffer/skywalking-api/src/test/java/
test/a/eye/cloud
/plugin/TestAroundInterceptor.java
→
skywalking-sniffer/skywalking-api/src/test/java/
com/a/eye/skywalking
/plugin/TestAroundInterceptor.java
浏览文件 @
431dd9b5
package
test.a.eye.cloud
.plugin
;
package
com.a.eye.skywalking
.plugin
;
import
com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext
;
import
com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext
;
...
...
skywalking-sniffer/skywalking-api/src/test/java/
test/a/eye/cloud
/plugin/TestInterceptorDefine.java
→
skywalking-sniffer/skywalking-api/src/test/java/
com/a/eye/skywalking
/plugin/TestInterceptorDefine.java
浏览文件 @
431dd9b5
package
test.a.eye.cloud
.plugin
;
package
com.a.eye.skywalking
.plugin
;
import
com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint
;
import
com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint
;
...
...
skywalking-sniffer/skywalking-api/src/test/java/
test/a/eye/cloud
/plugin/TestStaticAroundInterceptor.java
→
skywalking-sniffer/skywalking-api/src/test/java/
com/a/eye/skywalking
/plugin/TestStaticAroundInterceptor.java
浏览文件 @
431dd9b5
package
test.a.eye.cloud
.plugin
;
package
com.a.eye.skywalking
.plugin
;
import
com.a.eye.skywalking.plugin.interceptor.enhance.MethodInterceptResult
;
import
com.a.eye.skywalking.plugin.interceptor.enhance.MethodInvokeContext
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录