WillemJiang closed pull request #539: SCB-308 Vertx transport server timeout 
will cause VertxServerRequestT?
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/539
 
 
   

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/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/VertxServerRequestToHttpServletRequest.java
 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/VertxServerRequestToHttpServletRequest.java
index b3409a4d3..94bc41cb6 100644
--- 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/VertxServerRequestToHttpServletRequest.java
+++ 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/VertxServerRequestToHttpServletRequest.java
@@ -40,6 +40,7 @@
 import io.vertx.core.MultiMap;
 import io.vertx.core.buffer.Buffer;
 import io.vertx.core.http.HttpServerRequest;
+import io.vertx.core.net.SocketAddress;
 import io.vertx.ext.web.FileUpload;
 import io.vertx.ext.web.RoutingContext;
 
@@ -59,6 +60,8 @@
 
   private String path;
 
+  private SocketAddress socketAddress;
+
   public VertxServerRequestToHttpServletRequest(RoutingContext context, String 
path) {
     this(context);
     this.path = path;
@@ -67,6 +70,7 @@ public VertxServerRequestToHttpServletRequest(RoutingContext 
context, String pat
   public VertxServerRequestToHttpServletRequest(RoutingContext context) {
     this.context = context;
     this.vertxRequest = context.request();
+    this.socketAddress = this.vertxRequest.remoteAddress();
     super.setBodyBuffer(context.getBody());
   }
 
@@ -127,17 +131,17 @@ public String getScheme() {
 
   @Override
   public String getRemoteAddr() {
-    return this.vertxRequest.remoteAddress().host();
+    return this.socketAddress.host();
   }
 
   @Override
   public String getRemoteHost() {
-    return this.vertxRequest.remoteAddress().host();
+    return this.socketAddress.host();
   }
 
   @Override
   public int getRemotePort() {
-    return this.vertxRequest.remoteAddress().port();
+    return this.socketAddress.port();
   }
 
   @Override
diff --git 
a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxServerRequestToHttpServletRequest.java
 
b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxServerRequestToHttpServletRequest.java
index e4d5277fd..56fd1c242 100644
--- 
a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxServerRequestToHttpServletRequest.java
+++ 
b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxServerRequestToHttpServletRequest.java
@@ -53,6 +53,9 @@
   @Mocked
   HttpServerRequest vertxRequest;
 
+  @Mocked
+  SocketAddress socketAddress;
+
   VertxServerRequestToHttpServletRequest request;
 
   @Before
@@ -61,6 +64,8 @@ public void setup() {
       {
         context.request();
         result = vertxRequest;
+        vertxRequest.remoteAddress();
+        result = socketAddress;
       }
     };
 
@@ -192,13 +197,11 @@ public void testScheme() {
   }
 
   @Test
-  public void testGetRemoteAddr(@Mocked SocketAddress sa) {
+  public void testGetRemoteAddr() {
     new Expectations() {
       {
-        sa.host();
+        socketAddress.host();
         result = "host";
-        vertxRequest.remoteAddress();
-        result = sa;
       }
     };
 
@@ -206,13 +209,22 @@ public void testGetRemoteAddr(@Mocked SocketAddress sa) {
   }
 
   @Test
-  public void testGetRemoteHost(@Mocked SocketAddress sa) {
+  public void testGetRemoteAddrNull() {
     new Expectations() {
       {
-        sa.host();
+        socketAddress.host();
+        result = null;
+      }
+    };
+    Assert.assertEquals(null, request.getRemoteAddr());
+  }
+
+  @Test
+  public void testGetRemoteHost() {
+    new Expectations() {
+      {
+        socketAddress.host();
         result = "host";
-        vertxRequest.remoteAddress();
-        result = sa;
       }
     };
 
@@ -220,13 +232,11 @@ public void testGetRemoteHost(@Mocked SocketAddress sa) {
   }
 
   @Test
-  public void testGetRemotePort(@Mocked SocketAddress sa) {
+  public void testGetRemotePort() {
     new Expectations() {
       {
-        sa.port();
+        socketAddress.port();
         result = 1234;
-        vertxRequest.remoteAddress();
-        result = sa;
       }
     };
 
diff --git 
a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestDispatcher.java
 
b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestDispatcher.java
index 40537a310..6daafabb4 100644
--- 
a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestDispatcher.java
+++ 
b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestDispatcher.java
@@ -36,6 +36,8 @@
 import org.junit.Test;
 
 import 
io.netty.handler.codec.http.multipart.HttpPostRequestDecoder.ErrorDataDecoderException;
+import io.vertx.core.http.HttpServerRequest;
+import io.vertx.core.net.SocketAddress;
 import io.vertx.ext.web.Router;
 import io.vertx.ext.web.RoutingContext;
 import mockit.Deencapsulation;
@@ -147,7 +149,7 @@ public void failureHandlerErrorDataWithNormal(@Mocked 
RoutingContext context) {
   }
 
   @Test
-  public void onRequest() {
+  public void onRequest(@Mocked HttpServerRequest request, @Mocked 
SocketAddress socketAdrress) {
     Map<String, Object> map = new HashMap<>();
     RoutingContext context = new MockUp<RoutingContext>() {
       @Mock
@@ -155,6 +157,11 @@ RoutingContext put(String key, Object obj) {
         map.put(key, obj);
         return null;
       }
+
+      @Mock
+      HttpServerRequest request() {
+        return request;
+      }
     }.getMockInstance();
     Deencapsulation.invoke(dispatcher, "onRequest", context);
 


 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to