Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
SkyWalking
提交
6543814f
S
SkyWalking
项目概览
apache
/
SkyWalking
上一次同步 大约 1 年
通知
302
Star
21345
Fork
6091
代码
文件
提交
分支
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,体验更适合开发者的 AI 搜索 >>
提交
6543814f
编写于
10月 25, 2017
作者:
wu-sheng
提交者:
GitHub
10月 25, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #544 from OpenSkywalking/fix/sjdbcbug
Plugin test must compile with jdk 1.6, so not allow to use lambda.
上级
0e23b024
12c3c4ef
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
22 deletion
+30
-22
apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/test/java/org/skywalking/apm/plugin/sjdbc/InterceptorTest.java
...java/org/skywalking/apm/plugin/sjdbc/InterceptorTest.java
+30
-22
未找到文件。
apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/test/java/org/skywalking/apm/plugin/sjdbc/InterceptorTest.java
浏览文件 @
6543814f
...
...
@@ -26,7 +26,7 @@ import com.dangdang.ddframe.rdb.sharding.executor.threadlocal.ExecutorDataMap;
import
com.dangdang.ddframe.rdb.sharding.util.EventBusInstance
;
import
com.google.common.base.Optional
;
import
java.sql.SQLException
;
import
java.util.Array
s
;
import
java.util.Array
List
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -65,40 +65,40 @@ import static org.skywalking.apm.agent.test.tools.SpanAssert.assertTag;
@RunWith
(
PowerMockRunner
.
class
)
@PowerMockRunnerDelegate
(
TracingSegmentRunner
.
class
)
public
class
InterceptorTest
{
private
static
ExecutorService
ES
;
@SegmentStoragePoint
private
SegmentStorage
segmentStorage
;
@Rule
public
AgentServiceRule
serviceRule
=
new
AgentServiceRule
();
private
ExecuteInterceptor
executeInterceptor
;
private
AsyncExecuteInterceptor
asyncExecuteInterceptor
;
private
Object
[]
allArguments
;
@BeforeClass
public
static
void
init
()
{
ExecuteEventListener
.
init
();
new
ExecutorEngineConstructorInterceptor
().
onConstruct
(
null
,
null
);
ES
=
Executors
.
newSingleThreadExecutor
();
}
@AfterClass
public
static
void
finish
()
{
ES
.
shutdown
();
}
@Before
public
void
setUp
()
throws
SQLException
{
executeInterceptor
=
new
ExecuteInterceptor
();
asyncExecuteInterceptor
=
new
AsyncExecuteInterceptor
();
allArguments
=
new
Object
[]{
SQLType
.
DQL
,
null
};
allArguments
=
new
Object
[]
{
SQLType
.
DQL
,
null
};
}
@Test
public
void
assertSyncExecute
()
throws
Throwable
{
executeInterceptor
.
beforeMethod
(
null
,
null
,
allArguments
,
null
,
null
);
...
...
@@ -106,7 +106,7 @@ public class InterceptorTest {
executeInterceptor
.
afterMethod
(
null
,
null
,
allArguments
,
null
,
null
);
assertThat
(
segmentStorage
.
getTraceSegments
().
size
(),
is
(
1
));
TraceSegment
segment
=
segmentStorage
.
getTraceSegments
().
get
(
0
);
List
<
AbstractTracingSpan
>
spans
=
SegmentHelper
.
getSpans
(
segment
);
List
<
AbstractTracingSpan
>
spans
=
SegmentHelper
.
getSpans
(
segment
);
assertNotNull
(
spans
);
assertThat
(
spans
.
size
(),
is
(
2
));
assertSpan
(
spans
.
get
(
0
),
0
);
...
...
@@ -118,9 +118,11 @@ public class InterceptorTest {
executeInterceptor
.
beforeMethod
(
null
,
null
,
allArguments
,
null
,
null
);
asyncExecuteInterceptor
.
beforeMethod
(
null
,
null
,
null
,
null
,
null
);
final
Map
<
String
,
Object
>
dataMap
=
ExecutorDataMap
.
getDataMap
();
ES
.
submit
(()
->
{
ExecutorDataMap
.
setDataMap
(
dataMap
);
sendEvent
(
"ds_1"
,
"select * from t_order_1"
);
ES
.
submit
(
new
Runnable
()
{
@Override
public
void
run
()
{
ExecutorDataMap
.
setDataMap
(
dataMap
);
sendEvent
(
"ds_1"
,
"select * from t_order_1"
);
}
}).
get
();
asyncExecuteInterceptor
.
afterMethod
(
null
,
null
,
null
,
null
,
null
);
sendEvent
(
"ds_0"
,
"select * from t_order_0"
);
...
...
@@ -140,15 +142,17 @@ public class InterceptorTest {
assertSpan
(
spans1
.
get
(
0
),
0
);
assertThat
(
spans1
.
get
(
1
).
getOperationName
(),
is
(
"/SJDBC/TRUNK/DQL"
));
}
@Test
public
void
assertExecuteError
()
throws
Throwable
{
executeInterceptor
.
beforeMethod
(
null
,
null
,
allArguments
,
null
,
null
);
asyncExecuteInterceptor
.
beforeMethod
(
null
,
null
,
null
,
null
,
null
);
final
Map
<
String
,
Object
>
dataMap
=
ExecutorDataMap
.
getDataMap
();
ES
.
submit
(()
->
{
ExecutorDataMap
.
setDataMap
(
dataMap
);
sendError
();
ES
.
submit
(
new
Runnable
()
{
@Override
public
void
run
()
{
ExecutorDataMap
.
setDataMap
(
dataMap
);
sendError
();
}
}).
get
();
asyncExecuteInterceptor
.
handleMethodException
(
null
,
null
,
null
,
null
,
new
SQLException
(
"test"
));
asyncExecuteInterceptor
.
afterMethod
(
null
,
null
,
null
,
null
,
null
);
...
...
@@ -178,18 +182,22 @@ public class InterceptorTest {
assertThat
(
span
.
isExit
(),
is
(
true
));
assertThat
(
span
.
getOperationName
(),
is
(
"/SJDBC/BRANCH/QUERY"
));
}
private
void
assertErrorSpan
(
AbstractTracingSpan
span
)
{
assertOccurException
(
span
,
true
);
}
private
void
sendEvent
(
String
datasource
,
String
sql
)
{
DQLExecutionEvent
event
=
new
DQLExecutionEvent
(
datasource
,
sql
,
Arrays
.
asList
(
"1"
,
100
));
List
<
Object
>
parameters
=
new
ArrayList
<
Object
>();
parameters
.
add
(
"1"
);
parameters
.
add
(
100
);
DQLExecutionEvent
event
=
new
DQLExecutionEvent
(
datasource
,
sql
,
parameters
);
EventBusInstance
.
getInstance
().
post
(
event
);
event
.
setEventExecutionType
(
EventExecutionType
.
EXECUTE_SUCCESS
);
EventBusInstance
.
getInstance
().
post
(
event
);
}
private
void
sendError
()
{
DMLExecutionEvent
event
=
new
DMLExecutionEvent
(
""
,
""
,
Collections
.
emptyList
());
EventBusInstance
.
getInstance
().
post
(
event
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录