You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by hy...@apache.org on 2020/07/08 02:02:20 UTC
[dubbo-admin] branch develop updated: add consumer for integration
test (#632)
This is an automated email from the ASF dual-hosted git repository.
hyunkun pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-admin.git
The following commit(s) were added to refs/heads/develop by this push:
new 2256293 add consumer for integration test (#632)
2256293 is described below
commit 2256293789f5e7bb4b772fac9d9abf1ec09da73e
Author: Huang YunKun <ht...@gmail.com>
AuthorDate: Wed Jul 8 10:01:04 2020 +0800
add consumer for integration test (#632)
---
.github/workflows/integration.yml | 8 +-
dubbo-admin-test/pom.xml | 127 +++++++++++++++++----
.../org/apache/dubbo/admin/ConsumerBootstrap.java | 71 ++++++++++++
.../org/apache/dubbo/admin/ProviderBootstrap.java | 2 +-
.../{ => consumer}/AnnotatedGreetingService.java | 16 +--
.../dubbo/admin/impl/consumer/RestApiService.java | 74 ++++++++++++
.../{ => provider}/AnnotatedGreetingService.java | 2 +-
.../resources/spring/dubbo-consumer.properties | 21 ++++
.../java/org/apache/dubbo/admin/BaseIT.java} | 32 ++++--
.../test/java/org/apache/dubbo/admin/LoginIT.java | 4 +-
10 files changed, 313 insertions(+), 44 deletions(-)
diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml
index 9df45ca..54c2ab6 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 ab6a447..e9bf90a 100644
--- a/dubbo-admin-test/pom.xml
+++ b/dubbo-admin-test/pom.xml
@@ -84,6 +84,30 @@
</dependency>
<dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-servlet</artifactId>
+ <version>1.19.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-json</artifactId>
+ <version>1.19.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-client</artifactId>
+ <version>1.19.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.jetty.aggregate</groupId>
+ <artifactId>jetty-all-server</artifactId>
+ <version>8.2.0.v20160908</version>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
@@ -151,6 +175,7 @@
<portNames>
<portName>zookeeper.port</portName>
<portName>dubbo-admin.port</portName>
+ <portName>rest.api.port</portName>
</portNames>
</configuration>
</execution>
@@ -178,31 +203,6 @@
</plugin>
<plugin>
- <groupId>com.google.cloud.tools</groupId>
- <artifactId>jib-maven-plugin</artifactId>
- <version>${jib-maven-plugin.version}</version>
- <configuration>
- <from>
- <image>${java-image.name}</image>
- </from>
- <to>
- <image>${provider.image.name}</image>
- </to>
- <container>
- <mainClass>org.apache.dubbo.admin.ProviderBootstrap</mainClass>
- </container>
- </configuration>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>dockerBuild</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
-
- <plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker-maven-plugin.version}</version>
@@ -263,6 +263,21 @@
</wait>
</run>
</image>
+ <image>
+ <alias>dubbo-admin-consumer</alias>
+ <name>${consumer.image.name}</name>
+ <run>
+ <dependsOn>dubbo-admin-provider</dependsOn>
+ <env>
+ <dubbo.config-center.address>zookeeper://${local.ip}:${zookeeper.port}
+ </dubbo.config-center.address>
+ <rest.api.port>${rest.api.port}</rest.api.port>
+ </env>
+ <wait>
+ <log>dubbo service init finish</log>
+ </wait>
+ </run>
+ </image>
</images>
</configuration>
<executions>
@@ -307,6 +322,68 @@
</plugins>
</build>
</profile>
+ <profile>
+ <id>build-provider</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>com.google.cloud.tools</groupId>
+ <artifactId>jib-maven-plugin</artifactId>
+ <version>${jib-maven-plugin.version}</version>
+ <configuration>
+ <from>
+ <image>${java-image.name}</image>
+ </from>
+ <to>
+ <image>${provider.image.name}</image>
+ </to>
+ <container>
+ <mainClass>org.apache.dubbo.admin.ProviderBootstrap</mainClass>
+ </container>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>dockerBuild</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
+ <id>build-consumer</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>com.google.cloud.tools</groupId>
+ <artifactId>jib-maven-plugin</artifactId>
+ <version>${jib-maven-plugin.version}</version>
+ <configuration>
+ <from>
+ <image>${java-image.name}</image>
+ </from>
+ <to>
+ <image>${consumer.image.name}</image>
+ </to>
+ <container>
+ <mainClass>org.apache.dubbo.admin.ConsumerBootstrap</mainClass>
+ </container>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>dockerBuild</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
</profiles>
<build>
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 0000000..5401639
--- /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 bfcbd0c..309fb8d 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 class ProviderBootstrap {
}
@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/AnnotatedGreetingService.java b/dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/consumer/AnnotatedGreetingService.java
similarity index 73%
copy from dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/AnnotatedGreetingService.java
copy to dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/consumer/AnnotatedGreetingService.java
index d6c0115..3673a5c 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/consumer/AnnotatedGreetingService.java
@@ -16,16 +16,18 @@
* limitations under the License.
*
*/
-
-package org.apache.dubbo.admin.impl;
+package org.apache.dubbo.admin.impl.consumer;
import org.apache.dubbo.admin.api.GreetingService;
-import org.apache.dubbo.config.annotation.DubboService;
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.springframework.stereotype.Service;
+
+@Service
+public class AnnotatedGreetingService {
+ @DubboReference(version = "1.0.0")
+ private GreetingService greetingService;
-@DubboService(version = "1.0.0")
-public class AnnotatedGreetingService implements GreetingService {
public String sayHello(String name) {
- System.out.println("greeting service received: " + name);
- return "hello, " + 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 0000000..4af2fd6
--- /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%
copy from dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/AnnotatedGreetingService.java
copy to dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/provider/AnnotatedGreetingService.java
index d6c0115..eeb5d83 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 0000000..42b088f
--- /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/main/java/org/apache/dubbo/admin/impl/AnnotatedGreetingService.java b/dubbo-admin-test/src/test/java/org/apache/dubbo/admin/BaseIT.java
similarity index 50%
rename from dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/AnnotatedGreetingService.java
rename to dubbo-admin-test/src/test/java/org/apache/dubbo/admin/BaseIT.java
index d6c0115..cfe11c3 100644
--- a/dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/AnnotatedGreetingService.java
+++ b/dubbo-admin-test/src/test/java/org/apache/dubbo/admin/BaseIT.java
@@ -16,16 +16,32 @@
* limitations under the License.
*
*/
+package org.apache.dubbo.admin;
-package org.apache.dubbo.admin.impl;
+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 org.apache.dubbo.admin.api.GreetingService;
-import org.apache.dubbo.config.annotation.DubboService;
+import java.io.File;
+import java.io.IOException;
-@DubboService(version = "1.0.0")
-public class AnnotatedGreetingService implements GreetingService {
- public String sayHello(String name) {
- System.out.println("greeting service received: " + name);
- return "hello, " + name;
+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 7586798..62be596 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 org.seleniumhq.selenium.fluent.FluentWebDriver;
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 class LoginIT {
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();
}