Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
山不在高_有仙则灵
SkyWalking
提交
d9b3321d
S
SkyWalking
项目概览
山不在高_有仙则灵
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
12
Star
0
Fork
2
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
d9b3321d
编写于
7月 08, 2017
作者:
A
ascrutae
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add clear agent service rule
上级
a382f3f7
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
140 addition
and
22 deletion
+140
-22
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/boot/ServiceManagerTest.java
...rg/skywalking/apm/agent/core/boot/ServiceManagerTest.java
+8
-1
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/ContextManagerTest.java
...skywalking/apm/agent/core/context/ContextManagerTest.java
+7
-9
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/IgnoredTracerContextTest.java
...king/apm/agent/core/context/IgnoredTracerContextTest.java
+8
-5
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/remote/DiscoveryRestServiceClientTest.java
...apm/agent/core/remote/DiscoveryRestServiceClientTest.java
+4
-0
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/remote/GRPCChannelManagerTest.java
...walking/apm/agent/core/remote/GRPCChannelManagerTest.java
+1
-0
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/remote/TraceSegmentServiceClientTest.java
.../apm/agent/core/remote/TraceSegmentServiceClientTest.java
+8
-4
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/AgentServiceRule.java
...kywalking/apm/agent/core/test/tools/AgentServiceRule.java
+28
-0
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/SegmentStorage.java
.../skywalking/apm/agent/core/test/tools/SegmentStorage.java
+2
-2
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/SegmentStoragePoint.java
...alking/apm/agent/core/test/tools/SegmentStoragePoint.java
+1
-1
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/TracingSegmentRunner.java
...lking/apm/agent/core/test/tools/TracingSegmentRunner.java
+73
-0
未找到文件。
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/boot/ServiceManagerTest.java
浏览文件 @
d9b3321d
...
...
@@ -3,7 +3,10 @@ package org.skywalking.apm.agent.core.boot;
import
java.lang.reflect.Field
;
import
java.util.HashMap
;
import
java.util.List
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.skywalking.apm.agent.core.boot.BootService
;
import
org.skywalking.apm.agent.core.boot.ServiceManager
;
import
org.skywalking.apm.agent.core.context.ContextManager
;
import
org.skywalking.apm.agent.core.context.IgnoredTracerContext
;
import
org.skywalking.apm.agent.core.context.TracingContext
;
...
...
@@ -14,6 +17,7 @@ import org.skywalking.apm.agent.core.remote.GRPCChannelListener;
import
org.skywalking.apm.agent.core.remote.GRPCChannelManager
;
import
org.skywalking.apm.agent.core.remote.TraceSegmentServiceClient
;
import
org.skywalking.apm.agent.core.sampling.SamplingService
;
import
org.skywalking.apm.agent.core.test.tools.AgentServiceRule
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
...
...
@@ -21,9 +25,12 @@ import static org.junit.Assert.assertEquals;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
public
class
ServiceManagerTest
{
@Rule
public
AgentServiceRule
agentServiceRule
=
new
AgentServiceRule
();
@Test
public
void
testServiceDependencies
()
throws
Exception
{
ServiceManager
.
INSTANCE
.
boot
();
HashMap
<
Class
,
BootService
>
registryService
=
getFieldValue
(
ServiceManager
.
INSTANCE
,
"bootedServices"
);
assertThat
(
registryService
.
size
(),
is
(
7
));
...
...
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/ContextManagerTest.java
浏览文件 @
d9b3321d
package
org.skywalking.apm.agent.core.context
;
import
com.google.instrumentation.trace.Span
;
import
com.google.protobuf.InvalidProtocolBufferException
;
import
java.util.Date
;
import
java.util.List
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.skywalking.apm.agent.core.boot.ServiceManager
;
...
...
@@ -20,10 +19,11 @@ import org.skywalking.apm.agent.core.context.trace.TraceSegment;
import
org.skywalking.apm.agent.core.context.trace.TraceSegmentRef
;
import
org.skywalking.apm.agent.core.context.util.AbstractTracingSpanHelper
;
import
org.skywalking.apm.agent.core.context.util.SegmentHelper
;
import
org.skywalking.apm.agent.core.context.util.SegmentStorage
;
import
org.skywalking.apm.agent.core.context.util.SegmentStoragePoint
;
import
org.skywalking.apm.agent.core.test.tools.AgentServiceRule
;
import
org.skywalking.apm.agent.core.test.tools.SegmentStorage
;
import
org.skywalking.apm.agent.core.test.tools.SegmentStoragePoint
;
import
org.skywalking.apm.agent.core.context.util.TraceSegmentRefHelper
;
import
org.skywalking.apm.agent.core.
context.util
.TracingSegmentRunner
;
import
org.skywalking.apm.agent.core.
test.tools
.TracingSegmentRunner
;
import
org.skywalking.apm.agent.core.dictionary.DictionaryUtil
;
import
org.skywalking.apm.network.proto.KeyWithStringValue
;
import
org.skywalking.apm.network.proto.LogMessage
;
...
...
@@ -45,10 +45,8 @@ public class ContextManagerTest {
@SegmentStoragePoint
private
SegmentStorage
tracingData
;
@BeforeClass
public
static
void
setUpBeforeClass
()
{
ServiceManager
.
INSTANCE
.
boot
();
}
@Rule
public
AgentServiceRule
agentServiceRule
=
new
AgentServiceRule
();
@Before
public
void
setUp
()
throws
Exception
{
...
...
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/IgnoredTracerContextTest.java
浏览文件 @
d9b3321d
...
...
@@ -3,6 +3,7 @@ package org.skywalking.apm.agent.core.context;
import
java.util.LinkedList
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.skywalking.apm.agent.core.boot.ServiceManager
;
...
...
@@ -10,9 +11,10 @@ import org.skywalking.apm.agent.core.conf.Config;
import
org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig
;
import
org.skywalking.apm.agent.core.context.trace.AbstractSpan
;
import
org.skywalking.apm.agent.core.context.trace.NoopSpan
;
import
org.skywalking.apm.agent.core.context.util.SegmentStorage
;
import
org.skywalking.apm.agent.core.context.util.SegmentStoragePoint
;
import
org.skywalking.apm.agent.core.context.util.TracingSegmentRunner
;
import
org.skywalking.apm.agent.core.test.tools.AgentServiceRule
;
import
org.skywalking.apm.agent.core.test.tools.SegmentStorage
;
import
org.skywalking.apm.agent.core.test.tools.SegmentStoragePoint
;
import
org.skywalking.apm.agent.core.test.tools.TracingSegmentRunner
;
import
static
junit
.
framework
.
TestCase
.
assertNull
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
...
...
@@ -24,6 +26,9 @@ public class IgnoredTracerContextTest {
@SegmentStoragePoint
private
SegmentStorage
storage
;
@Rule
public
AgentServiceRule
agentServiceRule
=
new
AgentServiceRule
();
@Before
public
void
setUp
()
throws
Exception
{
RemoteDownstreamConfig
.
Agent
.
APPLICATION_ID
=
1
;
...
...
@@ -57,7 +62,6 @@ public class IgnoredTracerContextTest {
@Test
public
void
ignoredTraceContextWithExcludeOperationName
()
{
ServiceManager
.
INSTANCE
.
boot
();
AbstractSpan
abstractSpan
=
ContextManager
.
createEntrySpan
(
"test.js"
,
null
);
ContextManager
.
stopSpan
();
...
...
@@ -68,7 +72,6 @@ public class IgnoredTracerContextTest {
@Test
public
void
ignoredTraceContextWithEmptyOperationName
()
{
ServiceManager
.
INSTANCE
.
boot
();
ContextCarrier
contextCarrier
=
new
ContextCarrier
();
AbstractSpan
abstractSpan
=
ContextManager
.
createExitSpan
(
""
,
contextCarrier
,
"127.0.0.1:2181"
);
ContextManager
.
stopSpan
();
...
...
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/remote/DiscoveryRestServiceClientTest.java
浏览文件 @
d9b3321d
...
...
@@ -8,6 +8,7 @@ import org.junit.Rule;
import
org.junit.Test
;
import
org.skywalking.apm.agent.core.conf.Config
;
import
org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig
;
import
org.skywalking.apm.agent.core.test.tools.AgentServiceRule
;
import
static
com
.
github
.
tomakehurst
.
wiremock
.
client
.
WireMock
.
aResponse
;
import
static
com
.
github
.
tomakehurst
.
wiremock
.
client
.
WireMock
.
get
;
...
...
@@ -18,6 +19,9 @@ import static org.hamcrest.MatcherAssert.assertThat;
public
class
DiscoveryRestServiceClientTest
{
@Rule
public
AgentServiceRule
agentServiceRule
=
new
AgentServiceRule
();
private
DiscoveryRestServiceClient
client
;
@Rule
public
WireMockRule
wireMockRule
=
new
WireMockRule
(
8089
);
...
...
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/remote/GRPCChannelManagerTest.java
浏览文件 @
d9b3321d
...
...
@@ -18,6 +18,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import
org.powermock.modules.junit4.PowerMockRunner
;
import
org.powermock.reflect.Whitebox
;
import
org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig
;
import
org.skywalking.apm.agent.core.test.tools.AgentServiceRule
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
...
...
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/remote/TraceSegmentServiceClientTest.java
浏览文件 @
d9b3321d
...
...
@@ -17,9 +17,10 @@ import org.skywalking.apm.agent.core.context.ContextManager;
import
org.skywalking.apm.agent.core.context.tag.Tags
;
import
org.skywalking.apm.agent.core.context.trace.AbstractSpan
;
import
org.skywalking.apm.agent.core.context.trace.SpanLayer
;
import
org.skywalking.apm.agent.core.context.util.SegmentStorage
;
import
org.skywalking.apm.agent.core.context.util.SegmentStoragePoint
;
import
org.skywalking.apm.agent.core.context.util.TracingSegmentRunner
;
import
org.skywalking.apm.agent.core.test.tools.AgentServiceRule
;
import
org.skywalking.apm.agent.core.test.tools.SegmentStorage
;
import
org.skywalking.apm.agent.core.test.tools.SegmentStoragePoint
;
import
org.skywalking.apm.agent.core.test.tools.TracingSegmentRunner
;
import
org.skywalking.apm.network.proto.Downstream
;
import
org.skywalking.apm.network.proto.SpanObject
;
import
org.skywalking.apm.network.proto.SpanType
;
...
...
@@ -34,6 +35,10 @@ import static org.mockito.Mockito.spy;
@RunWith
(
TracingSegmentRunner
.
class
)
public
class
TraceSegmentServiceClientTest
{
@Rule
public
AgentServiceRule
agentServiceRule
=
new
AgentServiceRule
();
@Rule
public
GrpcServerRule
grpcServerRule
=
new
GrpcServerRule
().
directExecutor
();
...
...
@@ -73,7 +78,6 @@ public class TraceSegmentServiceClientTest {
@Before
public
void
setUp
()
throws
Throwable
{
ServiceManager
.
INSTANCE
.
boot
();
Whitebox
.
setInternalState
(
ServiceManager
.
INSTANCE
.
findService
(
GRPCChannelManager
.
class
),
"reconnect"
,
false
);
spy
(
serviceClient
);
...
...
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/test/tools/AgentServiceRule.java
0 → 100644
浏览文件 @
d9b3321d
package
org.skywalking.apm.agent.core.test.tools
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
org.junit.rules.ExternalResource
;
import
org.powermock.reflect.Whitebox
;
import
org.skywalking.apm.agent.core.boot.BootService
;
import
org.skywalking.apm.agent.core.boot.ServiceManager
;
import
org.skywalking.apm.agent.core.context.IgnoredTracerContext
;
import
org.skywalking.apm.agent.core.context.TracingContext
;
import
org.skywalking.apm.agent.core.context.TracingContextListener
;
public
class
AgentServiceRule
extends
ExternalResource
{
@Override
protected
void
after
()
{
super
.
after
();
Whitebox
.
setInternalState
(
ServiceManager
.
INSTANCE
,
"bootedServices"
,
new
HashMap
<
Class
,
BootService
>());
Whitebox
.
setInternalState
(
TracingContext
.
ListenerManager
.
class
,
"LISTENERS"
,
new
LinkedList
<
TracingContextListener
>()
);
Whitebox
.
setInternalState
(
IgnoredTracerContext
.
ListenerManager
.
class
,
"LISTENERS"
,
new
LinkedList
<
TracingContextListener
>()
);
}
@Override
protected
void
before
()
throws
Throwable
{
super
.
before
();
ServiceManager
.
INSTANCE
.
boot
();
}
}
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/
context/util
/SegmentStorage.java
→
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/
test/tools
/SegmentStorage.java
浏览文件 @
d9b3321d
package
org.skywalking.apm.agent.core.
context.util
;
package
org.skywalking.apm.agent.core.
test.tools
;
import
java.util.LinkedList
;
import
java.util.List
;
...
...
@@ -9,7 +9,7 @@ public class SegmentStorage {
private
LinkedList
<
TraceSegment
>
traceSegments
;
private
LinkedList
<
IgnoredTracerContext
>
ignoredTracerContexts
;
SegmentStorage
()
{
public
SegmentStorage
()
{
traceSegments
=
new
LinkedList
<
TraceSegment
>();
ignoredTracerContexts
=
new
LinkedList
<
IgnoredTracerContext
>();
}
...
...
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/
context/util
/SegmentStoragePoint.java
→
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/
test/tools
/SegmentStoragePoint.java
浏览文件 @
d9b3321d
package
org.skywalking.apm.agent.core.
context.util
;
package
org.skywalking.apm.agent.core.
test.tools
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
...
...
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/
context/util
/TracingSegmentRunner.java
→
apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/
test/tools
/TracingSegmentRunner.java
浏览文件 @
d9b3321d
package
org.skywalking.apm.agent.core.
context.util
;
package
org.skywalking.apm.agent.core.
test.tools
;
import
java.lang.reflect.Field
;
import
org.junit.runner.Description
;
import
org.junit.runner.notification.Failure
;
import
org.junit.runner.notification.RunNotifier
;
import
org.junit.runners.BlockJUnit4ClassRunner
;
import
org.junit.runners.model.FrameworkMethod
;
import
org.junit.runners.model.InitializationError
;
import
org.junit.runners.model.Statement
;
import
org.skywalking.apm.agent.core.context.IgnoreTracerContextListener
;
import
org.skywalking.apm.agent.core.context.IgnoredTracerContext
;
import
org.skywalking.apm.agent.core.context.TracingContext
;
...
...
@@ -36,51 +35,39 @@ public class TracingSegmentRunner extends BlockJUnit4ClassRunner {
return
targetObject
;
}
@Override
public
void
run
(
RunNotifier
notifier
)
{
notifier
.
addListener
(
new
RunListener
());
super
.
run
(
notifier
);
}
@Override
protected
Statement
withAfters
(
FrameworkMethod
method
,
Object
target
,
final
Statement
statement
)
{
return
new
Statement
()
{
@Override
public
void
evaluate
()
throws
Throwable
{
if
(
field
!=
null
)
{
try
{
tracingData
=
new
SegmentStorage
();
field
.
set
(
targetObject
,
tracingData
);
}
catch
(
IllegalAccessException
e
)
{
}
}
tracingContextListener
=
new
TracingContextListener
()
{
@Override
public
void
afterFinished
(
TraceSegment
traceSegment
)
{
tracingData
.
addTraceSegment
(
traceSegment
);
}
};
class
RunListener
extends
org
.
junit
.
runner
.
notification
.
RunListener
{
@Override
public
void
testStarted
(
Description
description
)
throws
Exception
{
if
(
field
!=
null
)
{
ignoreTracerContextListener
=
new
IgnoreTracerContextListener
()
{
@Override
public
void
afterFinished
(
IgnoredTracerContext
tracerContext
)
{
tracingData
.
addIgnoreTraceContext
(
tracerContext
);
}
};
TracingContext
.
ListenerManager
.
add
(
tracingContextListener
);
IgnoredTracerContext
.
ListenerManager
.
add
(
ignoreTracerContextListener
);
try
{
tracingData
=
new
SegmentStorage
();
field
.
set
(
targetObject
,
tracingData
);
}
catch
(
IllegalAccessException
e
)
{
statement
.
evaluate
();
}
finally
{
TracingContext
.
ListenerManager
.
remove
(
tracingContextListener
);
IgnoredTracerContext
.
ListenerManager
.
remove
(
ignoreTracerContextListener
);
}
}
tracingContextListener
=
new
TracingContextListener
()
{
@Override
public
void
afterFinished
(
TraceSegment
traceSegment
)
{
tracingData
.
addTraceSegment
(
traceSegment
);
}
};
ignoreTracerContextListener
=
new
IgnoreTracerContextListener
()
{
@Override
public
void
afterFinished
(
IgnoredTracerContext
tracerContext
)
{
tracingData
.
addIgnoreTraceContext
(
tracerContext
);
}
};
TracingContext
.
ListenerManager
.
add
(
tracingContextListener
);
IgnoredTracerContext
.
ListenerManager
.
add
(
ignoreTracerContextListener
);
super
.
testStarted
(
description
);
}
@Override
public
void
testFinished
(
Description
description
)
throws
Exception
{
super
.
testFinished
(
description
);
TracingContext
.
ListenerManager
.
remove
(
tracingContextListener
);
IgnoredTracerContext
.
ListenerManager
.
remove
(
ignoreTracerContextListener
);
}
@Override
public
void
testFailure
(
Failure
failure
)
throws
Exception
{
super
.
testFailure
(
failure
);
TracingContext
.
ListenerManager
.
remove
(
tracingContextListener
);
}
};
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录