[ https://issues.apache.org/jira/browse/SCB-793?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16575679#comment-16575679 ]
ASF GitHub Bot commented on SCB-793: ------------------------------------ liubao68 closed pull request #864: [SCB-793] Run it-consumer during travis ci URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/864 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/SCBEngine.java b/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java index aa42ded56..6c5ccb3ac 100644 --- a/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java +++ b/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java @@ -155,6 +155,7 @@ public void afterRegistryInstance(MicroserviceInstanceRegisterTask microserviceI status = SCBStatus.UP; triggerEvent(EventType.AFTER_REGISTRY); EventManager.unregister(this); + LOGGER.info("ServiceComb is ready."); } } }); diff --git a/demo/demo-signature/src/main/java/org/apache/servicecomb/demo/signature/ClientSignature.java b/demo/demo-signature/src/main/java/org/apache/servicecomb/demo/signature/ClientSignature.java index 6acd4643d..aa715d2bc 100644 --- a/demo/demo-signature/src/main/java/org/apache/servicecomb/demo/signature/ClientSignature.java +++ b/demo/demo-signature/src/main/java/org/apache/servicecomb/demo/signature/ClientSignature.java @@ -47,7 +47,7 @@ public Response afterReceiveResponse(Invocation invocation, HttpServletResponseE String serverSignature = responseEx.getHeader("signature"); if (serverSignature != null) { - LOGGER.info("check response signature, client: {}, server: {}.", signature, serverSignature); + LOGGER.debug("check response signature, client: {}, server: {}.", signature, serverSignature); if (!signature.equals(serverSignature)) { LOGGER.error("check response signature failed"); return Response.create(Status.UNAUTHORIZED, "check response signature failed"); diff --git a/demo/demo-signature/src/main/java/org/apache/servicecomb/demo/signature/ServerSignature.java b/demo/demo-signature/src/main/java/org/apache/servicecomb/demo/signature/ServerSignature.java index 35540611a..937aa7ff6 100644 --- a/demo/demo-signature/src/main/java/org/apache/servicecomb/demo/signature/ServerSignature.java +++ b/demo/demo-signature/src/main/java/org/apache/servicecomb/demo/signature/ServerSignature.java @@ -48,7 +48,7 @@ public boolean needCacheRequest(OperationMeta operationMeta) { public Response afterReceiveRequest(Invocation invocation, HttpServletRequestEx requestEx) { String signature = SignatureUtils.genSignature(requestEx); String clientSignature = requestEx.getHeader("signature"); - LOGGER.info("check request signature, client: {}, server: {}.", clientSignature, signature); + LOGGER.debug("check request signature, client: {}, server: {}.", clientSignature, signature); if (!signature.equals(clientSignature)) { LOGGER.error("check request signature failed: {}", invocation.getInvocationQualifiedName()); return Response diff --git a/integration-tests/it-common/src/main/resources/logback.xml b/integration-tests/it-common/src/main/resources/logback.xml index dfdfa9214..d753514a0 100644 --- a/integration-tests/it-common/src/main/resources/logback.xml +++ b/integration-tests/it-common/src/main/resources/logback.xml @@ -23,7 +23,7 @@ <pattern>%d [%level] [%thread] - %msg (%F:%L\)%n</pattern> </encoder> </appender> - <root level="WARN"> + <root level="INFO"> <appender-ref ref="STDOUT"/> </root> </configuration> \ No newline at end of file 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 528f9728c..a52e787f5 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 @@ -39,13 +39,17 @@ public static boolean autoExit = true; public static void main(String[] args) throws Throwable { + deploys.init(); + deploys.getServiceCenter().ensureReady(); + BeanUtils.init(); ITUtils.waitBootFinished(); - deploys.init(); run(); SCBEngine.getInstance().destroy(); + deploys.getServiceCenter().stop(); + resultPrinter.print(); if (autoExit) { diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/DeployDefinition.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/DeployDefinition.java index dfdc15840..99becf4fc 100644 --- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/DeployDefinition.java +++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/DeployDefinition.java @@ -23,6 +23,10 @@ protected String displayName; + protected String startCompleteLog; + + protected String workDir; + /** * <pre> * edge as the example: @@ -57,6 +61,22 @@ public void setDisplayName(String displayName) { this.displayName = displayName; } + public String getStartCompleteLog() { + return startCompleteLog; + } + + public void setStartCompleteLog(String startCompleteLog) { + this.startCompleteLog = startCompleteLog; + } + + public String getWorkDir() { + return workDir; + } + + public void setWorkDir(String workDir) { + this.workDir = workDir; + } + public String getCmd() { return cmd; } diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/Deploys.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/Deploys.java index aae0dadf5..881ae6c88 100644 --- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/Deploys.java +++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/Deploys.java @@ -32,11 +32,17 @@ private String pomVersion; - public MicroserviceDeploy edge; + private ServiceCenterDeploy serviceCenter; - public MicroserviceDeploy baseProducer; + private MicroserviceDeploy edge; - public MicroserviceDeploy zuul; + private MicroserviceDeploy baseProducer; + + private MicroserviceDeploy zuul; + + public ServiceCenterDeploy getServiceCenter() { + return serviceCenter; + } public MicroserviceDeploy getEdge() { return edge; @@ -54,6 +60,7 @@ public void init() throws Throwable { initPomVersion(); LOGGER.info("test version: {}", pomVersion); + serviceCenter = new ServiceCenterDeploy(); initEdge(); initBaseProducer(); // initZuul(); diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/MicroserviceDeploy.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/MicroserviceDeploy.java index 027688211..2892c51a8 100644 --- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/MicroserviceDeploy.java +++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/MicroserviceDeploy.java @@ -16,6 +16,7 @@ */ package org.apache.servicecomb.it.deploy; +import org.apache.commons.lang3.ArrayUtils; import org.apache.servicecomb.it.ITUtils; import org.apache.servicecomb.serviceregistry.RegistryUtils; import org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersionRule; @@ -30,11 +31,8 @@ public MicroserviceDeploy(DeployDefinition deployDefinition) { super(deployDefinition); this.microserviceDeployDefinition = (MicroserviceDeployDefinition) deployDefinition; - } - @Override - public void deploy() throws Throwable { - super.deploy(); + this.microserviceDeployDefinition.setStartCompleteLog("ServiceComb is ready."); } @Override @@ -42,6 +40,12 @@ public void deploy() throws Throwable { return new String[] {"java", "-jar", deployDefinition.getCmd()}; } + @Override + protected String[] addArgs(String[] cmds) { + return ArrayUtils.addAll(super.addArgs(cmds), + "-DselfController=" + RegistryUtils.getMicroserviceInstance().getInstanceId()); + } + public void ensureReady() throws Throwable { MicroserviceVersionRule microserviceVersionRule = RegistryUtils.getServiceRegistry().getAppManager() .getOrCreateMicroserviceVersionRule(microserviceDeployDefinition.getAppId(), @@ -53,6 +57,7 @@ public void ensureReady() throws Throwable { } deploy(); + waitStartComplete(); ITUtils.waitMicroserviceReady(microserviceDeployDefinition.getAppId(), microserviceDeployDefinition.getMicroserviceName(), microserviceDeployDefinition.getVersion(), diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/NormalDeploy.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/NormalDeploy.java index f750f1e19..8db18287f 100644 --- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/NormalDeploy.java +++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/NormalDeploy.java @@ -18,12 +18,12 @@ import java.io.BufferedWriter; +import java.io.File; import java.io.OutputStreamWriter; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.servicecomb.foundation.common.utils.JsonUtils; -import org.apache.servicecomb.serviceregistry.RegistryUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,13 +44,17 @@ public NormalDeploy(DeployDefinition deployDefinition) { public void deploy() throws Throwable { String[] cmds = createCmds(); - cmds = ArrayUtils.addAll(cmds, deployDefinition.getArgs()); - cmds = ArrayUtils.addAll(cmds, - "-DselfController=" + RegistryUtils.getMicroserviceInstance().getInstanceId()); + cmds = addArgs(cmds); subProcess = createProcessBuilder(cmds).start(); subProcessCommandWriter = new BufferedWriter(new OutputStreamWriter(subProcess.getOutputStream())); - subProcessLogger = new SubProcessLogger(deployDefinition.getDisplayName(), subProcess.getInputStream()); + subProcessLogger = new SubProcessLogger(deployDefinition.getDisplayName(), subProcess.getInputStream(), + deployDefinition.getStartCompleteLog()); + } + + protected String[] addArgs(String[] cmds) { + cmds = ArrayUtils.addAll(cmds, deployDefinition.getArgs()); + return cmds; } protected String[] createCmds() { @@ -58,7 +62,15 @@ public void deploy() throws Throwable { } protected ProcessBuilder createProcessBuilder(String[] cmds) { - return new ProcessBuilder(cmds).redirectErrorStream(true); + ProcessBuilder processBuilder = new ProcessBuilder(cmds).redirectErrorStream(true); + if (deployDefinition.getWorkDir() != null) { + processBuilder.directory(new File(deployDefinition.getWorkDir())); + } + return processBuilder; + } + + public void waitStartComplete() { + subProcessLogger.waitStartComplete(); } public void sendCommand(Object command) { @@ -82,7 +94,7 @@ protected void afterStop() { public void waitStop() { if (subProcess == null) { - LOGGER.info("Ignore, already stop, displayName={}.", deployDefinition.getDisplayName()); + LOGGER.info("Ignore, already stop or reusing exist instance, displayName={}.", deployDefinition.getDisplayName()); return; } @@ -98,17 +110,18 @@ public void waitStop() { subProcess = null; afterStop(); - LOGGER.info("finished stop {}.", deployDefinition.getDisplayName()); + LOGGER.info("stop complete, displayName={}.", deployDefinition.getDisplayName()); } public void stop() { if (subProcess == null) { - LOGGER.info("Ignore, already stop, displayName={}.", deployDefinition.getDisplayName()); + LOGGER.info("Ignore, already stop or reusing exist instance, displayName={}.", deployDefinition.getDisplayName()); return; } subProcess.destroy(); subProcess = null; afterStop(); + LOGGER.info("stop complete, displayName={}.", deployDefinition.getDisplayName()); } } diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/ServiceCenterDeploy.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/ServiceCenterDeploy.java new file mode 100644 index 000000000..9a38dbcc2 --- /dev/null +++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/ServiceCenterDeploy.java @@ -0,0 +1,96 @@ +/* + * 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.it.deploy; + +import java.io.File; +import java.io.IOException; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.SystemUtils; +import org.apache.servicecomb.serviceregistry.api.registry.ServiceCenterInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.client.RestTemplate; + +import io.swagger.util.Json; + +public class ServiceCenterDeploy extends NormalDeploy { + private static final Logger LOGGER = LoggerFactory.getLogger(ServiceCenterDeploy.class); + + public ServiceCenterDeploy() { + super(new DeployDefinition()); + + deployDefinition.setDeployName("serviceCenter"); + deployDefinition.setDisplayName("serviceCenter"); + if (SystemUtils.IS_OS_WINDOWS) { + deployDefinition.setCmd("service-center.exe"); + } else { + deployDefinition.setCmd("service-center"); + } + deployDefinition.setStartCompleteLog("server is ready"); + } + + public void ensureReady() throws Throwable { + // check if is running + // {"version":"1.0.0","buildTag":"20180608145515.1.0.0.b913a2d","runMode":"dev","apiVersion":"3.0.0"} + try { + String address = "http://localhost:30100/version"; + ServiceCenterInfo serviceCenterInfo = new RestTemplate().getForObject(address, ServiceCenterInfo.class); + if (serviceCenterInfo != null && serviceCenterInfo.getVersion() != null) { + LOGGER.info("{} already started, {}.", deployDefinition.getDisplayName(), Json.pretty(serviceCenterInfo)); + return; + } + } catch (Throwable e) { + LOGGER.info("failed to get ServiceCenter version, message={}", e.getMessage()); + } + + initServiceCenterCmd(); + LOGGER.info("definition of {} is: {}", deployDefinition.getDeployName(), deployDefinition); + + deploy(); + waitStartComplete(); + } + + protected void initServiceCenterCmd() throws IOException { + // where is service center + // 1.find from env, for local dev environment + LOGGER.info("try to find serviceCenter by env {}.", "serviceCenterHome"); + String dir = System.getenv("serviceCenterHome"); + if (dir != null) { + LOGGER.info("serviceCenterHome={}.", dir); + File file = new File(dir, deployDefinition.getCmd()); + if (file.exists()) { + FileUtils.cleanDirectory(new File(dir, "data")); + deployDefinition.setWorkDir(dir); + deployDefinition.setCmd(file.getAbsolutePath()); + return; + } + + LOGGER.info("{} is not exist.", file.getAbsolutePath()); + } + + // 2.docker, for CI environment + LOGGER.info("can not find serviceCenter by env {}, try run by docker.", "serviceCenterHome"); + deployDefinition.setCmd("docker"); + deployDefinition.setArgs(new String[] { + "run", + "-p", + "127.0.0.1:30100:30100", + "servicecomb/service-center" + }); + } +} diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/SubProcessLogger.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/SubProcessLogger.java index 0189eefde..86d7f6945 100644 --- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/SubProcessLogger.java +++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/deploy/SubProcessLogger.java @@ -22,7 +22,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.util.concurrent.TimeUnit; +import org.apache.servicecomb.it.ITUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,8 +37,13 @@ private Thread thread; - public SubProcessLogger(String displayName, InputStream inputStream) { + private String startCompleteLog; + + private volatile boolean startCompleted; + + public SubProcessLogger(String displayName, InputStream inputStream, String startCompleteLog) { this.displayName = displayName; + this.startCompleteLog = startCompleteLog; BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream); this.reader = new BufferedReader(new InputStreamReader(bufferedInputStream)); @@ -58,6 +65,37 @@ private void doRun() throws IOException { while ((line = reader.readLine()) != null) { System.out.print(String.format("[%s] ", displayName)); System.out.println(line); + + checkStartComplete(line); + } + } + + private void checkStartComplete(String line) { + if (startCompleted || startCompleteLog == null) { + return; + } + + startCompleted = line.contains(startCompleteLog); + } + + public boolean isStartCompleted() { + return startCompleted; + } + + public void waitStartComplete() { + if (startCompleteLog == null) { + throw new IllegalStateException( + String.format("[%s] not set startCompleteLog, can not wait start complete.", displayName)); + } + + LOGGER.info("waiting {} start.", displayName); + for (; ; ) { + if (startCompleted) { + LOGGER.info("{} start completed.", displayName); + return; + } + + ITUtils.forceWait(TimeUnit.MILLISECONDS, 500); } } diff --git a/integration-tests/it-consumer/src/test/java/org/apache/servicecomb/it/TestMain.java b/integration-tests/it-consumer/src/test/java/org/apache/servicecomb/it/TestMain.java index 62c8a822a..ce4b42f88 100644 --- a/integration-tests/it-consumer/src/test/java/org/apache/servicecomb/it/TestMain.java +++ b/integration-tests/it-consumer/src/test/java/org/apache/servicecomb/it/TestMain.java @@ -16,13 +16,15 @@ */ package org.apache.servicecomb.it; +import org.apache.servicecomb.it.junit.ITJUnitUtils; +import org.junit.Assert; import org.junit.Test; public class TestMain { @Test - public void testMain() { -// ConsumerMain.autoExit = false; -// ConsumerMain.main(new String[] {}); -// Assert.assertTrue(ITJUnitUtils.getFailures().isEmpty()); + public void testMain() throws Throwable { + ConsumerMain.autoExit = false; + ConsumerMain.main(new String[] {}); + Assert.assertTrue(ITJUnitUtils.getFailures().isEmpty()); } } diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 9089eef5d..9ec78a84d 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -187,7 +187,7 @@ <manifest> <classpathLayoutType>repository</classpathLayoutType> <addClasspath>true</addClasspath> - <classpathPrefix>/${settings.localRepository}/</classpathPrefix> + <classpathPrefix>file:///${settings.localRepository}/</classpathPrefix> <mainClass>${it.main}</mainClass> </manifest> <manifestEntries> ---------------------------------------------------------------- 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 > run it-consumer during travis CI > --------------------------------- > > Key: SCB-793 > URL: https://issues.apache.org/jira/browse/SCB-793 > Project: Apache ServiceComb > Issue Type: Sub-task > Components: Java-Chassis > Reporter: wujimin > Assignee: wujimin > Priority: Major > Fix For: java-chassis-1.1.0 > > -- This message was sent by Atlassian JIRA (v7.6.3#76005)