Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
月轩居士
SkyWalking
提交
41bb3b5c
S
SkyWalking
项目概览
月轩居士
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
4
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,体验更适合开发者的 AI 搜索 >>
提交
41bb3b5c
编写于
11月 14, 2019
作者:
D
Daming
提交者:
wu-sheng
11月 14, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[hotfix] Make socketio-plugin test case stable (#3861)
* make socketio-plugin testcase stable
上级
db0b7486
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
49 addition
and
87 deletion
+49
-87
test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/CaseServlet.java
...e/skywalking/apm/testcase/netty/socketio/CaseServlet.java
+32
-6
test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/ContextListener.java
...ywalking/apm/testcase/netty/socketio/ContextListener.java
+0
-45
test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/HealthCheckServlet.java
...lking/apm/testcase/netty/socketio/HealthCheckServlet.java
+3
-3
test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/SocketIOStarter.java
...ywalking/apm/testcase/netty/socketio/SocketIOStarter.java
+14
-33
未找到文件。
test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/CaseServlet.java
浏览文件 @
41bb3b5c
...
@@ -18,7 +18,9 @@
...
@@ -18,7 +18,9 @@
package
org.apache.skywalking.apm.testcase.netty.socketio
;
package
org.apache.skywalking.apm.testcase.netty.socketio
;
import
com.corundumstudio.socketio.SocketIOClient
;
import
io.socket.client.IO
;
import
io.socket.client.Socket
;
import
io.socket.emitter.Emitter
;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServlet
;
import
javax.servlet.http.HttpServlet
;
...
@@ -26,6 +28,8 @@ import javax.servlet.http.HttpServletRequest;
...
@@ -26,6 +28,8 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.io.PrintWriter
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.TimeUnit
;
public
class
CaseServlet
extends
HttpServlet
{
public
class
CaseServlet
extends
HttpServlet
{
...
@@ -33,13 +37,35 @@ public class CaseServlet extends HttpServlet {
...
@@ -33,13 +37,35 @@ public class CaseServlet extends HttpServlet {
protected
void
doGet
(
HttpServletRequest
req
,
HttpServletResponse
resp
)
throws
ServletException
,
IOException
{
protected
void
doGet
(
HttpServletRequest
req
,
HttpServletResponse
resp
)
throws
ServletException
,
IOException
{
// create socket io client and send data
// create socket io client and send data
// test send message interceptor
// test send message interceptor
SocketIOClient
client
=
SocketIOStarter
.
server
.
getAllClients
().
iterator
().
next
();
try
{
client
.
sendEvent
(
SocketIOStarter
.
SEND_EVENT_NAME
,
"data"
);
Socket
socket
=
null
;
try
{
// client send message to server
// test for get message from client interceptor
SocketIOStarter
.
getInstance
().
sendEvent
(
"data"
);
// client send message to server
socket
=
IO
.
socket
(
"http://localhost:"
+
SocketIOStarter
.
SERVER_PORT
);
// test for get message from client interceptor
final
CountDownLatch
latch
=
new
CountDownLatch
(
1
);
SocketIOStarter
.
client
.
emit
(
SocketIOStarter
.
LISTEN_EVENT_NAME
,
"hello"
);
socket
.
on
(
Socket
.
EVENT_CONNECT
,
new
Emitter
.
Listener
()
{
@Override
public
void
call
(
Object
...
objects
)
{
latch
.
countDown
();
}
});
socket
.
connect
();
socket
.
emit
(
SocketIOStarter
.
LISTEN_EVENT_NAME
,
"hello"
);
latch
.
await
(
5
,
TimeUnit
.
SECONDS
);
}
catch
(
Exception
e
)
{
throw
e
;
}
finally
{
if
(
socket
!=
null
)
{
socket
.
disconnect
();
}
}
}
catch
(
Exception
e
)
{
throw
new
IOException
(
e
);
}
PrintWriter
printWriter
=
resp
.
getWriter
();
PrintWriter
printWriter
=
resp
.
getWriter
();
printWriter
.
write
(
"success"
);
printWriter
.
write
(
"success"
);
printWriter
.
flush
();
printWriter
.
flush
();
...
...
test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/ContextListener.java
已删除
100644 → 0
浏览文件 @
db0b7486
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org.apache.skywalking.apm.testcase.netty.socketio
;
import
javax.servlet.ServletContextEvent
;
import
javax.servlet.ServletContextListener
;
/**
* @author MrPro
*/
public
class
ContextListener
implements
ServletContextListener
{
@Override
public
void
contextInitialized
(
ServletContextEvent
servletContextEvent
)
{
// start socket io server on tomcat start
SocketIOStarter
.
startServer
();
// start client
try
{
SocketIOStarter
.
startClientAndWaitConnect
();
}
catch
(
Exception
e
)
{
}
}
@Override
public
void
contextDestroyed
(
ServletContextEvent
servletContextEvent
)
{
SocketIOStarter
.
server
.
stop
();
}
}
test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/HealthCheckServlet.java
浏览文件 @
41bb3b5c
...
@@ -29,10 +29,10 @@ public class HealthCheckServlet extends HttpServlet {
...
@@ -29,10 +29,10 @@ public class HealthCheckServlet extends HttpServlet {
@Override
@Override
protected
void
doGet
(
HttpServletRequest
req
,
HttpServletResponse
resp
)
throws
ServletException
,
IOException
{
protected
void
doGet
(
HttpServletRequest
req
,
HttpServletResponse
resp
)
throws
ServletException
,
IOException
{
// start socket io server and client on heath check
// start socket io server and client on heath check
SocketIOStarter
.
startServer
();
try
{
try
{
SocketIOStarter
.
startClientAndWaitConnect
();
SocketIOStarter
.
getInstance
().
healthCheck
();
}
catch
(
Exception
e
)
{
}
catch
(
InterruptedException
e
)
{
throw
new
IOException
(
e
);
}
}
PrintWriter
writer
=
resp
.
getWriter
();
PrintWriter
writer
=
resp
.
getWriter
();
...
...
test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/SocketIOStarter.java
浏览文件 @
41bb3b5c
...
@@ -19,13 +19,8 @@ package org.apache.skywalking.apm.testcase.netty.socketio;
...
@@ -19,13 +19,8 @@ package org.apache.skywalking.apm.testcase.netty.socketio;
import
com.corundumstudio.socketio.Configuration
;
import
com.corundumstudio.socketio.Configuration
;
import
com.corundumstudio.socketio.SocketIOServer
;
import
com.corundumstudio.socketio.SocketIOServer
;
import
io.socket.client.IO
;
import
io.netty.util.concurrent.Future
;
import
io.socket.client.Socket
;
import
io.socket.emitter.Emitter
;
import
java.net.URISyntaxException
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
/**
/**
...
@@ -37,15 +32,15 @@ public class SocketIOStarter {
...
@@ -37,15 +32,15 @@ public class SocketIOStarter {
public
static
final
String
LISTEN_EVENT_NAME
=
"send_data"
;
public
static
final
String
LISTEN_EVENT_NAME
=
"send_data"
;
public
static
final
String
SEND_EVENT_NAME
=
"get_data"
;
public
static
final
String
SEND_EVENT_NAME
=
"get_data"
;
public
static
SocketIOServer
server
;
private
SocketIOServer
server
;
public
static
Socket
client
;
private
Future
<
Void
>
startFuture
;
private
static
final
SocketIOStarter
INSTANCE
=
new
SocketIOStarter
();
private
static
CountDownLatch
connectedCountDownLatch
=
new
CountDownLatch
(
1
);
public
static
final
SocketIOStarter
getInstance
()
{
return
INSTANCE
;
}
public
static
void
startServer
()
{
public
SocketIOStarter
()
{
if
(
server
!=
null
)
{
return
;
}
Configuration
config
=
new
Configuration
();
Configuration
config
=
new
Configuration
();
config
.
setHostname
(
"localhost"
);
config
.
setHostname
(
"localhost"
);
config
.
setPort
(
SERVER_PORT
);
config
.
setPort
(
SERVER_PORT
);
...
@@ -53,29 +48,15 @@ public class SocketIOStarter {
...
@@ -53,29 +48,15 @@ public class SocketIOStarter {
config
.
setWorkerThreads
(
1
);
config
.
setWorkerThreads
(
1
);
server
=
new
SocketIOServer
(
config
);
server
=
new
SocketIOServer
(
config
);
startFuture
=
server
.
startAsync
();
server
.
start
();
}
}
public
static
void
startClientAndWaitConnect
()
throws
URISyntaxException
,
InterruptedException
{
public
boolean
healthCheck
()
throws
InterruptedException
{
if
(
client
!=
null
)
{
return
startFuture
.
await
(
1L
,
TimeUnit
.
SECONDS
);
// check client is connected again
}
// if this method invoke on multi thread, client will return but not connected
connectedCountDownLatch
.
await
(
5
,
TimeUnit
.
SECONDS
);
return
;
}
client
=
IO
.
socket
(
"http://localhost:"
+
SERVER_PORT
);
LinkedBlockingQueue
<
Boolean
>
connected
=
new
LinkedBlockingQueue
<>(
1
);
client
.
on
(
Socket
.
EVENT_CONNECT
,
new
Emitter
.
Listener
()
{
@Override
public
void
call
(
Object
...
objects
)
{
connectedCountDownLatch
.
countDown
();
}
});
client
.
connect
();
// wait connect to server
public
void
sendEvent
(
String
message
)
{
connectedCountDownLatch
.
await
(
5
,
TimeUnit
.
SECONDS
);
server
.
getAllClients
().
forEach
(
e
->
e
.
sendEvent
(
SEND_EVENT_NAME
,
message
)
);
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录