Skip to content

Commit

Permalink
add consumer for integration test (apache#632)
Browse files Browse the repository at this point in the history
  • Loading branch information
htynkn authored Jul 8, 2020
1 parent bfae584 commit 2256293
Show file tree
Hide file tree
Showing 10 changed files with 360 additions and 29 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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/
127 changes: 102 additions & 25 deletions dubbo-admin-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,30 @@
<version>29.0-jre</version>
</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>
Expand Down Expand Up @@ -151,6 +175,7 @@
<portNames>
<portName>zookeeper.port</portName>
<portName>dubbo-admin.port</portName>
<portName>rest.api.port</portName>
</portNames>
</configuration>
</execution>
Expand All @@ -177,31 +202,6 @@
</executions>
</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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 2256293

Please sign in to comment.