fix deficient code, "/socket.io/" http segment declare (#3717)
* fix deficient code, "/socket.io/" http segment declare * add agent test and fix expectedData.yaml file * add listener on tomcat start, work for reduce socket io server start time change "/socket.io/" operation "http.method", cause get or post will invoke both * resolve style check error * change socket io server and client start to health check servlet * if startClientAndWaitConnect invoke on multi-thread, it will only check client ref, no check connect state, fix it.
This commit is contained in:
parent
f44b09483b
commit
7ebb3107bf
|
|
@ -104,6 +104,12 @@ pipeline {
|
|||
sh 'bash test/plugin/run.sh --build_id=wl1_${BUILD_ID} spring-async-scenario'
|
||||
}
|
||||
}
|
||||
|
||||
stage('netty-socketio 1.x (4)') {
|
||||
steps {
|
||||
sh 'bash test/plugin/run.sh --build_id=wl1_${BUILD_ID} netty-socketio-scenario'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Group2') {
|
||||
|
|
|
|||
|
|
@ -27,23 +27,6 @@ segmentItems:
|
|||
- applicationCode: netty-socketio-scenario
|
||||
segmentSize: ge 5
|
||||
segments:
|
||||
- segmentId: not null
|
||||
spans:
|
||||
- operationName: SocketIO/onConnect
|
||||
operationId: 0
|
||||
parentSpanId: -1
|
||||
spanId: 0
|
||||
spanLayer: Http
|
||||
startTime: nq 0
|
||||
endTime: nq 0
|
||||
componentId: 76
|
||||
componentName: ''
|
||||
isError: false
|
||||
spanType: Entry
|
||||
peer: ''
|
||||
peerId: 0
|
||||
tags:
|
||||
- {key: from, value: not null}
|
||||
- segmentId: not null
|
||||
spans:
|
||||
- operationName: /netty-socketio-scenario/case/netty-socketio
|
||||
|
|
@ -62,6 +45,23 @@ segmentItems:
|
|||
tags:
|
||||
- {key: url, value: 'http://localhost:8080/netty-socketio-scenario/case/netty-socketio'}
|
||||
- {key: http.method, value: GET}
|
||||
- segmentId: not null
|
||||
spans:
|
||||
- operationName: SocketIO/onConnect
|
||||
operationId: 0
|
||||
parentSpanId: -1
|
||||
spanId: 0
|
||||
spanLayer: Http
|
||||
startTime: nq 0
|
||||
endTime: nq 0
|
||||
componentId: 76
|
||||
componentName: ''
|
||||
isError: false
|
||||
spanType: Entry
|
||||
peer: ''
|
||||
peerId: 0
|
||||
tags:
|
||||
- {key: from, value: not null}
|
||||
- segmentId: not null
|
||||
spans:
|
||||
- operationName: SocketIO/send_data/receive
|
||||
|
|
@ -77,3 +77,21 @@ segmentItems:
|
|||
spanType: Entry
|
||||
peer: ''
|
||||
peerId: 0
|
||||
- segmentId: not null
|
||||
spans:
|
||||
- operationName: /socket.io/
|
||||
operationId: 0
|
||||
parentSpanId: -1
|
||||
spanId: 0
|
||||
spanLayer: Http
|
||||
startTime: nq 0
|
||||
endTime: nq 0
|
||||
componentId: 12
|
||||
componentName: ''
|
||||
isError: false
|
||||
spanType: Exit
|
||||
peer: not null
|
||||
peerId: 0
|
||||
tags:
|
||||
- {key: http.method, value: not null}
|
||||
- {key: url, value: not null}
|
||||
|
|
@ -29,17 +29,6 @@ import java.io.PrintWriter;
|
|||
|
||||
public class CaseServlet extends HttpServlet {
|
||||
|
||||
static {
|
||||
// start socket io server
|
||||
SocketIOStarter.startServer();
|
||||
|
||||
// start client
|
||||
try {
|
||||
SocketIOStarter.startClientAndWaitConnect();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
// create socket io client and send data
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
|
|
@ -28,6 +28,13 @@ public class HealthCheckServlet extends HttpServlet {
|
|||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
// start socket io server and client on heath check
|
||||
SocketIOStarter.startServer();
|
||||
try {
|
||||
SocketIOStarter.startClientAndWaitConnect();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
PrintWriter writer = resp.getWriter();
|
||||
writer.write("Success");
|
||||
writer.flush();
|
||||
|
|
|
|||
|
|
@ -17,17 +17,14 @@
|
|||
|
||||
package org.apache.skywalking.apm.testcase.netty.socketio;
|
||||
|
||||
import com.corundumstudio.socketio.AckRequest;
|
||||
import com.corundumstudio.socketio.Configuration;
|
||||
import com.corundumstudio.socketio.SocketIOClient;
|
||||
import com.corundumstudio.socketio.SocketIOServer;
|
||||
import com.corundumstudio.socketio.listener.ConnectListener;
|
||||
import com.corundumstudio.socketio.listener.DataListener;
|
||||
import io.socket.client.IO;
|
||||
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;
|
||||
|
||||
|
|
@ -43,53 +40,42 @@ public class SocketIOStarter {
|
|||
public static SocketIOServer server;
|
||||
public static Socket client;
|
||||
|
||||
private static CountDownLatch connectedCountDownLatch = new CountDownLatch(1);
|
||||
|
||||
public static void startServer() {
|
||||
if (server != null) {
|
||||
return;
|
||||
}
|
||||
Configuration config = new Configuration();
|
||||
config.setHostname("localhost");
|
||||
config.setPort(SERVER_PORT);
|
||||
config.setBossThreads(1);
|
||||
config.setWorkerThreads(1);
|
||||
|
||||
server = new SocketIOServer(config);
|
||||
server.addEventListener(LISTEN_EVENT_NAME, String.class, new DataListener<String>() {
|
||||
@Override
|
||||
public void onData(SocketIOClient client, String data, AckRequest ackRequest) {
|
||||
// get message
|
||||
}
|
||||
});
|
||||
|
||||
server.addConnectListener(new ConnectClientListener());
|
||||
|
||||
server.start();
|
||||
|
||||
// close server on kill signal
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
server.stop();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static class ConnectClientListener implements ConnectListener {
|
||||
|
||||
@Override
|
||||
public void onConnect(SocketIOClient client) {
|
||||
// connect client
|
||||
}
|
||||
}
|
||||
|
||||
public static void startClientAndWaitConnect() throws URISyntaxException, InterruptedException {
|
||||
if (client != null) {
|
||||
// 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) {
|
||||
connected.add(true);
|
||||
connectedCountDownLatch.countDown();
|
||||
}
|
||||
});
|
||||
client.connect();
|
||||
|
||||
// wait connect to server
|
||||
connected.poll(5, TimeUnit.SECONDS);
|
||||
connectedCountDownLatch.await(5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,5 +41,4 @@
|
|||
</servlet-mapping>
|
||||
|
||||
|
||||
|
||||
</web-app>
|
||||
|
|
|
|||
Loading…
Reference in New Issue