Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
killuaz丶x
SkyWalking
提交
ed71efda
S
SkyWalking
项目概览
killuaz丶x
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / 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,发现更多精彩内容 >>
未验证
提交
ed71efda
编写于
8月 17, 2020
作者:
于
于玉桔
提交者:
GitHub
8月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix spring-kafka test unstable (#5313)
上级
a6e45d04
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
46 addition
and
44 deletion
+46
-44
test/plugin/scenarios/spring-kafka-2.2.x-scenario/src/main/java/test/org/apache/skywalking/apm/testcase/spring/kafka/controller/CaseController.java
.../apm/testcase/spring/kafka/controller/CaseController.java
+23
-22
test/plugin/scenarios/spring-kafka-2.3.x-scenario/src/main/java/test/org/apache/skywalking/apm/testcase/spring/kafka/controller/CaseController.java
.../apm/testcase/spring/kafka/controller/CaseController.java
+23
-22
未找到文件。
test/plugin/scenarios/spring-kafka-2.2.x-scenario/src/main/java/test/org/apache/skywalking/apm/testcase/spring/kafka/controller/CaseController.java
浏览文件 @
ed71efda
...
...
@@ -18,8 +18,6 @@
package
test.org.apache.skywalking.apm.testcase.spring.kafka.controller
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.TimeUnit
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
import
okhttp3.Response
;
...
...
@@ -46,6 +44,7 @@ import javax.annotation.PostConstruct;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.concurrent.CountDownLatch
;
@Controller
@RequestMapping
(
"/case"
)
...
...
@@ -60,6 +59,7 @@ public class CaseController {
private
KafkaTemplate
<
String
,
String
>
kafkaTemplate
;
private
CountDownLatch
latch
=
new
CountDownLatch
(
1
);
private
String
helloWorld
=
"helloWorld"
;
@PostConstruct
private
void
setUp
()
{
...
...
@@ -74,6 +74,12 @@ public class CaseController {
props
.
put
(
ProducerConfig
.
KEY_SERIALIZER_CLASS_CONFIG
,
StringSerializer
.
class
);
props
.
put
(
ProducerConfig
.
VALUE_SERIALIZER_CLASS_CONFIG
,
StringSerializer
.
class
);
kafkaTemplate
=
new
KafkaTemplate
<
String
,
String
>(
new
DefaultKafkaProducerFactory
<>(
props
));
try
{
kafkaTemplate
.
send
(
topicName
,
"key"
,
"ping"
).
get
();
kafkaTemplate
.
flush
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
private
void
setUpConsumer
()
{
...
...
@@ -87,16 +93,18 @@ public class CaseController {
props
.
setMessageListener
(
new
AcknowledgingMessageListener
<
String
,
String
>()
{
@Override
public
void
onMessage
(
ConsumerRecord
<
String
,
String
>
data
,
Acknowledgment
acknowledgment
)
{
OkHttpClient
client
=
new
OkHttpClient
.
Builder
().
build
();
Request
request
=
new
Request
.
Builder
().
url
(
"http://localhost:8080/spring-kafka-2.2.x-scenario/case/spring-kafka-consumer-ping"
).
build
();
Response
response
=
null
;
try
{
response
=
client
.
newCall
(
request
).
execute
();
}
catch
(
IOException
e
)
{
if
(
data
.
value
().
equals
(
helloWorld
))
{
OkHttpClient
client
=
new
OkHttpClient
.
Builder
().
build
();
Request
request
=
new
Request
.
Builder
().
url
(
"http://localhost:8080/spring-kafka-2.2.x-scenario/case/spring-kafka-consumer-ping"
).
build
();
Response
response
=
null
;
try
{
response
=
client
.
newCall
(
request
).
execute
();
}
catch
(
IOException
e
)
{
}
response
.
body
().
close
();
acknowledgment
.
acknowledge
();
latch
.
countDown
();
}
response
.
body
().
close
();
acknowledgment
.
acknowledge
();
latch
.
countDown
();
}
});
KafkaMessageListenerContainer
<
String
,
String
>
container
=
new
KafkaMessageListenerContainer
<>(
factory
,
props
);
...
...
@@ -106,17 +114,10 @@ public class CaseController {
@RequestMapping
(
"/spring-kafka-case"
)
@ResponseBody
public
String
springKafkaCase
()
{
try
{
kafkaTemplate
.
send
(
topicName
,
"key"
,
"helloWorld"
).
get
();
kafkaTemplate
.
flush
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
try
{
latch
.
await
(
2
,
TimeUnit
.
SECONDS
);
}
catch
(
InterruptedException
e
)
{
}
public
String
springKafkaCase
()
throws
Exception
{
kafkaTemplate
.
send
(
topicName
,
"key"
,
helloWorld
).
get
();
latch
.
await
();
kafkaTemplate
.
flush
();
return
SUCCESS
;
}
...
...
test/plugin/scenarios/spring-kafka-2.3.x-scenario/src/main/java/test/org/apache/skywalking/apm/testcase/spring/kafka/controller/CaseController.java
浏览文件 @
ed71efda
...
...
@@ -18,8 +18,6 @@
package
test.org.apache.skywalking.apm.testcase.spring.kafka.controller
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.TimeUnit
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
import
okhttp3.Response
;
...
...
@@ -46,6 +44,7 @@ import javax.annotation.PostConstruct;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.concurrent.CountDownLatch
;
@Controller
@RequestMapping
(
"/case"
)
...
...
@@ -60,6 +59,7 @@ public class CaseController {
private
KafkaTemplate
<
String
,
String
>
kafkaTemplate
;
private
CountDownLatch
latch
=
new
CountDownLatch
(
1
);
private
String
helloWorld
=
"helloWorld"
;
@PostConstruct
private
void
setUp
()
{
...
...
@@ -74,6 +74,12 @@ public class CaseController {
props
.
put
(
ProducerConfig
.
KEY_SERIALIZER_CLASS_CONFIG
,
StringSerializer
.
class
);
props
.
put
(
ProducerConfig
.
VALUE_SERIALIZER_CLASS_CONFIG
,
StringSerializer
.
class
);
kafkaTemplate
=
new
KafkaTemplate
<
String
,
String
>(
new
DefaultKafkaProducerFactory
<>(
props
));
try
{
kafkaTemplate
.
send
(
topicName
,
"key"
,
"ping"
).
get
();
kafkaTemplate
.
flush
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
private
void
setUpConsumer
()
{
...
...
@@ -87,16 +93,18 @@ public class CaseController {
props
.
setMessageListener
(
new
AcknowledgingMessageListener
<
String
,
String
>()
{
@Override
public
void
onMessage
(
ConsumerRecord
<
String
,
String
>
data
,
Acknowledgment
acknowledgment
)
{
OkHttpClient
client
=
new
OkHttpClient
.
Builder
().
build
();
Request
request
=
new
Request
.
Builder
().
url
(
"http://localhost:8080/spring-kafka-2.3.x-scenario/case/spring-kafka-consumer-ping"
).
build
();
Response
response
=
null
;
try
{
response
=
client
.
newCall
(
request
).
execute
();
}
catch
(
IOException
e
)
{
if
(
data
.
value
().
equals
(
helloWorld
))
{
OkHttpClient
client
=
new
OkHttpClient
.
Builder
().
build
();
Request
request
=
new
Request
.
Builder
().
url
(
"http://localhost:8080/spring-kafka-2.3.x-scenario/case/spring-kafka-consumer-ping"
).
build
();
Response
response
=
null
;
try
{
response
=
client
.
newCall
(
request
).
execute
();
}
catch
(
IOException
e
)
{
}
response
.
body
().
close
();
acknowledgment
.
acknowledge
();
latch
.
countDown
();
}
response
.
body
().
close
();
acknowledgment
.
acknowledge
();
latch
.
countDown
();
}
});
KafkaMessageListenerContainer
<
String
,
String
>
container
=
new
KafkaMessageListenerContainer
<>(
factory
,
props
);
...
...
@@ -106,17 +114,10 @@ public class CaseController {
@RequestMapping
(
"/spring-kafka-case"
)
@ResponseBody
public
String
springKafkaCase
()
{
try
{
kafkaTemplate
.
send
(
topicName
,
"key"
,
"helloWorld"
).
get
();
kafkaTemplate
.
flush
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
try
{
latch
.
await
(
2
,
TimeUnit
.
SECONDS
);
}
catch
(
InterruptedException
e
)
{
}
public
String
springKafkaCase
()
throws
Exception
{
kafkaTemplate
.
send
(
topicName
,
"key"
,
helloWorld
).
get
();
latch
.
await
();
kafkaTemplate
.
flush
();
return
SUCCESS
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录