[ https://issues.apache.org/jira/browse/SCB-254?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16331770#comment-16331770 ]
ASF GitHub Bot commented on SCB-254: ------------------------------------ liubao68 closed pull request #518: [SCB-254] make demo perf support invoke next step URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/518 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/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 efd4041c9..a27844119 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 @@ 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 @@ 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 String syncQuery(@PathVariable(name = "id") String id, 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 String syncQuery(@PathVariable(name = "id") String id, } 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 13df0d2e8..8d750b041 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 @@ @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 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 void setRedisPort(int redisPort) { 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 2a7d9453b..5f6b8960b 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 @@ private void onGetResponse(AsyncResult<String> ar) { } 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); } ---------------------------------------------------------------- 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: us...@infra.apache.org > make demo perf support invoke next step > --------------------------------------- > > Key: SCB-254 > URL: https://issues.apache.org/jira/browse/SCB-254 > Project: Apache ServiceComb > Issue Type: Task > Components: Java-Chassis > Reporter: wujimin > Assignee: wujimin > Priority: Major > Fix For: java-chassis-1.0.0-m1 > > -- This message was sent by Atlassian JIRA (v7.6.3#76005)