You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by hu...@apache.org on 2019/04/26 06:16:56 UTC
[incubator-dubbo] branch master updated: etcd3 integration test api
(#3887)
This is an automated email from the ASF dual-hosted git repository.
huxing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new 2d0c07d etcd3 integration test api (#3887)
2d0c07d is described below
commit 2d0c07d84dac9c6750d307d3a4ec47c4c88c1fef
Author: myPrecious <Mo...@users.noreply.github.com>
AuthorDate: Fri Apr 26 14:16:50 2019 +0800
etcd3 integration test api (#3887)
* etcd config center integrate test
* clean code
---
dubbo-configcenter/dubbo-configcenter-etcd/pom.xml | 10 +++
.../support/etcd/EtcdDynamicConfigurationTest.java | 76 +++++++++++++---------
dubbo-dependencies-bom/pom.xml | 13 ++++
3 files changed, 67 insertions(+), 32 deletions(-)
diff --git a/dubbo-configcenter/dubbo-configcenter-etcd/pom.xml b/dubbo-configcenter/dubbo-configcenter-etcd/pom.xml
index 2eb1e35..66d2dfa 100644
--- a/dubbo-configcenter/dubbo-configcenter-etcd/pom.xml
+++ b/dubbo-configcenter/dubbo-configcenter-etcd/pom.xml
@@ -38,6 +38,16 @@
<version>${project.parent.version}</version>
</dependency>
<dependency>
+ <groupId>io.etcd</groupId>
+ <artifactId>jetcd-launcher</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>testcontainers</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-etcd3</artifactId>
<version>${project.parent.version}</version>
diff --git a/dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java b/dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java
index 87143fd..4e305ea 100644
--- a/dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java
+++ b/dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java
@@ -19,17 +19,20 @@ package org.apache.dubbo.configcenter.support.etcd;
import io.etcd.jetcd.ByteSequence;
import io.etcd.jetcd.Client;
+import io.etcd.jetcd.launcher.EtcdCluster;
+import io.etcd.jetcd.launcher.EtcdClusterFactory;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.configcenter.ConfigChangeEvent;
import org.apache.dubbo.configcenter.ConfigurationListener;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Disabled;
-import org.junit.jupiter.api.Test;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import java.net.URI;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -38,23 +41,23 @@ import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Unit test for etcd config center support
- * TODO Integrate with https://github.com/etcd-io/jetcd#launcher or using mock data.
+ * Integrate with https://github.com/etcd-io/jetcd#launcher
*/
-@Disabled
public class EtcdDynamicConfigurationTest {
- private static final String ENDPOINT = "http://127.0.0.1:2379";
-
private static EtcdDynamicConfiguration config;
- private static Client etcdClient;
+ public EtcdCluster etcdCluster = EtcdClusterFactory.buildCluster(getClass().getSimpleName(), 3, false, false);
+
+ private static Client client;
@Test
public void testGetConfig() {
+
put("/dubbo/config/org.apache.dubbo.etcd.testService/configurators", "hello");
put("/dubbo/config/test/dubbo.properties", "aaa=bbb");
- Assertions.assertEquals("hello", config.getConfig("org.apache.dubbo.etcd.testService.configurators"));
- Assertions.assertEquals("aaa=bbb", config.getConfig("dubbo.properties", "test"));
+ Assert.assertEquals("hello", config.getConfig("org.apache.dubbo.etcd.testService.configurators"));
+ Assert.assertEquals("aaa=bbb", config.getConfig("dubbo.properties", "test"));
}
@Test
@@ -77,16 +80,16 @@ public class EtcdDynamicConfigurationTest {
Thread.sleep(1000);
- Assertions.assertTrue(latch.await(5, TimeUnit.SECONDS));
- Assertions.assertEquals(1, listener1.getCount("/dubbo/config/AService/configurators"));
- Assertions.assertEquals(1, listener2.getCount("/dubbo/config/AService/configurators"));
- Assertions.assertEquals(1, listener3.getCount("/dubbo/config/testapp/tagrouters"));
- Assertions.assertEquals(1, listener4.getCount("/dubbo/config/testapp/tagrouters"));
+ Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
+ Assert.assertEquals(1, listener1.getCount("/dubbo/config/AService/configurators"));
+ Assert.assertEquals(1, listener2.getCount("/dubbo/config/AService/configurators"));
+ Assert.assertEquals(1, listener3.getCount("/dubbo/config/testapp/tagrouters"));
+ Assert.assertEquals(1, listener4.getCount("/dubbo/config/testapp/tagrouters"));
- Assertions.assertEquals("new value1", listener1.getValue());
- Assertions.assertEquals("new value1", listener2.getValue());
- Assertions.assertEquals("new value2", listener3.getValue());
- Assertions.assertEquals("new value2", listener4.getValue());
+ Assert.assertEquals("new value1", listener1.getValue());
+ Assert.assertEquals("new value1", listener2.getValue());
+ Assert.assertEquals("new value2", listener3.getValue());
+ Assert.assertEquals("new value2", listener4.getValue());
}
private class TestListener implements ConfigurationListener {
@@ -115,27 +118,36 @@ public class EtcdDynamicConfigurationTest {
}
}
- static void put(String key, String value) {
+ private void put(String key, String value) {
try {
- etcdClient.getKVClient()
- .put(ByteSequence.from(key, UTF_8), ByteSequence.from(value, UTF_8))
- .get();
+
+ client.getKVClient().put(ByteSequence.from(key, UTF_8), ByteSequence.from(value, UTF_8)).get();
} catch (Exception e) {
System.out.println("Error put value to etcd.");
}
}
- @BeforeAll
- static void setUp() {
- etcdClient = Client.builder().endpoints(ENDPOINT).build();
+ @Before
+ public void setUp() {
+
+ etcdCluster.start();
+
+ client = Client.builder().endpoints(etcdCluster.getClientEndpoints()).build();
+
+ List<URI> clientEndPoints = etcdCluster.getClientEndpoints();
+
+ String ipAddress = clientEndPoints.get(0).getHost() + ":" + clientEndPoints.get(0).getPort();
+ String urlForDubbo = "etcd3://" + ipAddress + "/org.apache.dubbo.etcd.testService";
+
// timeout in 15 seconds.
- URL url = URL.valueOf("etcd3://127.0.0.1:2379/org.apache.dubbo.etcd.testService")
+ URL url = URL.valueOf(urlForDubbo)
.addParameter(Constants.SESSION_TIMEOUT_KEY, 15000);
config = new EtcdDynamicConfiguration(url);
}
- @AfterAll
- static void tearDown() {
- etcdClient.close();
+ @After
+ public void tearDown() {
+ etcdCluster.close();
}
+
}
diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml
index 0329e73..1ba31db 100644
--- a/dubbo-dependencies-bom/pom.xml
+++ b/dubbo-dependencies-bom/pom.xml
@@ -137,6 +137,8 @@
<jaxb_version>2.2.7</jaxb_version>
<activation_version>1.2.0</activation_version>
+ <test_container_version>1.11.2</test_container_version>
+ <etcd_launcher_version>0.3.0</etcd_launcher_version>
<hessian_lite_version>3.2.5</hessian_lite_version>
<swagger_version>1.5.19</swagger_version>
<spring_test_version>4.3.16.RELEASE</spring_test_version>
@@ -552,6 +554,17 @@
<artifactId>portlet-api</artifactId>
<version>${portlet_version}</version>
</dependency>
+ <!-- for dubbo-configcenter-etcd -->
+ <dependency>
+ <groupId>io.etcd</groupId>
+ <artifactId>jetcd-launcher</artifactId>
+ <version>${etcd_launcher_version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>testcontainers</artifactId>
+ <version>${test_container_version}</version>
+ </dependency>
</dependencies>
</dependencyManagement>