You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2018/08/01 07:39:03 UTC

[GitHub] liubao68 closed pull request #824: [SCB-687] add highway server connection protection

liubao68 closed pull request #824: [SCB-687] add highway server connection protection
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/824
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/integration-tests/spring-pojo-tests/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoSpringMain.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/ClientClosedEvent.java
similarity index 60%
rename from integration-tests/spring-pojo-tests/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoSpringMain.java
rename to foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/ClientClosedEvent.java
index a81656cac..68fa037a4 100644
--- a/integration-tests/spring-pojo-tests/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoSpringMain.java
+++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/ClientClosedEvent.java
@@ -15,17 +15,26 @@
  * limitations under the License.
  */
 
-package org.apache.servicecomb.demo.pojo.test;
+package org.apache.servicecomb.foundation.vertx;
 
-import org.apache.servicecomb.springboot.starter.provider.EnableServiceComb;
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
+/**
+ * Notice: this event will raised in vertx eventloop thread, so do not run any block code
+ */
+public class ClientClosedEvent {
+  private final String address;
+
+  private final int totalConnectedCount;
 
-@SpringBootApplication
-@EnableServiceComb
-public class PojoSpringMain {
+  public String getAddress() {
+    return address;
+  }
+
+  public int getTotalConnectedCount() {
+    return totalConnectedCount;
+  }
 
-  public static void main(final String[] args) throws Exception {
-    SpringApplication.run(PojoSpringMain.class, args);
+  public ClientClosedEvent(String address, int totalConnectedCount) {
+    this.address = address;
+    this.totalConnectedCount = totalConnectedCount;
   }
-}
+}
\ No newline at end of file
diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/ClientConnectedEvent.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/ClientConnectedEvent.java
new file mode 100644
index 000000000..09e752e8e
--- /dev/null
+++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/ClientConnectedEvent.java
@@ -0,0 +1,42 @@
+/*
+ * 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.servicecomb.foundation.vertx;
+
+import io.vertx.core.net.NetSocket;
+
+/**
+ * Notice: this event will raised in vertx eventloop thread, so do not run any block code
+ */
+public class ClientConnectedEvent {
+  private final NetSocket netSocket;
+
+  private final int totalConnectedCount;
+
+  public NetSocket getNetSocket() {
+    return netSocket;
+  }
+
+  public int getTotalConnectedCount() {
+    return totalConnectedCount;
+  }
+
+  public ClientConnectedEvent(NetSocket netSocket, int totalConnectedCount) {
+    this.netSocket = netSocket;
+    this.totalConnectedCount = totalConnectedCount;
+  }
+}
\ No newline at end of file
diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/server/TcpServer.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/server/TcpServer.java
index a4fd6902e..a2db20637 100644
--- a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/server/TcpServer.java
+++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/server/TcpServer.java
@@ -18,14 +18,19 @@
 package org.apache.servicecomb.foundation.vertx.server;
 
 import java.net.InetSocketAddress;
+import java.util.concurrent.atomic.AtomicInteger;
 
+import org.apache.servicecomb.foundation.common.event.EventManager;
 import org.apache.servicecomb.foundation.common.net.URIEndpointObject;
 import org.apache.servicecomb.foundation.ssl.SSLCustom;
 import org.apache.servicecomb.foundation.ssl.SSLOption;
 import org.apache.servicecomb.foundation.ssl.SSLOptionFactory;
 import org.apache.servicecomb.foundation.vertx.AsyncResultCallback;
+import org.apache.servicecomb.foundation.vertx.ClientConnectedEvent;
 import org.apache.servicecomb.foundation.vertx.VertxTLSBuilder;
 
+import com.netflix.config.DynamicPropertyFactory;
+
 import io.vertx.core.Vertx;
 import io.vertx.core.net.NetServer;
 import io.vertx.core.net.NetServerOptions;
@@ -33,8 +38,11 @@
 public class TcpServer {
   private URIEndpointObject endpointObject;
 
-  public TcpServer(URIEndpointObject endpointObject) {
+  private final AtomicInteger connectedCounter;
+
+  public TcpServer(URIEndpointObject endpointObject, AtomicInteger connectedCounter) {
     this.endpointObject = endpointObject;
+    this.connectedCounter = connectedCounter;
   }
 
   public void init(Vertx vertx, String sslKey, AsyncResultCallback<InetSocketAddress> callback) {
@@ -57,8 +65,18 @@ public void init(Vertx vertx, String sslKey, AsyncResultCallback<InetSocketAddre
     }
 
     netServer.connectHandler(netSocket -> {
+      int connectedCount = connectedCounter.incrementAndGet();
+      int connectionLimit = DynamicPropertyFactory.getInstance()
+          .getIntProperty("servicecomb.highway.server.connection-limit", Integer.MAX_VALUE).get();
+      if (connectedCount > connectionLimit) {
+        connectedCounter.decrementAndGet();
+        netSocket.close();
+        return;
+      }
+
       TcpServerConnection connection = createTcpServerConnection();
-      connection.init(netSocket);
+      connection.init(netSocket, connectedCounter);
+      EventManager.post(new ClientConnectedEvent(netSocket, connectedCount));
     });
 
     InetSocketAddress socketAddress = endpointObject.getSocketAddress();
diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/server/TcpServerConnection.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/server/TcpServerConnection.java
index 348a3f843..5c47100ee 100644
--- a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/server/TcpServerConnection.java
+++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/server/TcpServerConnection.java
@@ -16,6 +16,10 @@
  */
 package org.apache.servicecomb.foundation.vertx.server;
 
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.servicecomb.foundation.common.event.EventManager;
+import org.apache.servicecomb.foundation.vertx.ClientClosedEvent;
 import org.apache.servicecomb.foundation.vertx.tcp.TcpConnection;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -28,7 +32,7 @@
 
   protected TcpParser splitter;
 
-  public void init(NetSocket netSocket) {
+  public void init(NetSocket netSocket, AtomicInteger connectedCounter) {
     // currently, socket always be NetSocketImpl
     this.initNetSocket((NetSocketImpl) netSocket);
 
@@ -46,6 +50,9 @@ public void init(NetSocket netSocket) {
       LOGGER.error("disconected from {}, in thread {}",
           remoteAddress,
           Thread.currentThread().getName());
+
+      int connectedCount = connectedCounter.decrementAndGet();
+      EventManager.post(new ClientClosedEvent(remoteAddress, connectedCount));
     });
 
     netSocket.handler(splitter);
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/server/TestTcpServer.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/server/TestTcpServer.java
index 403b73105..59825f5c9 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/server/TestTcpServer.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/server/TestTcpServer.java
@@ -18,6 +18,7 @@
 package org.apache.servicecomb.foundation.vertx.server;
 
 import java.net.InetSocketAddress;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.servicecomb.foundation.common.net.URIEndpointObject;
 import org.apache.servicecomb.foundation.vertx.AsyncResultCallback;
@@ -34,15 +35,15 @@
 public class TestTcpServer {
   static class TcpServerForTest extends TcpServer {
     public TcpServerForTest(URIEndpointObject endpointObject) {
-      super(endpointObject);
+      super(endpointObject, new AtomicInteger());
     }
 
     @Override
     protected TcpServerConnection createTcpServerConnection() {
       return new TcpServerConnection() {
         @Override
-        public void init(NetSocket netSocket) {
-          super.init(netSocket);
+        public void init(NetSocket netSocket, AtomicInteger connectedCounter) {
+          super.init(netSocket, connectedCounter);
         }
       };
     }
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/server/TestTcpServerConnection.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/server/TestTcpServerConnection.java
index 3047042f2..08b39780b 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/server/TestTcpServerConnection.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/server/TestTcpServerConnection.java
@@ -16,6 +16,8 @@
  */
 package org.apache.servicecomb.foundation.vertx.server;
 
+import java.util.concurrent.atomic.AtomicInteger;
+
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -29,7 +31,7 @@ public void test(@Mocked NetSocketImpl netSocket) {
     connection.setProtocol("p");
     connection.setZipName("z");
 
-    connection.init(netSocket);
+    connection.init(netSocket, new AtomicInteger());
 
     Assert.assertEquals(netSocket, connection.getNetSocket());
   }
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index 7a244ed8b..d7ceba424 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -41,6 +41,7 @@
     <module>spring-zuul-tracing-tests</module>
     <module>spring-pojo-tests</module>
     <module>dynamic-config-tests</module>
+    <module>spring-pojo-connection-limit-test</module>
   </modules>
 
   <dependencyManagement>
diff --git a/integration-tests/spring-pojo-connection-limit-test/pom.xml b/integration-tests/spring-pojo-connection-limit-test/pom.xml
new file mode 100644
index 000000000..b770bc26e
--- /dev/null
+++ b/integration-tests/spring-pojo-connection-limit-test/pom.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <parent>
+    <artifactId>integration-tests</artifactId>
+    <groupId>org.apache.servicecomb.tests</groupId>
+    <version>1.1.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>spring-pojo-connection-limit-test</artifactId>
+  <name>Java Chassis::Integration Tests::Spring POJO Connection Limit</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.servicecomb.tests</groupId>
+      <artifactId>pojo-test</artifactId>
+      <version>1.1.0-SNAPSHOT</version>
+      <type>test-jar</type>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.servicecomb.demo</groupId>
+          <artifactId>demo-signature</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-test</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-test</artifactId>
+    </dependency>
+  </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/integration-tests/spring-pojo-connection-limit-test/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoSpringConnectionLimitIntegrationTest.java b/integration-tests/spring-pojo-connection-limit-test/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoSpringConnectionLimitIntegrationTest.java
new file mode 100644
index 000000000..8c6d58688
--- /dev/null
+++ b/integration-tests/spring-pojo-connection-limit-test/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoSpringConnectionLimitIntegrationTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.servicecomb.demo.pojo.test;
+
+import static org.apache.servicecomb.serviceregistry.client.LocalServiceRegistryClientImpl.LOCAL_REGISTRY_FILE_KEY;
+import static org.junit.Assert.fail;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+public class PojoSpringConnectionLimitIntegrationTest {
+  @BeforeClass
+  public static void setUpClass() throws Exception {
+    System.setProperty(LOCAL_REGISTRY_FILE_KEY, "notExistJustForceLocal");
+    PojoTestMain.main(null);
+  }
+
+  @Test
+  public void remoteHelloPojo_sayHello() {
+    try {
+      PojoService.hello.SayHello("whatever");
+      fail("connection limit failed");
+    } catch (Exception e) {
+      Assert.assertEquals("java.io.IOException: socket closed", e.getCause().toString());
+    }
+  }
+}
\ No newline at end of file
diff --git a/integration-tests/spring-pojo-connection-limit-test/src/test/resources/log4j.properties b/integration-tests/spring-pojo-connection-limit-test/src/test/resources/log4j.properties
new file mode 100644
index 000000000..8cc015c91
--- /dev/null
+++ b/integration-tests/spring-pojo-connection-limit-test/src/test/resources/log4j.properties
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+log4j.rootLogger=WARN, stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
\ No newline at end of file
diff --git a/integration-tests/spring-pojo-connection-limit-test/src/test/resources/microservice.yaml b/integration-tests/spring-pojo-connection-limit-test/src/test/resources/microservice.yaml
new file mode 100644
index 000000000..d1333f0c1
--- /dev/null
+++ b/integration-tests/spring-pojo-connection-limit-test/src/test/resources/microservice.yaml
@@ -0,0 +1,29 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+APPLICATION_ID: pojotest-it
+service_description:
+  name: pojo
+  version: 0.0.4
+servicecomb:
+  service:
+    registry:
+      address: http://127.0.0.1:30100
+  highway:
+    address: 0.0.0.0:7070
+    server:
+      connection-limit: 0
\ No newline at end of file
diff --git a/integration-tests/spring-pojo-tests/pom.xml b/integration-tests/spring-pojo-tests/pom.xml
index 98e1fb324..f3155027d 100644
--- a/integration-tests/spring-pojo-tests/pom.xml
+++ b/integration-tests/spring-pojo-tests/pom.xml
@@ -42,14 +42,6 @@
         </exclusion>
       </exclusions>
     </dependency>
-    <dependency>
-      <groupId>org.springframework.boot</groupId>
-      <artifactId>spring-boot-autoconfigure</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.servicecomb</groupId>
-      <artifactId>spring-boot-starter-provider</artifactId>
-    </dependency>
     <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-test</artifactId>
@@ -58,11 +50,6 @@
       <groupId>org.springframework</groupId>
       <artifactId>spring-test</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.hibernate</groupId>
-      <artifactId>hibernate-validator</artifactId>
-    </dependency>
-
   </dependencies>
 
 
diff --git a/integration-tests/spring-pojo-tests/src/test/java/org/apache/servicecomb/demo/pojo/test/ConnectionEventWatcher.java b/integration-tests/spring-pojo-tests/src/test/java/org/apache/servicecomb/demo/pojo/test/ConnectionEventWatcher.java
new file mode 100644
index 000000000..68e58ccf0
--- /dev/null
+++ b/integration-tests/spring-pojo-tests/src/test/java/org/apache/servicecomb/demo/pojo/test/ConnectionEventWatcher.java
@@ -0,0 +1,44 @@
+/*
+ * 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.servicecomb.demo.pojo.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.servicecomb.foundation.vertx.ClientClosedEvent;
+import org.apache.servicecomb.foundation.vertx.ClientConnectedEvent;
+
+import com.google.common.eventbus.Subscribe;
+
+public class ConnectionEventWatcher {
+  private final List<Integer> counters = new ArrayList<>();
+
+  public List<Integer> getCounters() {
+    return counters;
+  }
+
+  @Subscribe
+  public void onConnected(ClientConnectedEvent event) {
+    counters.add(event.getTotalConnectedCount());
+  }
+
+  @Subscribe
+  public void onClosed(ClientClosedEvent event) {
+    counters.add(event.getTotalConnectedCount());
+  }
+}
diff --git a/integration-tests/spring-pojo-tests/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoSpringIntegrationTest.java b/integration-tests/spring-pojo-tests/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoSpringIntegrationTest.java
index 29f1c97c7..bcd56e73a 100644
--- a/integration-tests/spring-pojo-tests/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoSpringIntegrationTest.java
+++ b/integration-tests/spring-pojo-tests/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoSpringIntegrationTest.java
@@ -17,17 +17,29 @@
 
 package org.apache.servicecomb.demo.pojo.test;
 
+import org.apache.servicecomb.core.SCBEngine;
+import org.apache.servicecomb.foundation.common.event.EventManager;
+import org.junit.AfterClass;
+import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.runner.RunWith;
-import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
 @RunWith(SpringRunner.class)
-@SpringBootTest(classes = PojoSpringMain.class)
 public class PojoSpringIntegrationTest extends PojoIntegrationTestBase {
 
+  private static final ConnectionEventWatcher watcher = new ConnectionEventWatcher();
+
   @BeforeClass
-  public static void setUpClass() {
+  public static void setUpClass() throws Exception {
     setUpLocalRegistry();
+    EventManager.register(watcher);
+    PojoTestMain.main(null);
+  }
+
+  @AfterClass
+  public static void teardownClass() {
+    SCBEngine.getInstance().destroy();
+    Assert.assertArrayEquals("check connection count change", new Integer[] {1, 0}, watcher.getCounters().toArray());
   }
 }
diff --git a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServer.java b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServer.java
index 5aca854b7..0694c2de3 100644
--- a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServer.java
+++ b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServer.java
@@ -17,6 +17,8 @@
 
 package org.apache.servicecomb.transport.highway;
 
+import java.util.concurrent.atomic.AtomicInteger;
+
 import org.apache.servicecomb.core.Endpoint;
 import org.apache.servicecomb.foundation.common.net.URIEndpointObject;
 import org.apache.servicecomb.foundation.vertx.server.TcpServer;
@@ -25,8 +27,8 @@
 public class HighwayServer extends TcpServer {
   private Endpoint endpoint;
 
-  public HighwayServer(Endpoint endpoint) {
-    super((URIEndpointObject) endpoint.getAddress());
+  public HighwayServer(Endpoint endpoint, AtomicInteger connectedCounter) {
+    super((URIEndpointObject) endpoint.getAddress(), connectedCounter);
     this.endpoint = endpoint;
   }
 
diff --git a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerConnection.java b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerConnection.java
index 79b5e02c6..1f5a7593b 100644
--- a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerConnection.java
+++ b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerConnection.java
@@ -16,6 +16,8 @@
  */
 package org.apache.servicecomb.transport.highway;
 
+import java.util.concurrent.atomic.AtomicInteger;
+
 import javax.ws.rs.core.Response.Status;
 
 import org.apache.servicecomb.core.Endpoint;
@@ -45,9 +47,9 @@ public HighwayServerConnection(Endpoint endpoint) {
   }
 
   @Override
-  public void init(NetSocket netSocket) {
+  public void init(NetSocket netSocket, AtomicInteger connectedCounter) {
     splitter = new TcpParser(this);
-    super.init(netSocket);
+    super.init(netSocket, connectedCounter);
   }
 
   @Override
diff --git a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerVerticle.java b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerVerticle.java
index 123f5c7c8..162c63ff5 100644
--- a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerVerticle.java
+++ b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerVerticle.java
@@ -18,10 +18,12 @@
 package org.apache.servicecomb.transport.highway;
 
 import java.net.InetSocketAddress;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.servicecomb.core.Endpoint;
 import org.apache.servicecomb.core.transport.AbstractTransport;
 import org.apache.servicecomb.foundation.common.net.URIEndpointObject;
+import org.apache.servicecomb.foundation.common.utils.BeanUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -39,6 +41,16 @@
 
   private URIEndpointObject endpointObject;
 
+  private final AtomicInteger connectedCounter;
+
+  public HighwayServerVerticle() {
+    this(((HighwayTransport) BeanUtils.getBean("highwayTransport")).getConnectedCounter());
+  }
+
+  public HighwayServerVerticle(AtomicInteger connectedCounter) {
+    this.connectedCounter = connectedCounter;
+  }
+
   @Override
   public void init(Vertx vertx, Context context) {
     super.init(vertx, context);
@@ -66,7 +78,7 @@ protected void startListen(Future<Void> startFuture) {
       return;
     }
 
-    HighwayServer server = new HighwayServer(endpoint);
+    HighwayServer server = new HighwayServer(endpoint, connectedCounter);
     server.init(vertx, SSL_KEY, ar -> {
       if (ar.succeeded()) {
         InetSocketAddress socketAddress = ar.result();
diff --git a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayTransport.java b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayTransport.java
index 195741f16..956275c71 100644
--- a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayTransport.java
+++ b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayTransport.java
@@ -18,6 +18,7 @@
 package org.apache.servicecomb.transport.highway;
 
 import java.util.Collections;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.servicecomb.core.Invocation;
 import org.apache.servicecomb.core.transport.AbstractTransport;
@@ -35,6 +36,12 @@
 
   private HighwayClient highwayClient = new HighwayClient();
 
+  private final AtomicInteger connectedCounter = new AtomicInteger(0);
+
+  public AtomicInteger getConnectedCounter() {
+    return connectedCounter;
+  }
+
   @Override
   public String getName() {
     return NAME;
diff --git a/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/TestHighwayServerConnection.java b/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/TestHighwayServerConnection.java
index e951b97a7..4f49fbc6f 100644
--- a/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/TestHighwayServerConnection.java
+++ b/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/TestHighwayServerConnection.java
@@ -17,6 +17,7 @@
 package org.apache.servicecomb.transport.highway;
 
 import java.net.InetSocketAddress;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.xml.ws.Holder;
 
@@ -75,7 +76,7 @@ public void init() {
       }
     };
     connection = new HighwayServerConnection(endpoint);
-    connection.init(netSocket);
+    connection.init(netSocket, new AtomicInteger());
 
     header = new RequestHeader();
   }
diff --git a/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/TestHighwayVerticle.java b/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/TestHighwayVerticle.java
index b0b6f7552..1aeb09248 100644
--- a/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/TestHighwayVerticle.java
+++ b/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/TestHighwayVerticle.java
@@ -17,6 +17,8 @@
 
 package org.apache.servicecomb.transport.highway;
 
+import java.util.concurrent.atomic.AtomicInteger;
+
 import org.apache.servicecomb.core.Endpoint;
 import org.apache.servicecomb.core.Transport;
 import org.apache.servicecomb.foundation.common.net.URIEndpointObject;
@@ -39,12 +41,12 @@
   private HighwayServerVerticle highwayVerticle = null;
 
   @Before
-  public void setUp() throws Exception {
-    highwayVerticle = new HighwayServerVerticle();
+  public void setUp() {
+    highwayVerticle = new HighwayServerVerticle(new AtomicInteger());
   }
 
   @After
-  public void tearDown() throws Exception {
+  public void tearDown() {
     highwayVerticle = null;
   }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services