You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by il...@apache.org on 2019/06/25 06:17:53 UTC
[dubbo-samples] branch master updated: integration test for
dubbo-samples-servicelevel-override
This is an automated email from the ASF dual-hosted git repository.
iluo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-samples.git
The following commit(s) were added to refs/heads/master by this push:
new 0718380 integration test for dubbo-samples-servicelevel-override
0718380 is described below
commit 0718380a80d6c1ff5d5436461d3f00d207c5763a
Author: Ian Luo <ia...@gmail.com>
AuthorDate: Tue Jun 25 14:16:48 2019 +0800
integration test for dubbo-samples-servicelevel-override
---
.../dubbo-samples-servicelevel-override/pom.xml | 404 ++++++++-------------
.../dubbo/samples/governance/BasicConsumer.java | 20 +-
.../dubbo/samples/governance/BasicProvider.java | 8 +-
.../samples/governance/EmbeddedZooKeeper.java | 250 -------------
.../apache/dubbo/samples/governance/ZKTools.java | 58 ++-
.../dubbo/samples/governance/api/DemoService.java | 2 +-
.../samples/governance/impl/DemoServiceImpl.java | 4 +-
.../main/resources/spring/dubbo-demo-consumer.xml | 14 +-
.../main/resources/spring/dubbo-demo-provider.xml | 17 +-
.../dubbo/samples/governance/DemoServiceIT.java | 82 +++++
10 files changed, 295 insertions(+), 564 deletions(-)
diff --git a/dubbo-samples-governance/dubbo-samples-servicelevel-override/pom.xml b/dubbo-samples-governance/dubbo-samples-servicelevel-override/pom.xml
index 6aef034..d0994a3 100644
--- a/dubbo-samples-governance/dubbo-samples-servicelevel-override/pom.xml
+++ b/dubbo-samples-governance/dubbo-samples-servicelevel-override/pom.xml
@@ -31,301 +31,183 @@
<properties>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
+ <dubbo.version>2.7.2</dubbo.version>
<spring.version>4.3.16.RELEASE</spring.version>
- <dubbo.version>2.7.0</dubbo.version>
- <dubbo.rpc.version>2.7.0</dubbo.rpc.version>
- <zookeeper.version>3.4.13</zookeeper.version>
- <curator.version>4.0.1</curator.version>
- <validation-api.version>1.1.0.Final</validation-api.version>
- <hibernate-validator.version>4.2.0.Final</hibernate-validator.version>
- <resteasy.version>3.0.19.Final</resteasy.version>
- <curator-client.version>4.0.1</curator-client.version>
- <swagger.version>1.5.19</swagger.version>
- <tomcat.version>7.0.88</tomcat.version>
- <servlet.version>3.0.1</servlet.version>
- <maven_checkstyle_version>3.0.0</maven_checkstyle_version>
- <apache-rat-plugin.version>0.12</apache-rat-plugin.version>
- <spring-boot.version>1.5.13.RELEASE</spring-boot.version>
+ <junit.version>4.12</junit.version>
+ <docker-maven-plugin.version>0.30.0</docker-maven-plugin.version>
+ <jib-maven-plugin.version>1.2.0</jib-maven-plugin.version>
+ <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
+ <maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version>
+ <image.name>${artifactId}:${dubbo.version}</image.name>
+ <dubbo.port>20880</dubbo.port>
+ <zookeeper.port>2181</zookeeper.port>
+ <main-class>org.apache.dubbo.samples.governance.BasicProvider</main-class>
</properties>
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-framework-bom</artifactId>
- <version>${spring.version}</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- <dependency>
- <!-- Import dependency management from Spring Boot -->
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-dependencies</artifactId>
- <version>${spring-boot.version}</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- <dependency>
- <groupId>io.netty</groupId>
- <artifactId>netty-all</artifactId>
- <version>4.1.16.Final</version>
- </dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-bom</artifactId>
- <version>${dubbo.version}</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo</artifactId>
- <version>${dubbo.version}</version>
- <exclusions>
- <exclusion>
- <groupId>org.apache.thrift</groupId>
- <artifactId>libthrift</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-rpc-rest</artifactId>
- <version>${dubbo.rpc.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.zookeeper</groupId>
- <artifactId>zookeeper</artifactId>
- <version>${zookeeper.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-framework</artifactId>
- <version>${curator.version}</version>
- <exclusions>
- <exclusion>
- <groupId>org.apache.zookeeper</groupId>
- <artifactId>zookeeper</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>javax.validation</groupId>
- <artifactId>validation-api</artifactId>
- <version>${validation-api.version}</version>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-validator</artifactId>
- <version>${hibernate-validator.version}</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jackson-provider</artifactId>
- <version>${resteasy.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-client</artifactId>
- <version>${curator-client.version}</version>
- <exclusions>
- <exclusion>
- <groupId>org.apache.zookeeper</groupId>
- <artifactId>zookeeper</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- <version>${servlet.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tomcat.embed</groupId>
- <artifactId>tomcat-embed-core</artifactId>
- <version>${tomcat.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tomcat.embed</groupId>
- <artifactId>tomcat-embed-logging-juli</artifactId>
- <version>${tomcat.version}</version>
- </dependency>
- <!-- swagger -->
- <dependency>
- <groupId>io.swagger</groupId>
- <artifactId>swagger-annotations</artifactId>
- <version>${swagger.version}</version>
- </dependency>
- <dependency>
- <groupId>io.swagger</groupId>
- <artifactId>swagger-jaxrs</artifactId>
- <version>${swagger.version}</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
<dependencies>
<dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-framework</artifactId>
- <exclusions>
- <exclusion>
- <groupId>io.netty</groupId>
- <artifactId>netty</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.apache.zookeeper</groupId>
- <artifactId>zookeeper</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.apache.zookeeper</groupId>
- <artifactId>zookeeper</artifactId>
- </dependency>
- <dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
+ <version>${dubbo.version}</version>
</dependency>
+
<dependency>
<groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-configcenter-zookeeper</artifactId>
- </dependency>
- <dependency>
- <groupId>io.netty</groupId>
- <artifactId>netty-all</artifactId>
+ <artifactId>dubbo-dependencies-zookeeper</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
</dependency>
+
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
</dependency>
+
<dependency>
<groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-configcenter-zookeeper</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-metadata-report-api</artifactId>
+ <artifactId>spring-test</artifactId>
+ <version>${spring.version}</version>
+ <scope>test</scope>
</dependency>
</dependencies>
-
-
- <build>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <version>${spring-boot.version}</version>
- </plugin>
- </plugins>
- </pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.7.0</version>
- <configuration>
- <source>${source.level}</source>
- <target>${target.level}</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.rat</groupId>
- <artifactId>apache-rat-plugin</artifactId>
- <version>${apache-rat-plugin.version}</version>
- <executions>
- <execution>
- <id>verify.rat</id>
- <phase>verify</phase>
- <goals>
- <goal>check</goal>
- </goals>
- <configuration>
- <excludes>
- <exclude>**/*.versionsBackup</exclude>
- <exclude>**/.idea/</exclude>
- <exclude>**/*.iml</exclude>
- <exclude>**/*.txt</exclude>
- <exclude>**/*.load</exclude>
- <exclude>**/*.flex</exclude>
- <exclude>**/*.fc</exclude>
- <exclude>**/*.javascript</exclude>
- <exclude>**/*.properties</exclude>
- <exclude>**/*.thrift</exclude>
- <exclude>**/*.sh</exclude>
- <exclude>**/*.bat</exclude>
- <exclude>**/*.md</exclude>
- <exclude>.git/</exclude>
- <exclude>.gitignore</exclude>
- <!-- ASF jenkins box puts the Maven repo in our root directory. -->
- <exclude>.repository/</exclude>
- <exclude>**/.settings/*</exclude>
- <exclude>**/.classpath</exclude>
- <exclude>**/.project</exclude>
- <exclude>**/target/**</exclude>
- <exclude>**/*.log</exclude>
- <exclude>CODE_OF_CONDUCT.md</exclude>
- <exclude>.codecov.yml</exclude>
- <exclude>.travis.yml</exclude>
- <exclude>PULL_REQUEST_TEMPLATE.md</exclude>
- <exclude>CONTRIBUTING.md</exclude>
- <exclude>README.md</exclude>
- <exclude>**/codestyle/*</exclude>
- <exclude>**/resources/META-INF/**</exclude>
- <exclude>**/webapp/swagger/**</exclude>
- <exclude>**/org/apache/dubbo/samples/rpc/nativethrift/api/DemoService.java</exclude>
- </excludes>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
<profiles>
<profile>
- <id>checkstyle</id>
- <activation>
- <jdk>[1.8,)</jdk>
- </activation>
+ <id>dubbo-integration-test</id>
<build>
<plugins>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-checkstyle-plugin</artifactId>
- <version>${maven_checkstyle_version}</version>
- <dependencies>
- <dependency>
- <groupId>com.puppycrawl.tools</groupId>
- <artifactId>checkstyle</artifactId>
- <version>8.9</version>
- </dependency>
- </dependencies>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-maven-address-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
<executions>
<execution>
- <id>checkstyle-validation</id>
- <phase>validate</phase>
+ <goals>
+ <goal>local-address</goal>
+ </goals>
<configuration>
- <configLocation>../../codestyle/checkstyle.xml</configLocation>
- <suppressionsLocation>../../codestyle/checkstyle-suppressions.xml</suppressionsLocation>
- <encoding>UTF-8</encoding>
- <consoleOutput>true</consoleOutput>
- <failOnViolation>true</failOnViolation>
+ <localAddress>dubbo-local-address</localAddress>
</configuration>
+ <phase>initialize</phase>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>com.google.cloud.tools</groupId>
+ <artifactId>jib-maven-plugin</artifactId>
+ <version>${jib-maven-plugin.version}</version>
+ <configuration>
+ <from>
+ <image>openjdk:8</image>
+ </from>
+ <to>
+ <image>${image.name}</image>
+ </to>
+ <container>
+ <mainClass>${main-class}</mainClass>
+ <environment>
+ <DUBBO_IP_TO_REGISTRY>${dubbo-local-address}</DUBBO_IP_TO_REGISTRY>
+ </environment>
+ <jvmFlags>
+ <jvmFlag>-Dzookeeper.address=${dubbo-local-address}</jvmFlag>
+ </jvmFlags>
+ </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>
+ <configuration>
+ <images>
+ <image>
+ <name>zookeeper:latest</name>
+ <run>
+ <ports>
+ <port>${zookeeper.port}:${zookeeper.port}</port>
+ </ports>
+ </run>
+ </image>
+ <image>
+ <name>${image.name}</name>
+ <run>
+ <ports>
+ <port>${dubbo.port}:${dubbo.port}</port>
+ </ports>
+ <wait>
+ <log>dubbo service started</log>
+ </wait>
+ </run>
+ </image>
+ </images>
+ </configuration>
+ <executions>
+ <execution>
+ <id>start</id>
+ <phase>pre-integration-test</phase>
<goals>
- <goal>check</goal>
+ <goal>start</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>stop</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <version>${maven-failsafe-plugin.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ <configuration>
+ <systemPropertyVariables>
+ <zookeeper.address>${dubbo-local-address}</zookeeper.address>
+ </systemPropertyVariables>
+ <includes>
+ <include>**/*IT.java</include>
+ </includes>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
</profile>
</profiles>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>${maven-compiler-plugin.version}</version>
+ <configuration>
+ <source>${source.level}</source>
+ <target>${target.level}</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java b/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java
index 1951c0d..781543e 100644
--- a/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java
+++ b/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java
@@ -20,27 +20,17 @@
package org.apache.dubbo.samples.governance;
import org.apache.dubbo.samples.governance.api.DemoService;
+
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class BasicConsumer {
public static void main(String[] args) {
- ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"spring/dubbo-demo-consumer.xml"});
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-consumer.xml");
context.start();
- DemoService demoService = (DemoService) context.getBean("demoService"); // get remote service proxy
-
- while (true) {
- try {
- Thread.sleep(1000);
- String hello = demoService.sayHello("world"); // call remote method
- System.out.println(hello); // get result
-
- } catch (Throwable throwable) {
- throwable.printStackTrace();
- }
-
-
- }
+ DemoService demoService = context.getBean("demoService", DemoService.class);
+ String hello = demoService.sayHello("world", 500);
+ System.out.println(hello);
}
}
diff --git a/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java b/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java
index 25c76e7..033bf62 100644
--- a/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java
+++ b/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java
@@ -21,14 +21,16 @@ package org.apache.dubbo.samples.governance;
import org.springframework.context.support.ClassPathXmlApplicationContext;
+import java.util.concurrent.CountDownLatch;
+
public class BasicProvider {
public static void main(String[] args) throws Exception {
-// new EmbeddedZooKeeper(2181, false).start();
- ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"spring/dubbo-demo-provider.xml"});
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-provider.xml");
context.start();
- System.in.read(); // press any key to exit
+ System.out.println("dubbo service started");
+ new CountDownLatch(1).await();
}
}
diff --git a/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/EmbeddedZooKeeper.java b/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/EmbeddedZooKeeper.java
deleted file mode 100644
index 87d6f1d..0000000
--- a/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/EmbeddedZooKeeper.java
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * Copyright 2014 the original author or authors.
- *
- * Licensed 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.samples.governance;
-
-import org.apache.zookeeper.server.ServerConfig;
-import org.apache.zookeeper.server.ZooKeeperServerMain;
-import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.context.SmartLifecycle;
-import org.springframework.util.ErrorHandler;
-import org.springframework.util.SocketUtils;
-
-import java.io.File;
-import java.lang.reflect.Method;
-import java.util.Properties;
-import java.util.UUID;
-
-/**
- * from: https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java
- * <p>
- * Helper class to start an embedded instance of standalone (non clustered) ZooKeeper.
- * <p>
- * NOTE: at least an external standalone server (if not an ensemble) are recommended, even for
- * {@link org.springframework.xd.dirt.server.singlenode.SingleNodeApplication}
- *
- * @author Patrick Peralta
- * @author Mark Fisher
- * @author David Turanski
- */
-public class EmbeddedZooKeeper implements SmartLifecycle {
-
- /**
- * Logger.
- */
- private static final Logger logger = LoggerFactory.getLogger(EmbeddedZooKeeper.class);
-
- /**
- * ZooKeeper client port. This will be determined dynamically upon startup.
- */
- private final int clientPort;
-
- /**
- * Whether to auto-start. Default is true.
- */
- private boolean autoStartup = true;
-
- /**
- * Lifecycle phase. Default is 0.
- */
- private int phase = 0;
-
- /**
- * Thread for running the ZooKeeper server.
- */
- private volatile Thread zkServerThread;
-
- /**
- * ZooKeeper server.
- */
- private volatile ZooKeeperServerMain zkServer;
-
- /**
- * {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread.
- */
- private ErrorHandler errorHandler;
-
- private boolean daemon = true;
-
- /**
- * Construct an EmbeddedZooKeeper with a random port.
- */
- public EmbeddedZooKeeper() {
- clientPort = SocketUtils.findAvailableTcpPort();
- }
-
- /**
- * Construct an EmbeddedZooKeeper with the provided port.
- *
- * @param clientPort port for ZooKeeper server to bind to
- */
- public EmbeddedZooKeeper(int clientPort, boolean daemon) {
- this.clientPort = clientPort;
- this.daemon = daemon;
- }
-
- /**
- * Returns the port that clients should use to connect to this embedded server.
- *
- * @return dynamically determined client port
- */
- public int getClientPort() {
- return this.clientPort;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean isAutoStartup() {
- return this.autoStartup;
- }
-
- /**
- * Specify whether to start automatically. Default is true.
- *
- * @param autoStartup whether to start automatically
- */
- public void setAutoStartup(boolean autoStartup) {
- this.autoStartup = autoStartup;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int getPhase() {
- return this.phase;
- }
-
- /**
- * Specify the lifecycle phase for the embedded server.
- *
- * @param phase the lifecycle phase
- */
- public void setPhase(int phase) {
- this.phase = phase;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean isRunning() {
- return (zkServerThread != null);
- }
-
- /**
- * Start the ZooKeeper server in a background thread.
- * <p>
- * Register an error handler via {@link #setErrorHandler} in order to handle
- * any exceptions thrown during startup or execution.
- */
- @Override
- public synchronized void start() {
- if (zkServerThread == null) {
- zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper Server Starter");
- zkServerThread.setDaemon(daemon);
- zkServerThread.start();
- }
- }
-
- /**
- * Shutdown the ZooKeeper server.
- */
- @Override
- public synchronized void stop() {
- if (zkServerThread != null) {
- // The shutdown method is protected...thus this hack to invoke it.
- // This will log an exception on shutdown; see
- // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for details.
- try {
- Method shutdown = ZooKeeperServerMain.class.getDeclaredMethod("shutdown");
- shutdown.setAccessible(true);
- shutdown.invoke(zkServer);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-
- // It is expected that the thread will exit after
- // the server is shutdown; this will block until
- // the shutdown is complete.
- try {
- zkServerThread.join(5000);
- zkServerThread = null;
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- logger.warn("Interrupted while waiting for embedded ZooKeeper to exit");
- // abandoning zk thread
- zkServerThread = null;
- }
- }
- }
-
- /**
- * Stop the server if running and invoke the callback when complete.
- */
- @Override
- public void stop(Runnable callback) {
- stop();
- callback.run();
- }
-
- /**
- * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread. If none
- * is provided, only error-level logging will occur.
- *
- * @param errorHandler the {@link ErrorHandler} to be invoked
- */
- public void setErrorHandler(ErrorHandler errorHandler) {
- this.errorHandler = errorHandler;
- }
-
- /**
- * Runnable implementation that starts the ZooKeeper server.
- */
- private class ServerRunnable implements Runnable {
-
- @Override
- public void run() {
- try {
- Properties properties = new Properties();
- File file = new File(System.getProperty("java.io.tmpdir")
- + File.separator + UUID.randomUUID());
- file.deleteOnExit();
- properties.setProperty("dataDir", file.getAbsolutePath());
- properties.setProperty("clientPort", String.valueOf(clientPort));
-
- QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
- quorumPeerConfig.parseProperties(properties);
-
- zkServer = new ZooKeeperServerMain();
- ServerConfig configuration = new ServerConfig();
- configuration.readFrom(quorumPeerConfig);
-
- zkServer.runFromConfig(configuration);
- } catch (Exception e) {
- if (errorHandler != null) {
- errorHandler.handleError(e);
- } else {
- logger.error("Exception running embedded ZooKeeper", e);
- }
- }
- }
- }
-
-}
\ No newline at end of file
diff --git a/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/ZKTools.java b/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/ZKTools.java
index 380b09b..353f6bf 100644
--- a/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/ZKTools.java
+++ b/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/ZKTools.java
@@ -22,28 +22,35 @@ import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
-/**
- *
- */
public class ZKTools {
+ private static String zookeeperHost = System.getProperty("zookeeper.address", "127.0.0.1");
private static CuratorFramework client;
public static void main(String[] args) throws Exception {
- client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", 60 * 1000, 60 * 1000,
+ initClient();
+ generateServiceLevelOverride(5000);
+ generateApplicationLevelOverride(2000);
+ }
+
+ public static void initClient() {
+ client = CuratorFrameworkFactory.newClient(zookeeperHost + ":2181", 60 * 1000, 60 * 1000,
new ExponentialBackoffRetry(6000, 3));
client.start();
-
- generateServiceLevelOverride();
- generateApplicationLevelOverride();
}
- public static void generateServiceLevelOverride() {
- String str = "# All Consumers that consume the service org.apache.dubbo.samples.governance.api.DemoService will increase the timeout value to 6000\n" + "---\n" + "configVersion: v2.7\n" +
+ public static void generateServiceLevelOverride(long timeout) {
+ String str = "" +
+ "# All Consumers that consume the service org.apache.dubbo.samples.governance.api.DemoService will increase the timeout value to 6000\n" +
+ "---\n" +
+ "configVersion: v2.7\n" +
"scope: service\n" +
"key: org.apache.dubbo.samples.governance.api.DemoService\n" +
"enabled: true\n" +
"configs:\n" +
- "- addresses: [0.0.0.0]\n" + " side: consumer\n" + " parameters:\n" + " timeout: 5000\n" +
+ "- addresses: [0.0.0.0]\n" +
+ " side: consumer\n" +
+ " parameters:\n" +
+ " timeout: " + timeout + "\n" +
"...\n";
System.out.println(str);
@@ -59,8 +66,20 @@ public class ZKTools {
}
}
- public static void generateApplicationLevelOverride() {
- String str = "# All Consumers that consume the service org.apache.dubbo.samples.governance.api.DemoService will increase the timeout value to 6000\n" + "---\n" + "configVersion: v2.7\n" + "scope: application\n" + "key: governance-serviceoverride-consumer\n" + "enabled: true\n" + "configs:\n" + "- addresses: [0.0.0.0]\n" + " side: consumer\n" + " parameters:\n" + " timeout: 2000\n" + "...\n";
+ public static void generateApplicationLevelOverride(long timeout) {
+ String str = "" +
+ "# All Consumers that consume the service org.apache.dubbo.samples.governance.api.DemoService will increase the timeout value to 6000\n" +
+ "---\n" +
+ "configVersion: v2.7\n" +
+ "scope: application\n" +
+ "key: governance-serviceoverride-consumer\n" +
+ "enabled: true\n" +
+ "configs:\n" +
+ "- addresses: [0.0.0.0]\n" +
+ " side: consumer\n" +
+ " parameters:\n" +
+ " timeout: " + timeout + "\n" +
+ "...\n";
System.out.println(str);
@@ -75,6 +94,21 @@ public class ZKTools {
}
}
+ public static void cleanup() {
+ try {
+ String path = "/dubbo/config/org.apache.dubbo.samples.governance.api.DemoService/configurators";
+ if (client.checkExists().forPath(path) != null) {
+ client.delete().forPath(path);
+ }
+ path = "/dubbo/config/governance-serviceoverride-consumer/configurators";
+ if (client.checkExists().forPath(path) != null) {
+ client.delete().forPath(path);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
private static void setData(String path, String data) throws Exception {
client.setData().forPath(path, data.getBytes());
}
diff --git a/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java b/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java
index bde5f6e..957c601 100644
--- a/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java
+++ b/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java
@@ -21,6 +21,6 @@ package org.apache.dubbo.samples.governance.api;
public interface DemoService {
- String sayHello(String name);
+ String sayHello(String name, long millis);
}
diff --git a/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java b/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java
index e1f0348..8be2656 100644
--- a/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java
+++ b/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java
@@ -25,9 +25,9 @@ import org.apache.dubbo.samples.governance.api.DemoService;
public class DemoServiceImpl implements DemoService {
@Override
- public String sayHello(String name) {
+ public String sayHello(String name, long millis) {
try {
- Thread.sleep(3000);
+ Thread.sleep(millis);
} catch (InterruptedException e) {
e.printStackTrace();
}
diff --git a/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/resources/spring/dubbo-demo-consumer.xml b/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/resources/spring/dubbo-demo-consumer.xml
index 6bb289e..1c82dc4 100644
--- a/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/resources/spring/dubbo-demo-consumer.xml
+++ b/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/resources/spring/dubbo-demo-consumer.xml
@@ -20,21 +20,17 @@
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
- xmlns="http://www.springframework.org/schema/beans"
+ xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
+ http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
+ <context:property-placeholder/>
- <!-- optional, consumer's application name, used for tracing dependency relationship (not a matching criterion),
- don't set it same as provider -->
<dubbo:application name="governance-serviceoverride-consumer"/>
- <!-- optional, use multicast registry center to discover service -->
- <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
+ <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
- <dubbo:config-center address="zookeeper://127.0.0.1:2181"/>
+ <dubbo:config-center address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
- <!-- generate proxy for the remote service, then demoService can be used in the same way as the
- local regular interface -->
<dubbo:reference timeout="1000" id="demoService" check="false"
interface="org.apache.dubbo.samples.governance.api.DemoService"/>
diff --git a/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/resources/spring/dubbo-demo-provider.xml b/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/resources/spring/dubbo-demo-provider.xml
index 63d49ef..ffe2005 100644
--- a/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/resources/spring/dubbo-demo-provider.xml
+++ b/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/resources/spring/dubbo-demo-provider.xml
@@ -20,23 +20,18 @@
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
- xmlns="http://www.springframework.org/schema/beans"
+ xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
+ http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
+ <context:property-placeholder/>
- <!-- optional provider's application name, used for tracing dependency relationship -->
<dubbo:application name="governance-serviceoverride-provider"/>
- <!-- optional -->
- <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
+ <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
- <!--optional, use dubbo protocol to export service on port 20880 -->
- <dubbo:protocol name="dubbo" port="20890"/>
+ <dubbo:protocol name="dubbo" port="20880"/>
- <!-- service implementation, as same as regular local bean -->
<bean id="demoService" class="org.apache.dubbo.samples.governance.impl.DemoServiceImpl"/>
- <!-- declare the service interface to be exported -->
- <dubbo:service tag="" interface="org.apache.dubbo.samples.governance.api.DemoService" ref="demoService"/>
-
+ <dubbo:service interface="org.apache.dubbo.samples.governance.api.DemoService" ref="demoService"/>
</beans>
diff --git a/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/test/java/org/apache/dubbo/samples/governance/DemoServiceIT.java b/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/test/java/org/apache/dubbo/samples/governance/DemoServiceIT.java
new file mode 100644
index 0000000..699425e
--- /dev/null
+++ b/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/test/java/org/apache/dubbo/samples/governance/DemoServiceIT.java
@@ -0,0 +1,82 @@
+/*
+ * 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.samples.governance;
+
+import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.samples.governance.api.DemoService;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:/spring/dubbo-demo-consumer.xml"})
+public class DemoServiceIT {
+ @Autowired
+ private DemoService demoService;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ ZKTools.initClient();
+ }
+
+ @Before
+ public void cleanAllRules() throws Exception {
+ ZKTools.cleanup();
+ }
+
+ @Test(expected = RpcException.class)
+ public void testWithoutRule() throws Exception {
+ Thread.sleep(2000);
+ demoService.sayHello("world", 3000);
+ }
+
+ @Test(expected = RpcException.class)
+ public void testWithServiceRuleWithInsufficientTimeout() throws Exception {
+ ZKTools.generateServiceLevelOverride(600);
+ Thread.sleep(2000);
+ demoService.sayHello("world", 1000);
+ }
+
+ @Test
+ public void testWithServiceRuleWithSufficientTimeout() throws Exception {
+ ZKTools.generateServiceLevelOverride(6000);
+ Thread.sleep(2000);
+ Assert.assertTrue(demoService.sayHello("world", 1000).startsWith("Hello world"));
+ }
+
+ @Test(expected = RpcException.class)
+ public void testWithAppRuleWithInsufficientTimeout() throws Exception {
+ ZKTools.generateApplicationLevelOverride(600);
+ Thread.sleep(2000);
+ demoService.sayHello("world", 1000);
+ }
+
+ @Test
+ public void testWithAppRuleWithSufficientTimeout() throws Exception {
+ ZKTools.generateApplicationLevelOverride(6000);
+ Thread.sleep(2000);
+ Assert.assertTrue(demoService.sayHello("world", 1000).startsWith("Hello world"));
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org