You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2018/01/19 05:45:44 UTC

[incubator-servicecomb-java-chassis] branch master updated: SCB-254 make demo perf support invoke next step

This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git


The following commit(s) were added to refs/heads/master by this push:
     new a69e9a5  SCB-254 make demo perf support invoke next step
a69e9a5 is described below

commit a69e9a5ade17898040149b2d20e50cedcacd90b6
Author: wujimin <wu...@huawei.com>
AuthorDate: Thu Jan 18 12:35:47 2018 +0800

    SCB-254 make demo perf support invoke next step
---
 .../org/apache/servicecomb/demo/perf/Impl.java     | 28 ++++++++++++++--------
 .../servicecomb/demo/perf/PerfConfiguration.java   | 27 ++++++++++-----------
 .../apache/servicecomb/demo/perf/RedisSession.java |  5 +---
 3 files changed, 32 insertions(+), 28 deletions(-)

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 efd4041..a278441 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
@@ -18,7 +18,9 @@ package org.apache.servicecomb.demo.perf;
 
 import java.util.concurrent.CompletableFuture;
 
+import org.apache.servicecomb.provider.pojo.Invoker;
 import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -29,10 +31,16 @@ import org.springframework.web.bind.annotation.RequestParam;
 public class Impl {
   private Intf intf;
 
-  public Impl() {
-    //    intf = Invoker.createProxy(perfConfiguration.getNextMicroserviceName(),
-    //        "impl",
-    //        Intf.class);
+  @Value(value = "${service_description.name}")
+  public void setSelfMicroserviceName(String selfMicroserviceName) {
+    // self: perf-1/perf-a
+    // next: perf-2/perf-b
+    char last = selfMicroserviceName.charAt(selfMicroserviceName.length() - 1);
+    String nextMicroserviceName =
+        selfMicroserviceName.substring(0, selfMicroserviceName.length() - 1) + (char) (last + 1);
+    intf = Invoker.createProxy(nextMicroserviceName,
+        "impl",
+        Intf.class);
   }
 
   @GetMapping(path = "/syncQuery/{id}")
@@ -44,16 +52,16 @@ public class Impl {
         return RedisClientUtils.syncQuery(id);
       }
 
-      return new StringBuilder(64 + PerfConfiguration.responseData.length())
-          .append(id)
-          .append(" from memory: ")
-          .append(PerfConfiguration.responseData)
-          .toString();
+      return buildFromMemoryResponse(id);
     }
 
     return intf.syncQuery(id, step, all, fromDB);
   }
 
+  public String buildFromMemoryResponse(String id) {
+    return PerfConfiguration.buildResponse("memory", id);
+  }
+
   @GetMapping(path = "/asyncQuery/{id}")
   public CompletableFuture<String> asyncQuery(@PathVariable(name = "id") String id,
       @RequestParam(name = "step") int step, @RequestParam(name = "all") int all,
@@ -64,7 +72,7 @@ public class Impl {
       }
 
       CompletableFuture<String> future = new CompletableFuture<>();
-      future.complete("value of " + id + " from memory.");
+      future.complete(buildFromMemoryResponse(id));
       return future;
     }
 
diff --git a/demo/perf/src/main/java/org/apache/servicecomb/demo/perf/PerfConfiguration.java b/demo/perf/src/main/java/org/apache/servicecomb/demo/perf/PerfConfiguration.java
index 13df0d2..8d750b0 100644
--- a/demo/perf/src/main/java/org/apache/servicecomb/demo/perf/PerfConfiguration.java
+++ b/demo/perf/src/main/java/org/apache/servicecomb/demo/perf/PerfConfiguration.java
@@ -16,6 +16,7 @@
  */
 package org.apache.servicecomb.demo.perf;
 
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
@@ -23,10 +24,6 @@ import com.google.common.base.Strings;
 
 @Component
 public class PerfConfiguration {
-  public static String selfMicroserviceName;
-
-  public static String nextMicroserviceName;
-
   public static int syncCount;
 
   public static int asyncCount;
@@ -55,15 +52,14 @@ public class PerfConfiguration {
 
   public static String redisPassword;
 
-  @Value(value = "${service_description.name}")
-  public void setSelfMicroserviceName(String selfMicroserviceName) {
-    PerfConfiguration.selfMicroserviceName = selfMicroserviceName;
-
-    // self: perf-1/perf-a
-    // next: perf-2/perf-b
-    char last = selfMicroserviceName.charAt(selfMicroserviceName.length() - 1);
-    nextMicroserviceName =
-        selfMicroserviceName.substring(0, selfMicroserviceName.length() - 1) + (char) (last + 1);
+  public static String buildResponse(String from, String id) {
+    return new StringBuilder(64 + PerfConfiguration.responseData.length())
+        .append(id)
+        .append(" from ")
+        .append(from)
+        .append(": ")
+        .append(PerfConfiguration.responseData)
+        .toString();
   }
 
   @Value(value = "${response-size}")
@@ -127,8 +123,11 @@ public class PerfConfiguration {
     PerfConfiguration.redisPort = redisPort;
   }
 
-  @Value(value = "${redis.password:null}")
+  @Value(value = "${redis.password:}")
   public void setRedisPassword(String redisPassword) {
+    if (StringUtils.isEmpty(redisPassword)) {
+      return;
+    }
     PerfConfiguration.redisPassword = redisPassword;
   }
 }
diff --git a/demo/perf/src/main/java/org/apache/servicecomb/demo/perf/RedisSession.java b/demo/perf/src/main/java/org/apache/servicecomb/demo/perf/RedisSession.java
index 2a7d945..5f6b896 100644
--- a/demo/perf/src/main/java/org/apache/servicecomb/demo/perf/RedisSession.java
+++ b/demo/perf/src/main/java/org/apache/servicecomb/demo/perf/RedisSession.java
@@ -55,10 +55,7 @@ public class RedisSession {
   }
 
   private void createCache() {
-    createResult = new StringBuilder(64 + PerfConfiguration.responseData.length()).append(id)
-        .append(" from redis: ")
-        .append(PerfConfiguration.responseData)
-        .toString();
+    createResult = PerfConfiguration.buildResponse("redis", id);
     redis.set(id, createResult, this::onCreateCacheResponse);
   }
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>'].