diff --git a/Jenkinsfile-Agent-Test b/Jenkinsfile-Agent-Test index cb62f10a3f23d6796bc5cf683e027e8bcdf03412..cc9093cf4791a06b0da64a58fc0fd8404ac2f367 100755 --- a/Jenkinsfile-Agent-Test +++ b/Jenkinsfile-Agent-Test @@ -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') { diff --git a/test/plugin/scenarios/netty-socketio-scenario/config/expectedData.yaml b/test/plugin/scenarios/netty-socketio-scenario/config/expectedData.yaml index 5f328fd846bd4188b7fade48d346ba10cd066352..e8ea27c327c0cf92f5c240a26f334192d152d3de 100644 --- a/test/plugin/scenarios/netty-socketio-scenario/config/expectedData.yaml +++ b/test/plugin/scenarios/netty-socketio-scenario/config/expectedData.yaml @@ -29,39 +29,39 @@ segmentItems: segments: - segmentId: not null spans: - - operationName: SocketIO/onConnect + - operationName: /netty-socketio-scenario/case/netty-socketio operationId: 0 parentSpanId: -1 spanId: 0 spanLayer: Http startTime: nq 0 endTime: nq 0 - componentId: 76 + componentId: 1 componentName: '' isError: false spanType: Entry peer: '' peerId: 0 tags: - - {key: from, value: not null} + - {key: url, value: 'http://localhost:8080/netty-socketio-scenario/case/netty-socketio'} + - {key: http.method, value: GET} - segmentId: not null spans: - - operationName: /netty-socketio-scenario/case/netty-socketio + - operationName: SocketIO/onConnect operationId: 0 parentSpanId: -1 spanId: 0 spanLayer: Http startTime: nq 0 endTime: nq 0 - componentId: 1 + componentId: 76 componentName: '' isError: false spanType: Entry peer: '' peerId: 0 tags: - - {key: url, value: 'http://localhost:8080/netty-socketio-scenario/case/netty-socketio'} - - {key: http.method, value: GET} + - {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} \ No newline at end of file diff --git a/test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/CaseServlet.java b/test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/CaseServlet.java index 6ad02af9cf5650c9a1b74ee450dd6c77fbae3466..33cfab91c63ea028a9771a64b73ef362c252b7df 100644 --- a/test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/CaseServlet.java +++ b/test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/CaseServlet.java @@ -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 diff --git a/test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/ContextListener.java b/test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/ContextListener.java new file mode 100644 index 0000000000000000000000000000000000000000..5c99e635fccd7d050f278e814aeb4118d79b60a1 --- /dev/null +++ b/test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/ContextListener.java @@ -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(); + } +} diff --git a/test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/HealthCheckServlet.java b/test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/HealthCheckServlet.java index ac81af30d4534b45f325f00050ec4b6caf6ebc55..ad4a73c7ca871ecf1a9054002fb5c0dc8b430e9f 100644 --- a/test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/HealthCheckServlet.java +++ b/test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/HealthCheckServlet.java @@ -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(); diff --git a/test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/SocketIOStarter.java b/test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/SocketIOStarter.java index 1c26fa8d78edb9fa7d613a6ca372f95a24ead5a9..ff2b266cb3c8fc8bbf44dde538fef5de1463f052 100644 --- a/test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/SocketIOStarter.java +++ b/test/plugin/scenarios/netty-socketio-scenario/src/main/java/org/apache/skywalking/apm/testcase/netty/socketio/SocketIOStarter.java @@ -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() { - @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 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); } } diff --git a/test/plugin/scenarios/netty-socketio-scenario/src/main/webapp/WEB-INF/web.xml b/test/plugin/scenarios/netty-socketio-scenario/src/main/webapp/WEB-INF/web.xml index 655eb656551b33b5dd820e5aab446493ba7b41f1..d790f441a464fce85350cf6acb9a0360e5210f11 100644 --- a/test/plugin/scenarios/netty-socketio-scenario/src/main/webapp/WEB-INF/web.xml +++ b/test/plugin/scenarios/netty-socketio-scenario/src/main/webapp/WEB-INF/web.xml @@ -41,5 +41,4 @@ -