From 2256293789f5e7bb4b772fac9d9abf1ec09da73e Mon Sep 17 00:00:00 2001 From: Huang YunKun Date: Wed, 8 Jul 2020 10:01:04 +0800 Subject: [PATCH] add consumer for integration test (#632) --- .github/workflows/integration.yml | 8 +- dubbo-admin-test/pom.xml | 127 ++++++++++++++---- .../apache/dubbo/admin/ConsumerBootstrap.java | 71 ++++++++++ .../apache/dubbo/admin/ProviderBootstrap.java | 2 +- .../consumer/AnnotatedGreetingService.java | 33 +++++ .../admin/impl/consumer/RestApiService.java | 74 ++++++++++ .../AnnotatedGreetingService.java | 2 +- .../spring/dubbo-consumer.properties | 21 +++ .../java/org/apache/dubbo/admin/BaseIT.java | 47 +++++++ .../java/org/apache/dubbo/admin/LoginIT.java | 4 +- 10 files changed, 360 insertions(+), 29 deletions(-) create mode 100644 dubbo-admin-test/src/main/java/org/apache/dubbo/admin/ConsumerBootstrap.java create mode 100644 dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/consumer/AnnotatedGreetingService.java create mode 100644 dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/consumer/RestApiService.java rename dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/{ => provider}/AnnotatedGreetingService.java (96%) create mode 100644 dubbo-admin-test/src/main/resources/spring/dubbo-consumer.properties create mode 100644 dubbo-admin-test/src/test/java/org/apache/dubbo/admin/BaseIT.java diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 9df45ca81..54c2ab613 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -12,7 +12,13 @@ jobs: run: cp docker/latest/** ./ - name: Docker build run: docker build -t apache/dubbo-admin-integration:latest . + - name: Build provider and consumer image + run: ./mvnw --batch-mode --projects dubbo-admin-test --activate-profiles build-provider package && ./mvnw --batch-mode --projects dubbo-admin-test --activate-profiles build-consumer package - name: Setup xvfb run: sudo apt-get install xvfb - name: Run integration test - run: xvfb-run --server-args="-screen 0, 1024x768x24" ./mvnw --batch-mode --projects dubbo-admin-test --activate-profiles dubbo-admin-integration-test -Ddocker.showLogs=true docker:stop docker:remove verify \ No newline at end of file + run: xvfb-run --server-args="-screen 0, 1024x768x24" ./mvnw --batch-mode --projects dubbo-admin-test --activate-profiles dubbo-admin-integration-test -Ddocker.showLogs=true docker:stop docker:remove verify + - uses: actions/upload-artifact@v2 + with: + name: screenshots + path: dubbo-admin-test/target/screens/ \ No newline at end of file diff --git a/dubbo-admin-test/pom.xml b/dubbo-admin-test/pom.xml index ab6a447d4..e9bf90a87 100644 --- a/dubbo-admin-test/pom.xml +++ b/dubbo-admin-test/pom.xml @@ -83,6 +83,30 @@ 29.0-jre + + com.sun.jersey + jersey-servlet + 1.19.4 + + + + com.sun.jersey + jersey-json + 1.19.4 + + + + com.sun.jersey + jersey-client + 1.19.4 + + + + org.eclipse.jetty.aggregate + jetty-all-server + 8.2.0.v20160908 + + junit junit @@ -151,6 +175,7 @@ zookeeper.port dubbo-admin.port + rest.api.port @@ -177,31 +202,6 @@ - - com.google.cloud.tools - jib-maven-plugin - ${jib-maven-plugin.version} - - - ${java-image.name} - - - ${provider.image.name} - - - org.apache.dubbo.admin.ProviderBootstrap - - - - - package - - dockerBuild - - - - - io.fabric8 docker-maven-plugin @@ -263,6 +263,21 @@ + + dubbo-admin-consumer + ${consumer.image.name} + + dubbo-admin-provider + + zookeeper://${local.ip}:${zookeeper.port} + + ${rest.api.port} + + + dubbo service init finish + + + @@ -307,6 +322,68 @@ + + build-provider + + + + com.google.cloud.tools + jib-maven-plugin + ${jib-maven-plugin.version} + + + ${java-image.name} + + + ${provider.image.name} + + + org.apache.dubbo.admin.ProviderBootstrap + + + + + package + + dockerBuild + + + + + + + + + build-consumer + + + + com.google.cloud.tools + jib-maven-plugin + ${jib-maven-plugin.version} + + + ${java-image.name} + + + ${consumer.image.name} + + + org.apache.dubbo.admin.ConsumerBootstrap + + + + + package + + dockerBuild + + + + + + + diff --git a/dubbo-admin-test/src/main/java/org/apache/dubbo/admin/ConsumerBootstrap.java b/dubbo-admin-test/src/main/java/org/apache/dubbo/admin/ConsumerBootstrap.java new file mode 100644 index 000000000..5401639f0 --- /dev/null +++ b/dubbo-admin-test/src/main/java/org/apache/dubbo/admin/ConsumerBootstrap.java @@ -0,0 +1,71 @@ +/* + * + * 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.dubbo.admin; + + +import com.sun.jersey.spi.container.servlet.ServletContainer; +import org.apache.dubbo.admin.impl.consumer.RestApiService; +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +public class ConsumerBootstrap { + public static void main(String[] args) throws Exception { + int port = 8282; + try { + port = Integer.parseInt(System.getenv("rest.api.port")); + } catch (Exception ex) { + //ignore + } + + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerBootstrap.ConsumerConfiguration.class); + context.start(); + + + RestApiService.applicationContext = context; + + Server server = new Server(port); + ServletHolder servlet = new ServletHolder(ServletContainer.class); + + servlet.setInitParameter("com.sun.jersey.config.property.packages", "org.apache.dubbo.admin.impl.consumer"); + servlet.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true"); + + ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS); + handler.setContextPath("/"); + handler.addServlet(servlet, "/*"); + server.setHandler(handler); + server.start(); + + System.out.println("dubbo service init finish"); + } + + + @Configuration + @EnableDubbo(scanBasePackages = "org.apache.dubbo.admin.impl.consumer") + @ComponentScan(basePackages = "org.apache.dubbo.admin.impl.consumer") + @PropertySource("classpath:/spring/dubbo-consumer.properties") + public static class ConsumerConfiguration { + } + +} diff --git a/dubbo-admin-test/src/main/java/org/apache/dubbo/admin/ProviderBootstrap.java b/dubbo-admin-test/src/main/java/org/apache/dubbo/admin/ProviderBootstrap.java index bfcbd0c2a..309fb8d9d 100644 --- a/dubbo-admin-test/src/main/java/org/apache/dubbo/admin/ProviderBootstrap.java +++ b/dubbo-admin-test/src/main/java/org/apache/dubbo/admin/ProviderBootstrap.java @@ -43,7 +43,7 @@ public static void main(String[] args) throws Exception { } @Configuration - @EnableDubbo(scanBasePackages = "org.apache.dubbo.admin.impl") + @EnableDubbo(scanBasePackages = "org.apache.dubbo.admin.impl.provider") @PropertySource("classpath:/spring/dubbo-provider.properties") static class ProviderConfiguration { @Value("${dubbo.config-center.address}") diff --git a/dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/consumer/AnnotatedGreetingService.java b/dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/consumer/AnnotatedGreetingService.java new file mode 100644 index 000000000..3673a5cd3 --- /dev/null +++ b/dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/consumer/AnnotatedGreetingService.java @@ -0,0 +1,33 @@ +/* + * + * 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.dubbo.admin.impl.consumer; + +import org.apache.dubbo.admin.api.GreetingService; +import org.apache.dubbo.config.annotation.DubboReference; +import org.springframework.stereotype.Service; + +@Service +public class AnnotatedGreetingService { + @DubboReference(version = "1.0.0") + private GreetingService greetingService; + + public String sayHello(String name) { + return greetingService.sayHello(name); + } +} diff --git a/dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/consumer/RestApiService.java b/dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/consumer/RestApiService.java new file mode 100644 index 000000000..4af2fd69b --- /dev/null +++ b/dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/consumer/RestApiService.java @@ -0,0 +1,74 @@ +/* + * + * 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.dubbo.admin.impl.consumer; + +import org.springframework.context.ApplicationContext; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +@Path("/") +public class RestApiService { + public static ApplicationContext applicationContext; + + @Path("/checkAlive") + @GET + @Produces(MediaType.APPLICATION_JSON) + public CommonResult alive() { + return CommonResult.success("OK"); + } + + @Path("/hello") + @GET + @Produces(MediaType.APPLICATION_JSON) // 声明这个接口将以json格式返回 + public CommonResult hello(@QueryParam("name") String name) { + return CommonResult.success(applicationContext.getBean(AnnotatedGreetingService.class).sayHello(name)); + } + + public static class CommonResult { + private Object data; + private int code; + + public static CommonResult success(Object object) { + CommonResult result = new CommonResult(); + result.data = object; + result.code = 1; + return result; + } + + public Object getData() { + return data; + } + + public void setData(Object data) { + this.data = data; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + } +} diff --git a/dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/AnnotatedGreetingService.java b/dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/provider/AnnotatedGreetingService.java similarity index 96% rename from dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/AnnotatedGreetingService.java rename to dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/provider/AnnotatedGreetingService.java index d6c011543..eeb5d8350 100644 --- a/dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/AnnotatedGreetingService.java +++ b/dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/provider/AnnotatedGreetingService.java @@ -17,7 +17,7 @@ * */ -package org.apache.dubbo.admin.impl; +package org.apache.dubbo.admin.impl.provider; import org.apache.dubbo.admin.api.GreetingService; import org.apache.dubbo.config.annotation.DubboService; diff --git a/dubbo-admin-test/src/main/resources/spring/dubbo-consumer.properties b/dubbo-admin-test/src/main/resources/spring/dubbo-consumer.properties new file mode 100644 index 000000000..42b088ffa --- /dev/null +++ b/dubbo-admin-test/src/main/resources/spring/dubbo-consumer.properties @@ -0,0 +1,21 @@ +# +# +# 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. +# +# + +dubbo.application.name=dubbo-admin-integration-consumer +dubbo.config-center.address=zookeeper://localhost:2181 diff --git a/dubbo-admin-test/src/test/java/org/apache/dubbo/admin/BaseIT.java b/dubbo-admin-test/src/test/java/org/apache/dubbo/admin/BaseIT.java new file mode 100644 index 000000000..cfe11c39a --- /dev/null +++ b/dubbo-admin-test/src/test/java/org/apache/dubbo/admin/BaseIT.java @@ -0,0 +1,47 @@ +/* + * + * 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.dubbo.admin; + +import org.apache.commons.io.FileUtils; +import org.openqa.selenium.OutputType; +import org.openqa.selenium.TakesScreenshot; +import org.openqa.selenium.WebDriver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; + +public class BaseIT { + private Logger logger = LoggerFactory.getLogger(this.getClass()); + + public void takeShot(WebDriver webDriver, String name) { + TakesScreenshot scrShot = ((TakesScreenshot) webDriver); + + File SrcFile = scrShot.getScreenshotAs(OutputType.FILE); + + File DestFile = new File("target/screens/" + name + ".png"); + + try { + FileUtils.copyFile(SrcFile, DestFile); + } catch (IOException e) { + logger.info("#takeShot# take shot fail", e); + } + } +} diff --git a/dubbo-admin-test/src/test/java/org/apache/dubbo/admin/LoginIT.java b/dubbo-admin-test/src/test/java/org/apache/dubbo/admin/LoginIT.java index 75867989c..62be59603 100644 --- a/dubbo-admin-test/src/test/java/org/apache/dubbo/admin/LoginIT.java +++ b/dubbo-admin-test/src/test/java/org/apache/dubbo/admin/LoginIT.java @@ -30,7 +30,7 @@ import java.util.concurrent.TimeUnit; -public class LoginIT { +public class LoginIT extends BaseIT { private static WebDriver driver; private static FluentWebDriver fwd; private static String BASE_URL; @@ -60,6 +60,8 @@ public void shouldOpenLogin() { fwd.input(By.name("username")).sendKeys("root"); fwd.input(By.cssSelector("input[type='password']")).sendKeys("root"); + this.takeShot(driver, "login"); + fwd.button(By.tagName("button")).click(); }