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/07 12:48:56 UTC

[GitHub] liubao68 closed pull request #852: [SCB-688] vertx rest server not accept too many connection

liubao68 closed pull request #852: [SCB-688] vertx rest server not accept too many connection
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/852
 
 
   

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/core/src/main/java/org/apache/servicecomb/core/Const.java b/core/src/main/java/org/apache/servicecomb/core/Const.java
index 08fcf7c6a..e46cc820a 100644
--- a/core/src/main/java/org/apache/servicecomb/core/Const.java
+++ b/core/src/main/java/org/apache/servicecomb/core/Const.java
@@ -27,6 +27,8 @@ private Const() {
 
   public static final String RESTFUL = "rest";
 
+  public static final String HIGHWAY = "highway";
+
   public static final String ANY_TRANSPORT = "";
 
   public static final String VERSION_RULE_LATEST = DefinitionConst.VERSION_RULE_LATEST;
diff --git a/core/src/main/java/org/apache/servicecomb/core/Transport.java b/core/src/main/java/org/apache/servicecomb/core/Transport.java
index ed9ade43e..026ed7c4e 100644
--- a/core/src/main/java/org/apache/servicecomb/core/Transport.java
+++ b/core/src/main/java/org/apache/servicecomb/core/Transport.java
@@ -17,6 +17,8 @@
 
 package org.apache.servicecomb.core;
 
+import java.util.concurrent.atomic.AtomicInteger;
+
 import org.apache.servicecomb.swagger.invocation.AsyncResponse;
 
 // TODO:感觉要拆成显式的client、server才好些
@@ -49,4 +51,6 @@ default boolean canInit() {
   Endpoint getPublishEndpoint() throws Exception;
 
   void send(Invocation invocation, AsyncResponse asyncResp) throws Exception;
+
+  AtomicInteger getConnectedCounter();
 }
diff --git a/core/src/main/java/org/apache/servicecomb/core/transport/AbstractTransport.java b/core/src/main/java/org/apache/servicecomb/core/transport/AbstractTransport.java
index d75570ec5..ff5370afd 100644
--- a/core/src/main/java/org/apache/servicecomb/core/transport/AbstractTransport.java
+++ b/core/src/main/java/org/apache/servicecomb/core/transport/AbstractTransport.java
@@ -23,6 +23,7 @@
 import java.net.URLDecoder;
 import java.nio.charset.StandardCharsets;
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
 import org.apache.http.client.utils.URLEncodedUtils;
@@ -65,6 +66,8 @@
 
   protected Endpoint publishEndpoint;
 
+  private final AtomicInteger connectedCounter = new AtomicInteger(0);
+
   @Override
   public Endpoint getPublishEndpoint() {
     return publishEndpoint;
@@ -75,6 +78,11 @@ public Endpoint getEndpoint() {
     return endpoint;
   }
 
+  @Override
+  public AtomicInteger getConnectedCounter() {
+    return connectedCounter;
+  }
+
   protected void setListenAddressWithoutSchema(String addressWithoutSchema) {
     setListenAddressWithoutSchema(addressWithoutSchema, null);
   }
diff --git a/core/src/test/java/org/apache/servicecomb/core/TestTransport.java b/core/src/test/java/org/apache/servicecomb/core/TestTransport.java
index c1bca1f79..abfa20252 100644
--- a/core/src/test/java/org/apache/servicecomb/core/TestTransport.java
+++ b/core/src/test/java/org/apache/servicecomb/core/TestTransport.java
@@ -21,6 +21,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.servicecomb.core.endpoint.EndpointsCache;
 import org.apache.servicecomb.core.transport.TransportManager;
@@ -43,7 +44,12 @@ public void testEndpoint() throws Exception {
     Endpoint oEndpoint = new Endpoint(new Transport() {
 
       @Override
-      public void send(Invocation invocation, AsyncResponse asyncResp) throws Exception {
+      public void send(Invocation invocation, AsyncResponse asyncResp) {
+      }
+
+      @Override
+      public AtomicInteger getConnectedCounter() {
+        return new AtomicInteger(0);
       }
 
       @Override
@@ -52,7 +58,7 @@ public Object parseAddress(String address) {
       }
 
       @Override
-      public boolean init() throws Exception {
+      public boolean init() {
         return true;
       }
 
@@ -67,7 +73,7 @@ public Endpoint getEndpoint() {
       }
 
       @Override
-      public Endpoint getPublishEndpoint() throws Exception {
+      public Endpoint getPublishEndpoint() {
         return (new Endpoint(this, "testEndpoint"));
       }
     }, "rest://127.0.0.1:8080");
@@ -75,14 +81,13 @@ public Endpoint getPublishEndpoint() throws Exception {
     Assert.assertEquals("rest://127.0.0.1:8080", oEndpoint.getEndpoint());
     Assert.assertEquals("127.0.0.1", oEndpoint.getAddress());
     Assert.assertEquals("test", oEndpoint.getTransport().getName());
-    Assert.assertEquals("rest://127.0.0.1:8080", oEndpoint.getEndpoint().toString());
+    Assert.assertEquals("rest://127.0.0.1:8080", oEndpoint.getEndpoint());
   }
 
   @Test
   public void testAbstractTransport(@Mocked Microservice microservice,
       @Injectable InstanceCacheManager instanceCacheManager, @Injectable TransportManager transportManager,
-      @Mocked InstanceCache instanceCache, @Injectable MicroserviceInstance instance)
-      throws Exception {
+      @Mocked InstanceCache instanceCache, @Injectable MicroserviceInstance instance) {
     EndpointsCache.init(instanceCacheManager, transportManager);
     EndpointsCache oEndpointsCache = new EndpointsCache("app", "testname", "test", "rest");
 
diff --git a/coverage-reports/pom.xml b/coverage-reports/pom.xml
index ecbc01cf7..6a174b3ad 100644
--- a/coverage-reports/pom.xml
+++ b/coverage-reports/pom.xml
@@ -266,6 +266,31 @@
       <artifactId>jaxrs-tests</artifactId>
       <version>1.1.0-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb.tests</groupId>
+      <artifactId>pojo-test</artifactId>
+      <version>1.1.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb.tests</groupId>
+      <artifactId>spring-jaxrs-tests</artifactId>
+      <version>1.1.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb.tests</groupId>
+      <artifactId>spring-pojo-tests</artifactId>
+      <version>1.1.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb.tests</groupId>
+      <artifactId>spring-pojo-connection-limit-test</artifactId>
+      <version>1.1.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb.tests</groupId>
+      <artifactId>spring-zuul-tracing-tests</artifactId>
+      <version>1.1.0-SNAPSHOT</version>
+    </dependency>
     <dependency>
       <groupId>org.apache.servicecomb.tests</groupId>
       <artifactId>springmvc-tests-general</artifactId>
@@ -281,6 +306,11 @@
       <artifactId>springmvc-tests-simplified-mapping</artifactId>
       <version>1.1.0-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb.tests</groupId>
+      <artifactId>springmvc-tests-connection-limit</artifactId>
+      <version>1.1.0-SNAPSHOT</version>
+    </dependency>
     <dependency>
       <groupId>org.apache.servicecomb.tests</groupId>
       <artifactId>springmvc-tests-simplified-mapping-with-springboot</artifactId>
diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/ClientClosedEvent.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/ClientEvent.java
similarity index 71%
rename from foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/ClientClosedEvent.java
rename to foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/ClientEvent.java
index 68fa037a4..0b37bbfcc 100644
--- a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/ClientClosedEvent.java
+++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/ClientEvent.java
@@ -20,21 +20,36 @@
 /**
  * Notice: this event will raised in vertx eventloop thread, so do not run any block code
  */
-public class ClientClosedEvent {
+public class ClientEvent {
   private final String address;
 
+  private final ConnectionEvent connectionEvent;
+
+  private final TransportType transportType;
+
   private final int totalConnectedCount;
 
   public String getAddress() {
     return address;
   }
 
+  public ConnectionEvent getConnectionEvent() {
+    return connectionEvent;
+  }
+
+  public TransportType getTransportType() {
+    return transportType;
+  }
+
   public int getTotalConnectedCount() {
     return totalConnectedCount;
   }
 
-  public ClientClosedEvent(String address, int totalConnectedCount) {
+  public ClientEvent(String address, ConnectionEvent connectionEvent, TransportType transportType,
+      int totalConnectedCount) {
     this.address = address;
+    this.connectionEvent = connectionEvent;
+    this.transportType = transportType;
     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/ConnectionEvent.java
similarity index 60%
rename from foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/ClientConnectedEvent.java
rename to foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/ConnectionEvent.java
index 09e752e8e..359f92853 100644
--- 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/ConnectionEvent.java
@@ -17,26 +17,7 @@
 
 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
+public enum ConnectionEvent {
+  Connected,
+  Closed
+}
diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/TransportType.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/TransportType.java
new file mode 100644
index 000000000..0d8489dc0
--- /dev/null
+++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/TransportType.java
@@ -0,0 +1,23 @@
+/*
+ * 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;
+
+public enum TransportType {
+  Highway,
+  Rest
+}
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 a2db20637..7fc3f24f4 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
@@ -26,7 +26,9 @@
 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.ClientEvent;
+import org.apache.servicecomb.foundation.vertx.ConnectionEvent;
+import org.apache.servicecomb.foundation.vertx.TransportType;
 import org.apache.servicecomb.foundation.vertx.VertxTLSBuilder;
 
 import com.netflix.config.DynamicPropertyFactory;
@@ -76,7 +78,8 @@ public void init(Vertx vertx, String sslKey, AsyncResultCallback<InetSocketAddre
 
       TcpServerConnection connection = createTcpServerConnection();
       connection.init(netSocket, connectedCounter);
-      EventManager.post(new ClientConnectedEvent(netSocket, connectedCount));
+      EventManager.post(new ClientEvent(netSocket.remoteAddress().toString(),
+          ConnectionEvent.Connected, TransportType.Highway, 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 5c47100ee..18120a477 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
@@ -19,7 +19,9 @@
 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.ClientEvent;
+import org.apache.servicecomb.foundation.vertx.ConnectionEvent;
+import org.apache.servicecomb.foundation.vertx.TransportType;
 import org.apache.servicecomb.foundation.vertx.tcp.TcpConnection;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -52,7 +54,7 @@ public void init(NetSocket netSocket, AtomicInteger connectedCounter) {
           Thread.currentThread().getName());
 
       int connectedCount = connectedCounter.decrementAndGet();
-      EventManager.post(new ClientClosedEvent(remoteAddress, connectedCount));
+      EventManager.post(new ClientEvent(remoteAddress, ConnectionEvent.Closed, TransportType.Highway, connectedCount));
     });
 
     netSocket.handler(splitter);
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
index ded64d1d1..528f9728c 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
@@ -27,7 +27,6 @@
 import org.apache.servicecomb.it.testcase.base.TestDataTypePojo;
 import org.apache.servicecomb.it.testcase.base.TestDataTypeRest;
 import org.apache.servicecomb.it.testcase.support.ProducerDevMode;
-import org.apache.servicecomb.transport.highway.HighwayTransport;
 
 
 public class ConsumerMain {
@@ -69,7 +68,7 @@ protected static void run() throws Throwable {
     //   run rest
     //   run native restTemplate to edge/zuul
     // stop standalone base-producer
-    transports = Arrays.asList(HighwayTransport.NAME, Const.RESTFUL);
+    transports = Arrays.asList(Const.HIGHWAY, Const.RESTFUL);
     testStandalone();
 
     transports = Arrays.asList(Const.RESTFUL);
diff --git a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DataTypePojo.java b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DataTypePojo.java
index 902757396..47d91e08d 100644
--- a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DataTypePojo.java
+++ b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DataTypePojo.java
@@ -21,7 +21,6 @@
 import org.apache.servicecomb.core.Const;
 import org.apache.servicecomb.provider.pojo.RpcSchema;
 import org.apache.servicecomb.provider.rest.common.InvocationToHttpServletRequest;
-import org.apache.servicecomb.transport.highway.HighwayTransport;
 
 import io.swagger.annotations.SwaggerDefinition;
 
@@ -29,8 +28,8 @@
 @SwaggerDefinition(basePath = "/v1/dataTypePojo")
 public class DataTypePojo {
   public String checkTransport(HttpServletRequest request) {
-    if (InvocationToHttpServletRequest.class.isInstance(request)) {
-      return HighwayTransport.NAME;
+    if (request instanceof InvocationToHttpServletRequest) {
+      return Const.HIGHWAY;
     }
 
     return Const.RESTFUL;
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
index 68e58ccf0..bda03c01c 100644
--- 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
@@ -20,8 +20,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.servicecomb.foundation.vertx.ClientClosedEvent;
-import org.apache.servicecomb.foundation.vertx.ClientConnectedEvent;
+import org.apache.servicecomb.foundation.vertx.ClientEvent;
+import org.apache.servicecomb.foundation.vertx.TransportType;
 
 import com.google.common.eventbus.Subscribe;
 
@@ -33,12 +33,9 @@
   }
 
   @Subscribe
-  public void onConnected(ClientConnectedEvent event) {
-    counters.add(event.getTotalConnectedCount());
-  }
-
-  @Subscribe
-  public void onClosed(ClientClosedEvent event) {
-    counters.add(event.getTotalConnectedCount());
+  public void getEvent(ClientEvent event) {
+    if (TransportType.Highway.equals(event.getTransportType())) {
+      counters.add(event.getTotalConnectedCount());
+    }
   }
 }
diff --git a/integration-tests/springmvc-tests/pom.xml b/integration-tests/springmvc-tests/pom.xml
index 732f77a8c..cd8908f1f 100644
--- a/integration-tests/springmvc-tests/pom.xml
+++ b/integration-tests/springmvc-tests/pom.xml
@@ -36,6 +36,7 @@
     <module>springmvc-tests-simplified-mapping</module>
     <module>springmvc-tests-general-with-springboot</module>
     <module>springmvc-tests-simplified-mapping-with-springboot</module>
+    <module>springmvc-tests-connection-limit</module>
   </modules>
 
   <dependencies>
diff --git a/integration-tests/springmvc-tests/springmvc-tests-common/src/test/java/org/apache/servicecomb/demo/springmvc/tests/ConnectionEventWatcher.java b/integration-tests/springmvc-tests/springmvc-tests-common/src/test/java/org/apache/servicecomb/demo/springmvc/tests/ConnectionEventWatcher.java
new file mode 100644
index 000000000..2ad819c17
--- /dev/null
+++ b/integration-tests/springmvc-tests/springmvc-tests-common/src/test/java/org/apache/servicecomb/demo/springmvc/tests/ConnectionEventWatcher.java
@@ -0,0 +1,41 @@
+/*
+ * 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.springmvc.tests;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.servicecomb.foundation.vertx.ClientEvent;
+import org.apache.servicecomb.foundation.vertx.TransportType;
+
+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 getEvent(ClientEvent event) {
+    if (TransportType.Rest.equals(event.getTransportType())) {
+      counters.add(event.getTotalConnectedCount());
+    }
+  }
+}
diff --git a/integration-tests/springmvc-tests/springmvc-tests-connection-limit/pom.xml b/integration-tests/springmvc-tests/springmvc-tests-connection-limit/pom.xml
new file mode 100644
index 000000000..a0760fd0a
--- /dev/null
+++ b/integration-tests/springmvc-tests/springmvc-tests-connection-limit/pom.xml
@@ -0,0 +1,41 @@
+<?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>springmvc-tests</artifactId>
+    <groupId>org.apache.servicecomb.tests</groupId>
+    <version>1.1.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>springmvc-tests-connection-limit</artifactId>
+  <name>Java Chassis::Integration Tests::Spring MVC Connection Limit</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.servicecomb.tests</groupId>
+      <artifactId>springmvc-tests-common</artifactId>
+      <version>1.1.0-SNAPSHOT</version>
+      <type>test-jar</type>
+    </dependency>
+  </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/integration-tests/springmvc-tests/springmvc-tests-connection-limit/src/test/java/org/apache/servicecomb/demo/springmvc/tests/RawSpringMvcIntegrationTest.java b/integration-tests/springmvc-tests/springmvc-tests-connection-limit/src/test/java/org/apache/servicecomb/demo/springmvc/tests/RawSpringMvcIntegrationTest.java
new file mode 100644
index 000000000..e4cd60dca
--- /dev/null
+++ b/integration-tests/springmvc-tests/springmvc-tests-connection-limit/src/test/java/org/apache/servicecomb/demo/springmvc/tests/RawSpringMvcIntegrationTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.springmvc.tests;
+
+import static org.apache.servicecomb.serviceregistry.client.LocalServiceRegistryClientImpl.LOCAL_REGISTRY_FILE_KEY;
+import static org.junit.Assert.fail;
+
+import org.apache.servicecomb.core.SCBEngine;
+import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.springframework.web.client.RestTemplate;
+
+public class RawSpringMvcIntegrationTest {
+
+  private RestTemplate restTemplate = RestTemplateBuilder.create();
+
+  private final String baseUrl = "http://127.0.0.1:8080/";
+
+  private final String controllerUrl = baseUrl + "springmvc/controller/";
+
+  @BeforeClass
+  public static void init() throws Exception {
+    System.setProperty("servicecomb.uploads.directory", "/tmp");
+    System.setProperty(LOCAL_REGISTRY_FILE_KEY, "notExistJustForceLocal");
+    SpringMvcTestMain.main(new String[0]);
+  }
+
+  @Test
+  public void ensureServerWorksFine() {
+    try {
+      String result = restTemplate.getForObject(controllerUrl + "sayhi?name=world", String.class);
+      fail("connection limit failed");
+    } catch (Exception ex) {
+      Assert.assertEquals("java.net.SocketException: Unexpected end of file from server", ex.getCause().toString());
+    }
+  }
+
+  @AfterClass
+  public static void shutdown() {
+    SCBEngine.getInstance().destroy();
+  }
+}
diff --git a/integration-tests/springmvc-tests/springmvc-tests-connection-limit/src/test/java/org/apache/servicecomb/demo/springmvc/tests/SpringMvcTestMain.java b/integration-tests/springmvc-tests/springmvc-tests-connection-limit/src/test/java/org/apache/servicecomb/demo/springmvc/tests/SpringMvcTestMain.java
new file mode 100644
index 000000000..99d937049
--- /dev/null
+++ b/integration-tests/springmvc-tests/springmvc-tests-connection-limit/src/test/java/org/apache/servicecomb/demo/springmvc/tests/SpringMvcTestMain.java
@@ -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.
+ */
+
+package org.apache.servicecomb.demo.springmvc.tests;
+
+import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
+
+public class SpringMvcTestMain {
+
+  public static void main(String[] args) throws Exception {
+    Log4jUtils.init();
+    BeanUtils.init();
+  }
+}
diff --git a/integration-tests/springmvc-tests/springmvc-tests-connection-limit/src/test/resources/microservice.yaml b/integration-tests/springmvc-tests/springmvc-tests-connection-limit/src/test/resources/microservice.yaml
new file mode 100644
index 000000000..97340cf5d
--- /dev/null
+++ b/integration-tests/springmvc-tests/springmvc-tests-connection-limit/src/test/resources/microservice.yaml
@@ -0,0 +1,33 @@
+## ---------------------------------------------------------------------------
+## 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: springmvctest-it
+service_description:
+  name: springmvc-tests
+  version: 0.0.2
+servicecomb:
+  service:
+    registry:
+      address: http://127.0.0.1:30100
+  rest:
+    address: 0.0.0.0:8080
+    server:
+      connection-limit: 0
+  handler:
+    chain:
+      Provider:
+        default: bizkeeper-provider
diff --git a/integration-tests/springmvc-tests/springmvc-tests-general/src/test/java/org/apache/servicecomb/demo/springmvc/tests/RawSpringMvcIntegrationTest.java b/integration-tests/springmvc-tests/springmvc-tests-general/src/test/java/org/apache/servicecomb/demo/springmvc/tests/RawSpringMvcIntegrationTest.java
index 17fec5324..14d81da68 100644
--- a/integration-tests/springmvc-tests/springmvc-tests-general/src/test/java/org/apache/servicecomb/demo/springmvc/tests/RawSpringMvcIntegrationTest.java
+++ b/integration-tests/springmvc-tests/springmvc-tests-general/src/test/java/org/apache/servicecomb/demo/springmvc/tests/RawSpringMvcIntegrationTest.java
@@ -18,20 +18,27 @@
 package org.apache.servicecomb.demo.springmvc.tests;
 
 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;
 
 public class RawSpringMvcIntegrationTest extends SpringMvcIntegrationTestBase {
 
+  private static final ConnectionEventWatcher watcher = new ConnectionEventWatcher();
+
   @BeforeClass
   public static void init() throws Exception {
     System.setProperty("servicecomb.uploads.directory", "/tmp");
     setUpLocalRegistry();
+    EventManager.register(watcher);
     SpringMvcTestMain.main(new String[0]);
   }
 
   @AfterClass
   public static void shutdown() {
     SCBEngine.getInstance().destroy();
+    Assert.assertArrayEquals("check connection count change", new Integer[] {1, 2, 1, 0},
+        watcher.getCounters().toArray());
   }
 }
diff --git a/integration-tests/springmvc-tests/springmvc-tests-simplified-mapping/src/test/java/org/apache/servicecomb/demo/springmvc/tests/RawSpringMvcSimplifiedMappingAnnotationIntegrationTest.java b/integration-tests/springmvc-tests/springmvc-tests-simplified-mapping/src/test/java/org/apache/servicecomb/demo/springmvc/tests/RawSpringMvcSimplifiedMappingAnnotationIntegrationTest.java
index 709152cd9..32cfb03e7 100644
--- a/integration-tests/springmvc-tests/springmvc-tests-simplified-mapping/src/test/java/org/apache/servicecomb/demo/springmvc/tests/RawSpringMvcSimplifiedMappingAnnotationIntegrationTest.java
+++ b/integration-tests/springmvc-tests/springmvc-tests-simplified-mapping/src/test/java/org/apache/servicecomb/demo/springmvc/tests/RawSpringMvcSimplifiedMappingAnnotationIntegrationTest.java
@@ -18,21 +18,28 @@
 package org.apache.servicecomb.demo.springmvc.tests;
 
 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;
 
 public class RawSpringMvcSimplifiedMappingAnnotationIntegrationTest extends SpringMvcIntegrationTestBase {
 
+  private static final ConnectionEventWatcher watcher = new ConnectionEventWatcher();
+
   @BeforeClass
   public static void init() throws Exception {
     System.setProperty("spring.profiles.active", "SimplifiedMapping");
     System.setProperty("servicecomb.uploads.directory", "/tmp");
     setUpLocalRegistry();
+    EventManager.register(watcher);
     SpringMvcTestMain.main(new String[0]);
   }
 
   @AfterClass
   public static void shutdown() {
     SCBEngine.getInstance().destroy();
+    Assert.assertArrayEquals("check connection count change", new Integer[] {1, 2, 1, 0},
+        watcher.getCounters().toArray());
   }
 }
diff --git a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClientConnection.java b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClientConnection.java
index 447318804..b08d99c5b 100644
--- a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClientConnection.java
+++ b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClientConnection.java
@@ -16,6 +16,7 @@
  */
 package org.apache.servicecomb.transport.highway;
 
+import org.apache.servicecomb.core.Const;
 import org.apache.servicecomb.foundation.vertx.client.tcp.AbstractTcpClientPackage;
 import org.apache.servicecomb.foundation.vertx.client.tcp.NetClientWrapper;
 import org.apache.servicecomb.foundation.vertx.client.tcp.TcpClientConnection;
@@ -51,7 +52,7 @@ protected TcpOutputStream createLogin() {
       header.setMsgType(MsgType.LOGIN);
 
       LoginRequest login = new LoginRequest();
-      login.setProtocol(HighwayTransport.NAME);
+      login.setProtocol(Const.HIGHWAY);
       login.setUseProtobufMapCodec(true);
 
       HighwayOutputStream os = new HighwayOutputStream(AbstractTcpClientPackage.getAndIncRequestId(), null);
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 162c63ff5..9a17081d5 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
@@ -20,10 +20,11 @@
 import java.net.InetSocketAddress;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.apache.servicecomb.core.Const;
+import org.apache.servicecomb.core.CseContext;
 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;
 
@@ -44,7 +45,7 @@
   private final AtomicInteger connectedCounter;
 
   public HighwayServerVerticle() {
-    this(((HighwayTransport) BeanUtils.getBean("highwayTransport")).getConnectedCounter());
+    this(CseContext.getInstance().getTransportManager().findTransport(Const.HIGHWAY).getConnectedCounter());
   }
 
   public HighwayServerVerticle(AtomicInteger connectedCounter) {
@@ -89,7 +90,7 @@ protected void startListen(Future<Void> startFuture) {
         return;
       }
 
-      LOGGER.error(HighwayTransport.NAME, ar.cause());
+      LOGGER.error(Const.HIGHWAY, ar.cause());
       startFuture.fail(ar.cause());
     });
   }
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 956275c71..f4bbcd164 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,8 +18,8 @@
 package org.apache.servicecomb.transport.highway;
 
 import java.util.Collections;
-import java.util.concurrent.atomic.AtomicInteger;
 
+import org.apache.servicecomb.core.Const;
 import org.apache.servicecomb.core.Invocation;
 import org.apache.servicecomb.core.transport.AbstractTransport;
 import org.apache.servicecomb.foundation.vertx.SimpleJsonObject;
@@ -32,19 +32,12 @@
 
 @Component
 public class HighwayTransport extends AbstractTransport {
-  public static final String NAME = "highway";
 
   private HighwayClient highwayClient = new HighwayClient();
 
-  private final AtomicInteger connectedCounter = new AtomicInteger(0);
-
-  public AtomicInteger getConnectedCounter() {
-    return connectedCounter;
-  }
-
   @Override
   public String getName() {
-    return NAME;
+    return Const.HIGHWAY;
   }
 
   public boolean init() throws Exception {
diff --git a/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/TestHighwayClient.java b/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/TestHighwayClient.java
index eb037e605..0b88ba528 100644
--- a/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/TestHighwayClient.java
+++ b/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/TestHighwayClient.java
@@ -24,6 +24,7 @@
 import org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf;
 import org.apache.servicecomb.codec.protobuf.definition.ProtobufManager;
 import org.apache.servicecomb.config.ConfigUtil;
+import org.apache.servicecomb.core.Const;
 import org.apache.servicecomb.core.Endpoint;
 import org.apache.servicecomb.core.Invocation;
 import org.apache.servicecomb.core.definition.OperationMeta;
@@ -92,7 +93,7 @@ public void testHighwayClientSSL(@Mocked Vertx vertx) throws Exception {
       @Mock
       <VERTICLE extends AbstractVerticle> boolean blockDeploy(Vertx vertx,
           Class<VERTICLE> cls,
-          DeploymentOptions options) throws InterruptedException {
+          DeploymentOptions options) {
         return true;
       }
     };
@@ -109,7 +110,7 @@ private Object doTestSend(Vertx vertx, HighwayClientConnectionPool pool, Highway
       @Mock
       <VERTICLE extends AbstractVerticle> boolean blockDeploy(Vertx vertx,
           Class<VERTICLE> cls,
-          DeploymentOptions options) throws InterruptedException {
+          DeploymentOptions options) {
         return true;
       }
     };
@@ -123,7 +124,7 @@ public HighwayClientConnectionPool findClientPool(boolean sync) {
 
     new MockUp<ProtobufManager>() {
       @Mock
-      public OperationProtobuf getOrCreateOperation(OperationMeta operationMeta) throws Exception {
+      public OperationProtobuf getOrCreateOperation(OperationMeta operationMeta) {
         return operationProtobuf;
       }
     };
@@ -138,14 +139,14 @@ HighwayClientConnection findOrCreateClient(String endpoint) {
     new MockUp<HighwayCodec>() {
       @Mock
       public Buffer encodeRequest(Invocation invocation, OperationProtobuf operationProtobuf,
-          long msgId) throws Exception {
+          long msgId) {
         return null;
       }
 
       @Mock
       Response decodeResponse(Invocation invocation, OperationProtobuf operationProtobuf,
           TcpData tcpData, ProtobufFeature protobufFeature) throws Throwable {
-        if (Response.class.isInstance(decodedResponse)) {
+        if (decodedResponse instanceof Response) {
           return (Response) decodedResponse;
         }
 
@@ -243,6 +244,6 @@ public void testCreateLogin(@Mocked NetClientWrapper netClientWrapper) throws Ex
     Assert.assertEquals(MsgType.LOGIN, header.getMsgType());
 
     LoginRequest login = LoginRequest.readObject(bodyBuffer);
-    Assert.assertEquals(HighwayTransport.NAME, login.getProtocol());
+    Assert.assertEquals(Const.HIGHWAY, login.getProtocol());
   }
 }
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 1aeb09248..95019d8cc 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,15 +17,15 @@
 
 package org.apache.servicecomb.transport.highway;
 
+import static org.junit.Assert.assertTrue;
+
 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;
 import org.apache.servicecomb.transport.common.MockUtil;
-import org.junit.After;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
 
@@ -37,22 +37,10 @@
 import mockit.Mocked;
 
 public class TestHighwayVerticle {
-
-  private HighwayServerVerticle highwayVerticle = null;
-
-  @Before
-  public void setUp() {
-    highwayVerticle = new HighwayServerVerticle(new AtomicInteger());
-  }
-
-  @After
-  public void tearDown() {
-    highwayVerticle = null;
-  }
-
   @Test
   public void testHighwayVerticle(@Mocked Transport transport, @Mocked Vertx vertx, @Mocked Context context,
       @Mocked JsonObject json) {
+    HighwayServerVerticle highwayVerticle = new HighwayServerVerticle(new AtomicInteger());
     URIEndpointObject endpiontObject = new URIEndpointObject("highway://127.0.0.1:9090");
     new Expectations() {
       {
@@ -79,9 +67,9 @@ public void testHighwayVerticle(@Mocked Transport transport, @Mocked Vertx vertx
     MockUtil.getInstance().mockHighwayConfig();
     try {
       highwayVerticle.startListen(startFuture);
-      Assert.assertTrue(true);
+      assertTrue(true);
     } catch (Exception e) {
-      Assert.assertTrue(false);
+      Assert.fail();
     }
   }
 }
diff --git a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/RestServerVerticle.java b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/RestServerVerticle.java
index 3780347e8..53c3890ee 100644
--- a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/RestServerVerticle.java
+++ b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/RestServerVerticle.java
@@ -19,20 +19,29 @@
 
 import java.util.List;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
 
+import org.apache.servicecomb.core.Const;
+import org.apache.servicecomb.core.CseContext;
 import org.apache.servicecomb.core.Endpoint;
 import org.apache.servicecomb.core.transport.AbstractTransport;
+import org.apache.servicecomb.foundation.common.event.EventManager;
 import org.apache.servicecomb.foundation.common.net.URIEndpointObject;
 import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
 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.ClientEvent;
+import org.apache.servicecomb.foundation.vertx.ConnectionEvent;
+import org.apache.servicecomb.foundation.vertx.TransportType;
 import org.apache.servicecomb.foundation.vertx.VertxTLSBuilder;
 import org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogConfiguration;
 import org.apache.servicecomb.transport.rest.vertx.accesslog.impl.AccessLogHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.netflix.config.DynamicPropertyFactory;
+
 import io.vertx.core.AbstractVerticle;
 import io.vertx.core.Context;
 import io.vertx.core.Future;
@@ -52,6 +61,16 @@
 
   private URIEndpointObject endpointObject;
 
+  private final AtomicInteger connectedCounter;
+
+  public RestServerVerticle() {
+    this(CseContext.getInstance().getTransportManager().findTransport(Const.RESTFUL).getConnectedCounter());
+  }
+
+  public RestServerVerticle(AtomicInteger connectedCounter) {
+    this.connectedCounter = connectedCounter;
+  }
+
   @Override
   public void init(Vertx vertx, Context context) {
     super.init(vertx, context);
@@ -75,6 +94,21 @@ public void start(Future<Void> startFuture) throws Exception {
       initDispatcher(mainRouter);
       HttpServer httpServer = createHttpServer();
       httpServer.requestHandler(mainRouter::accept);
+      httpServer.connectionHandler(connection -> {
+        int connectedCount = connectedCounter.incrementAndGet();
+        int connectionLimit = DynamicPropertyFactory.getInstance()
+            .getIntProperty("servicecomb.rest.server.connection-limit", Integer.MAX_VALUE).get();
+        if (connectedCount > connectionLimit) {
+          connectedCounter.decrementAndGet();
+          connection.close();
+        } else {
+          EventManager.post(new ClientEvent(connection.remoteAddress().toString(),
+              ConnectionEvent.Connected, TransportType.Rest, connectedCount));
+          connection.closeHandler(event -> EventManager.post(new ClientEvent(connection.remoteAddress().toString(),
+              ConnectionEvent.Closed, TransportType.Rest, connectedCounter.decrementAndGet())));
+        }
+      });
+
       startListen(httpServer, startFuture);
     } catch (Throwable e) {
       // vert.x got some states that not print error and execute call back in VertexUtils.blockDeploy, we add a log our self.
diff --git a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestRestServerVerticle.java b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestRestServerVerticle.java
index 4b6543564..fb7a13cfe 100644
--- a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestRestServerVerticle.java
+++ b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestRestServerVerticle.java
@@ -57,7 +57,7 @@
 
   @Before
   public void setUp() {
-    instance = new RestServerVerticle();
+    instance = new RestServerVerticle(new AtomicInteger());
     startFuture = Future.future();
 
     CseContext.getInstance().setTransportManager(new TransportManager());
@@ -90,7 +90,7 @@ public void testRestServerVerticleWithRouter(@Mocked Transport transport, @Mocke
         result = endpiont;
       }
     };
-    RestServerVerticle server = new RestServerVerticle();
+    RestServerVerticle server = new RestServerVerticle(new AtomicInteger());
     // process stuff done by Expectations
     server.init(vertx, context);
     server.start(startFuture);
@@ -117,7 +117,7 @@ public void testRestServerVerticleWithRouterSSL(@Mocked Transport transport, @Mo
         result = endpiont;
       }
     };
-    RestServerVerticle server = new RestServerVerticle();
+    RestServerVerticle server = new RestServerVerticle(new AtomicInteger());
     // process stuff done by Expectations
     server.init(vertx, context);
     server.start(startFuture);
@@ -144,7 +144,7 @@ public void testRestServerVerticleWithHttp2(@Mocked Transport transport, @Mocked
         result = endpiont;
       }
     };
-    RestServerVerticle server = new RestServerVerticle();
+    RestServerVerticle server = new RestServerVerticle(new AtomicInteger());
     boolean status = false;
     try {
       server.init(vertx, context);
@@ -240,7 +240,7 @@ CorsHandler getCorsHandler(String corsAllowedOrigin) {
     Router router = Mockito.mock(Router.class);
     Mockito.when(router.route()).thenReturn(Mockito.mock(Route.class));
 
-    RestServerVerticle server = new RestServerVerticle();
+    RestServerVerticle server = new RestServerVerticle(new AtomicInteger());
 
     Deencapsulation.invoke(server, "mountCorsHandler", router);
     Assert.assertEquals(7, counter.get());


 

----------------------------------------------------------------
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