You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@servicecomb.apache.org by GitBox <gi...@apache.org> on 2018/01/26 01:05:52 UTC

[GitHub] liubao68 closed pull request #524: [SCB-190] Inherited invocation context for reactive

liubao68 closed pull request #524: [SCB-190] Inherited invocation context for reactive
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/524
 
 
   

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/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestObjectMapper.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestObjectMapper.java
index ee48c49e3..fb76c901d 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestObjectMapper.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestObjectMapper.java
@@ -29,6 +29,7 @@
 import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
 import com.fasterxml.jackson.databind.util.ISO8601Utils;
 
+@SuppressWarnings("deprecation")
 public final class RestObjectMapper extends ObjectMapper {
   public static final RestObjectMapper INSTANCE = new RestObjectMapper();
 
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestCookieProcessor.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestCookieProcessor.java
index e896369c2..16a263675 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestCookieProcessor.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestCookieProcessor.java
@@ -37,6 +37,7 @@
 import mockit.MockUp;
 import mockit.Mocked;
 
+@SuppressWarnings("deprecation")
 public class TestCookieProcessor {
   @Mocked
   HttpServletRequest request;
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestFormProcessor.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestFormProcessor.java
index 3ef0eea3e..e204d91ed 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestFormProcessor.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestFormProcessor.java
@@ -40,6 +40,7 @@
 import mockit.MockUp;
 import mockit.Mocked;
 
+@SuppressWarnings("deprecation")
 public class TestFormProcessor {
   @Mocked
   HttpServletRequest request;
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestHeaderProcessor.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestHeaderProcessor.java
index 649fa72a0..5a9d13ac9 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestHeaderProcessor.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestHeaderProcessor.java
@@ -41,6 +41,7 @@
 import mockit.MockUp;
 import mockit.Mocked;
 
+@SuppressWarnings("deprecation")
 public class TestHeaderProcessor {
   @Mocked
   HttpServletRequest request;
diff --git a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
index 2635ac392..2504ab00d 100644
--- a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
+++ b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
@@ -25,6 +25,7 @@
 import org.apache.servicecomb.swagger.invocation.AsyncResponse;
 import org.apache.servicecomb.swagger.invocation.InvocationType;
 import org.apache.servicecomb.swagger.invocation.Response;
+import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
 import org.apache.servicecomb.swagger.invocation.exception.ExceptionFactory;
 import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
 import org.slf4j.Logger;
@@ -94,8 +95,13 @@ public static void reactiveInvoke(Invocation invocation, AsyncResponse asyncResp
       invocation.setResponseExecutor(respExecutor);
 
       invocation.next(ar -> {
-        invocation.triggerFinishedEvent(ar.getStatusCode(), ar.isSuccessed());
-        asyncResp.handle(ar);
+        ContextUtils.setInvocationContext(invocation.getParentContext());
+        try {
+          invocation.triggerFinishedEvent(ar.getStatusCode(), ar.isSuccessed());
+          asyncResp.handle(ar);
+        } finally {
+          ContextUtils.removeInvocationContext();
+        }
       });
     } catch (Throwable e) {
       //if throw exception,we can use 500 for status code ?
diff --git a/core/src/test/java/org/apache/servicecomb/core/provider/consumer/TestInvokerUtils.java b/core/src/test/java/org/apache/servicecomb/core/provider/consumer/TestInvokerUtils.java
index 5560519cc..d975e65e9 100644
--- a/core/src/test/java/org/apache/servicecomb/core/provider/consumer/TestInvokerUtils.java
+++ b/core/src/test/java/org/apache/servicecomb/core/provider/consumer/TestInvokerUtils.java
@@ -17,6 +17,8 @@
 
 package org.apache.servicecomb.core.provider.consumer;
 
+import javax.xml.ws.Holder;
+
 import org.apache.servicecomb.core.BootListener;
 import org.apache.servicecomb.core.CseContext;
 import org.apache.servicecomb.core.Invocation;
@@ -25,6 +27,8 @@
 import org.apache.servicecomb.core.invocation.InvocationFactory;
 import org.apache.servicecomb.swagger.invocation.AsyncResponse;
 import org.apache.servicecomb.swagger.invocation.Response;
+import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
+import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
 import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
 import org.junit.Assert;
 import org.junit.Test;
@@ -34,6 +38,7 @@
 import mockit.Injectable;
 import mockit.Mock;
 import mockit.MockUp;
+import mockit.Mocked;
 
 public class TestInvokerUtils {
 
@@ -61,17 +66,28 @@ public Response waitResponse() throws InterruptedException {
   }
 
   @Test
-  public void testReactiveInvoke() {
-    Invocation invocation = Mockito.mock(Invocation.class);
-    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
-    boolean validAssert;
-    try {
-      InvokerUtils.reactiveInvoke(invocation, asyncResp);
-      validAssert = true;
-    } catch (Exception e) {
-      validAssert = false;
-    }
-    Assert.assertTrue(validAssert);
+  public void testReactiveInvoke(@Mocked Invocation invocation, @Mocked InvocationContext parentContext,
+      @Mocked Response response) {
+    new MockUp<Invocation>(invocation) {
+      @Mock
+      InvocationContext getParentContext() {
+        return parentContext;
+      }
+
+      @Mock
+      void next(AsyncResponse asyncResp) {
+        asyncResp.handle(response);
+      }
+    };
+
+
+    Holder<InvocationContext> holder = new Holder<>();
+    InvokerUtils.reactiveInvoke(invocation, ar -> {
+      holder.value = ContextUtils.getInvocationContext();
+    });
+
+    Assert.assertNull(ContextUtils.getInvocationContext());
+    Assert.assertSame(parentContext, holder.value);
   }
 
   @SuppressWarnings("deprecation")
diff --git a/demo/demo-pojo/pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/CodeFirstPojoClient.java b/demo/demo-pojo/pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/CodeFirstPojoClient.java
index 529ad45cc..6a775d05e 100644
--- a/demo/demo-pojo/pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/CodeFirstPojoClient.java
+++ b/demo/demo-pojo/pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/CodeFirstPojoClient.java
@@ -23,7 +23,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
+import java.util.concurrent.CountDownLatch;
 
 import javax.inject.Inject;
 
@@ -33,7 +33,12 @@
 import org.apache.servicecomb.demo.TestMgr;
 import org.apache.servicecomb.demo.compute.Person;
 import org.apache.servicecomb.demo.server.User;
+import org.apache.servicecomb.foundation.vertx.VertxUtils;
 import org.apache.servicecomb.provider.pojo.RpcReference;
+import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
+import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
+
+import io.vertx.core.Vertx;
 
 public class CodeFirstPojoClient {
   @RpcReference(microserviceName = "pojo", schemaId = "org.apache.servicecomb.demo.CodeFirstPojoIntf")
@@ -78,10 +83,33 @@ private void testCodeFirstCompletableFuture(CodeFirstPojoIntf codeFirst) {
       return;
     }
 
-    CompletableFuture<String> future = ((CodeFirstPojoClientIntf) codeFirst).sayHiAsync("someone");
+    Vertx vertx = VertxUtils.getOrCreateVertxByName("transport", null);
+    CountDownLatch latch = new CountDownLatch(1);
+    // vertx.runOnContext in normal thread is not a good practice
+    // here just a test, not care for this.
+    vertx.runOnContext(V -> {
+      InvocationContext context = new InvocationContext();
+      context.addContext("k", "v");
+      ContextUtils.setInvocationContext(context);
+      CompletableFuture<String> future = ((CodeFirstPojoClientIntf) codeFirst).sayHiAsync("someone");
+
+      future.thenCompose(result -> {
+        TestMgr.check("someone sayhi, context k: v", result);
+
+        TestMgr.check(true, context == ContextUtils.getInvocationContext());
+
+        return ((CodeFirstPojoClientIntf) codeFirst).sayHiAsync("someone 1");
+      }).whenComplete((r, e) -> {
+        TestMgr.check("someone 1 sayhi, context k: v", r);
+        latch.countDown();
+      });
+
+      ContextUtils.removeInvocationContext();
+    });
+
     try {
-      TestMgr.check("someone sayhi", future.get());
-    } catch (InterruptedException | ExecutionException e) {
+      latch.await();
+    } catch (InterruptedException e) {
       throw new IllegalStateException(e);
     }
   }
@@ -162,7 +190,7 @@ protected void testCodeFirstSayHi2(CodeFirstPojoIntf codeFirst) {
 
   protected void testCodeFirstSayHi(CodeFirstPojoIntf codeFirst) {
     String result = codeFirst.sayHi("world");
-    TestMgr.check("world sayhi", result);
+    TestMgr.check("world sayhi, context k: null", result);
     //        TestMgr.check(202, responseEntity.getStatusCode());
   }
 
diff --git a/demo/demo-pojo/pojo-server/src/main/java/org/apache/servicecomb/demo/pojo/server/CodeFirstPojo.java b/demo/demo-pojo/pojo-server/src/main/java/org/apache/servicecomb/demo/pojo/server/CodeFirstPojo.java
index 54bd4b27d..6bc588569 100644
--- a/demo/demo-pojo/pojo-server/src/main/java/org/apache/servicecomb/demo/pojo/server/CodeFirstPojo.java
+++ b/demo/demo-pojo/pojo-server/src/main/java/org/apache/servicecomb/demo/pojo/server/CodeFirstPojo.java
@@ -85,7 +85,9 @@ public String saySomething(String prefix, Person user) {
 
   public String sayHi(String name) {
     ContextUtils.getInvocationContext().setStatus(202);
-    return name + " sayhi";
+    return name + " sayhi, context k: "
+        + (ContextUtils.getInvocationContext() == null ? ""
+            : ContextUtils.getInvocationContext().getContext("k"));
   }
 
   @ApiOperation(nickname = "sayHi2", value = "")
diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/CodeFirstRestTemplateSpringmvc.java b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/CodeFirstRestTemplateSpringmvc.java
index 722f7d26d..606d6bafa 100644
--- a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/CodeFirstRestTemplateSpringmvc.java
+++ b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/CodeFirstRestTemplateSpringmvc.java
@@ -128,6 +128,18 @@ private void testUpload(RestTemplate template, String cseUrlPrefix) throws IOExc
     String result = testRestTemplateUpload(template, cseUrlPrefix, file1, someFile);
     TestMgr.check(expect, result);
 
+    {
+      MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
+      map.add("file1", new FileSystemResource(file1));
+
+      result = template.postForObject(
+          cseUrlPrefix + "/upload1",
+          new HttpEntity<>(map),
+          String.class);
+
+      System.out.println(result);
+    }
+
     result = uploadPartAndFile.fileUpload(new FilePart(null, file1), someFile);
     TestMgr.check(expect, result);
 
diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestGeneric.java b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestGeneric.java
index 34a3475a9..3ca0a570e 100644
--- a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestGeneric.java
+++ b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestGeneric.java
@@ -30,6 +30,7 @@
 
 import com.fasterxml.jackson.databind.util.ISO8601Utils;
 
+@SuppressWarnings("deprecation")
 public class TestGeneric {
   private CodeFirstSpringmvcIntf intf;
 
diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java
index 839844ec4..1251f61ec 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java
+++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java
@@ -112,6 +112,13 @@ private String _fileUpload(MultipartFile file1, Part file2) {
     }
   }
 
+  @PostMapping(path = "/upload1", produces = MediaType.TEXT_PLAIN_VALUE)
+  public String fileUpload1(@RequestPart(name = "file1") MultipartFile file1) throws IOException {
+    try (InputStream is = file1.getInputStream()) {
+      return IOUtils.toString(is);
+    }
+  }
+
   @PostMapping(path = "/upload", produces = MediaType.TEXT_PLAIN_VALUE)
   public String fileUpload(@RequestPart(name = "file1") MultipartFile file1,
       @RequestPart(name = "someFile") Part file2) {
diff --git a/demo/perf/src/main/java/org/apache/servicecomb/demo/perf/Impl.java b/demo/perf/src/main/java/org/apache/servicecomb/demo/perf/Impl.java
index a27844119..e2505ed0b 100644
--- a/demo/perf/src/main/java/org/apache/servicecomb/demo/perf/Impl.java
+++ b/demo/perf/src/main/java/org/apache/servicecomb/demo/perf/Impl.java
@@ -55,7 +55,7 @@ public String syncQuery(@PathVariable(name = "id") String id,
       return buildFromMemoryResponse(id);
     }
 
-    return intf.syncQuery(id, step, all, fromDB);
+    return intf.syncQuery(id, step + 1, all, fromDB);
   }
 
   public String buildFromMemoryResponse(String id) {
@@ -76,6 +76,6 @@ public String buildFromMemoryResponse(String id) {
       return future;
     }
 
-    return intf.asyncQuery(id, step, all, fromDB);
+    return intf.asyncQuery(id, step + 1, all, fromDB);
   }
 }
diff --git a/metrics/metrics-common/src/main/java/org/apache/servicecomb/metrics/common/CallMetric.java b/metrics/metrics-common/src/main/java/org/apache/servicecomb/metrics/common/CallMetric.java
index 4c5c862dc..36e1d49bf 100644
--- a/metrics/metrics-common/src/main/java/org/apache/servicecomb/metrics/common/CallMetric.java
+++ b/metrics/metrics-common/src/main/java/org/apache/servicecomb/metrics/common/CallMetric.java
@@ -81,10 +81,10 @@ public CallMetric merge(CallMetric metric) {
 
   public Map<String, Number> toMap() {
     Map<String, Number> metrics = new HashMap<>();
-    for (MetricValue totalValue : totalValues) {
+    for (LongMetricValue totalValue : totalValues) {
       metrics.put(prefix + ".total." + totalValue.getKey(), totalValue.getValue());
     }
-    for (MetricValue tpsValue : tpsValues) {
+    for (DoubleMetricValue tpsValue : tpsValues) {
       metrics.put(prefix + ".tps." + tpsValue.getKey(), tpsValue.getValue());
     }
     return metrics;
diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/utils/MonitorUtils.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/utils/MonitorUtils.java
index f2a816985..20bfe4e7a 100644
--- a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/utils/MonitorUtils.java
+++ b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/utils/MonitorUtils.java
@@ -42,12 +42,12 @@ public static long adjustValue(long value) {
     return value < 0 ? 0 : value;
   }
 
-  public static boolean containsTagValue(Monitor monitor, String tagKey, String tagValue) {
+  public static boolean containsTagValue(Monitor<?> monitor, String tagKey, String tagValue) {
     TagList tags = monitor.getConfig().getTags();
     return tags.containsKey(tagKey) && tagValue.equals(tags.getTag(tagKey).getValue());
   }
 
-  public static Map<String, String> convertTags(Monitor monitor) {
+  public static Map<String, String> convertTags(Monitor<?> monitor) {
     TagList tags = monitor.getConfig().getTags();
     if (tags.size() != 0) {
       Map<String, String> tagMap = new HashMap<>();
diff --git a/pom.xml b/pom.xml
index c2479fb79..51412e5f4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -232,7 +232,6 @@
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
-        <version>2.18.1</version>
         <configuration>
           <skip>${maven.test.skip}</skip>
           <testFailureIgnore>${maven.test.failure.ignore}</testFailureIgnore>
diff --git a/samples/metrics-write-file-sample/metrics-write-file/src/test/java/org/apache/servicecomb/samples/mwf/TestWriteFile.java b/samples/metrics-write-file-sample/metrics-write-file/src/test/java/org/apache/servicecomb/samples/mwf/TestWriteFile.java
index 63a46d238..8571ae770 100644
--- a/samples/metrics-write-file-sample/metrics-write-file/src/test/java/org/apache/servicecomb/samples/mwf/TestWriteFile.java
+++ b/samples/metrics-write-file-sample/metrics-write-file/src/test/java/org/apache/servicecomb/samples/mwf/TestWriteFile.java
@@ -17,7 +17,6 @@
 
 package org.apache.servicecomb.samples.mwf;
 
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -138,22 +137,24 @@ public Features getFeatures() {
 
     StringBuilder builder = new StringBuilder();
 
-    MetricsFileWriter writer = (loggerName, filePrefix, content) ->
-        builder.append(loggerName).append(filePrefix).append(content);
+    MetricsFileWriter writer =
+        (loggerName, filePrefix, content) -> builder.append(loggerName).append(filePrefix).append(content);
 
     SystemMetric systemMetric = new SystemMetric(50, 10, 1, 2, 3,
         4, 5, 6, 7, 8);
 
     Map<String, ConsumerInvocationMetric> consumerInvocationMetricMap = new HashMap<>();
-    consumerInvocationMetricMap.put("A", new ConsumerInvocationMetric("A", "A",
-        new TimerMetric("A1", 1, 2, 3, 4),
-        new CallMetric("A2", Collections.singletonList(new LongMetricValue("A2", 100L, new HashMap<>())),
-            Collections.singletonList(new DoubleMetricValue("A2", 999.44444, new HashMap<>())))));
-
-    consumerInvocationMetricMap.put("B", new ConsumerInvocationMetric("B", "B",
-        new TimerMetric("B1", 1, 2, 3, 4),
-        new CallMetric("B2", Collections.singletonList(new LongMetricValue("B2", 100L, new HashMap<>())),
-            Collections.singletonList(new DoubleMetricValue("B2", 888.66666, new HashMap<>())))));
+    consumerInvocationMetricMap.put("A",
+        new ConsumerInvocationMetric("A", "A",
+            new TimerMetric("A1", 1, 2, 3, 4),
+            new CallMetric("A2", Collections.singletonList(new LongMetricValue("A2", 100L, new HashMap<>())),
+                Collections.singletonList(new DoubleMetricValue("A2", 999.44444, new HashMap<>())))));
+
+    consumerInvocationMetricMap.put("B",
+        new ConsumerInvocationMetric("B", "B",
+            new TimerMetric("B1", 1, 2, 3, 4),
+            new CallMetric("B2", Collections.singletonList(new LongMetricValue("B2", 100L, new HashMap<>())),
+                Collections.singletonList(new DoubleMetricValue("B2", 888.66666, new HashMap<>())))));
 
     RegistryMetric metric = new RegistryMetric(systemMetric, consumerInvocationMetricMap, new HashMap<>(),
         new HashMap<>());
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/SwaggerInvocation.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/SwaggerInvocation.java
index d71c4f8a2..cd2c0948f 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/SwaggerInvocation.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/SwaggerInvocation.java
@@ -26,13 +26,19 @@
 
   protected Object[] swaggerArguments;
 
+  protected InvocationContext parentContext;
+
   public SwaggerInvocation() {
-    InvocationContext context = ContextUtils.getInvocationContext();
-    if (context != null) {
-      addContext(context.getContext());
+    parentContext = ContextUtils.getInvocationContext();
+    if (parentContext != null) {
+      addContext(parentContext.getContext());
     }
   }
 
+  public InvocationContext getParentContext() {
+    return parentContext;
+  }
+
   public InvocationType getInvocationType() {
     return invocationType;
   }
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/TestSwaggerInvocation.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/TestSwaggerInvocation.java
new file mode 100644
index 000000000..85177710f
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/TestSwaggerInvocation.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.swagger.invocation;
+
+import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
+import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
+import org.junit.Assert;
+import org.junit.Test;
+
+import mockit.Mocked;
+
+public class TestSwaggerInvocation {
+  @Test
+  public void construct_withContext(@Mocked InvocationContext parentContext) {
+    ContextUtils.setInvocationContext(parentContext);
+
+    try {
+      SwaggerInvocation invocation = new SwaggerInvocation();
+      Assert.assertSame(parentContext, invocation.getParentContext());
+    } finally {
+      ContextUtils.removeInvocationContext();
+    }
+  }
+
+  @Test
+  public void construct_noContext() {
+    SwaggerInvocation invocation = new SwaggerInvocation();
+    Assert.assertNull(invocation.getParentContext());
+  }
+}


 

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