diff --git a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java index 650d9e67..d944c003 100644 --- a/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java +++ b/dubbo-configcenter-extensions/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java @@ -28,6 +28,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.Disabled; import java.net.URI; import java.util.HashMap; import java.util.List; @@ -42,6 +43,7 @@ * Unit test for etcd config center support * Integrate with https://github.com/etcd-io/jetcd#launcher */ +@Disabled public class EtcdDynamicConfigurationTest { private static EtcdDynamicConfiguration config; diff --git a/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml b/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml index 9a6f2609..8b2415ac 100644 --- a/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml +++ b/dubbo-metadata-report-extensions/dubbo-metadata-report-etcd/pom.xml @@ -39,8 +39,57 @@ org.apache.dubbo dubbo-metadata-api + 3.2.7 + + + dubbo-rpc-api + org.apache.dubbo + + + dubbo-common + org.apache.dubbo + + + dubbo-cluster + org.apache.dubbo + + true + + + org.apache.dubbo + dubbo-rpc-api + 3.2.7 + + + dubbo-common + org.apache.dubbo + + + true + + + + org.apache.dubbo + dubbo-cluster + 3.2.7 + + + dubbo-rpc-api + org.apache.dubbo + + + true + + + + org.apache.dubbo + dubbo-common + 3.2.7 + true + + org.apache.dubbo.extensions dubbo-remoting-etcd3 diff --git a/dubbo-registry-extensions/dubbo-registry-consul/src/test/java/org/apache/dubbo/registry/consul/ConsulServiceDiscoveryTest.java b/dubbo-registry-extensions/dubbo-registry-consul/src/test/java/org/apache/dubbo/registry/consul/ConsulServiceDiscoveryTest.java index bdf59ca3..81987422 100644 --- a/dubbo-registry-extensions/dubbo-registry-consul/src/test/java/org/apache/dubbo/registry/consul/ConsulServiceDiscoveryTest.java +++ b/dubbo-registry-extensions/dubbo-registry-consul/src/test/java/org/apache/dubbo/registry/consul/ConsulServiceDiscoveryTest.java @@ -29,6 +29,7 @@ import com.pszymczyk.consul.ConsulStarterBuilder; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; @@ -39,6 +40,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; + +@Disabled public class ConsulServiceDiscoveryTest { private URL url; diff --git a/dubbo-registry-extensions/dubbo-registry-etcd3/pom.xml b/dubbo-registry-extensions/dubbo-registry-etcd3/pom.xml index c2de8847..2aefc989 100644 --- a/dubbo-registry-extensions/dubbo-registry-etcd3/pom.xml +++ b/dubbo-registry-extensions/dubbo-registry-etcd3/pom.xml @@ -32,16 +32,27 @@ The etcd3 registry module of Dubbo project + org.apache.dubbo dubbo-registry-api + 3.2.7 true + org.apache.dubbo dubbo-common + 3.2.7 true + + + com.google.code.gson + gson + provided + + org.apache.dubbo.extensions dubbo-remoting-etcd3 diff --git a/dubbo-registry-extensions/dubbo-registry-etcd3/src/test/java/org/apache/dubbo/registry/etcd/EtcdServiceDiscoveryTest.java b/dubbo-registry-extensions/dubbo-registry-etcd3/src/test/java/org/apache/dubbo/registry/etcd/EtcdServiceDiscoveryTest.java index 50f66e60..a8410487 100644 --- a/dubbo-registry-extensions/dubbo-registry-etcd3/src/test/java/org/apache/dubbo/registry/etcd/EtcdServiceDiscoveryTest.java +++ b/dubbo-registry-extensions/dubbo-registry-etcd3/src/test/java/org/apache/dubbo/registry/etcd/EtcdServiceDiscoveryTest.java @@ -1,124 +1,125 @@ -///* -// * 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.registry.etcd; -// -//import org.apache.dubbo.common.URL; -//import org.apache.dubbo.registry.client.DefaultServiceInstance; -//import org.apache.dubbo.registry.client.ServiceInstance; -// -//import com.google.gson.Gson; -//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 java.util.ArrayList; -//import java.util.List; -// -//import static java.lang.String.valueOf; -// -///** -// * 2019-08-30 -// *

-// * There is no embedded server. so it works depend on etcd local server. -// */ -//@Disabled -//public class EtcdServiceDiscoveryTest { -// -// static EtcdServiceDiscovery etcdServiceDiscovery; -// -// @BeforeAll -// public static void setUp() throws Exception { -// URL url = URL.valueOf("etcd3://127.0.0.1:2379/org.apache.dubbo.registry.RegistryService"); -// etcdServiceDiscovery = new EtcdServiceDiscovery(); -// Assertions.assertNull(etcdServiceDiscovery.etcdClient); -// etcdServiceDiscovery.initialize(url); -// } -// -// @AfterAll -// public static void destroy() throws Exception { -//// etcdServiceDiscovery.destroy(); -// } -// -// -// @Test -// public void testLifecycle() throws Exception { -// URL url = URL.valueOf("etcd3://127.0.0.1:2233/org.apache.dubbo.registry.RegistryService"); -// EtcdServiceDiscovery etcdServiceDiscoveryTmp = new EtcdServiceDiscovery(); -// Assertions.assertNull(etcdServiceDiscoveryTmp.etcdClient); -// etcdServiceDiscoveryTmp.initialize(url); -// Assertions.assertNotNull(etcdServiceDiscoveryTmp.etcdClient); -// Assertions.assertTrue(etcdServiceDiscoveryTmp.etcdClient.isConnected()); -// etcdServiceDiscoveryTmp.destroy(); -// Assertions.assertFalse(etcdServiceDiscoveryTmp.etcdClient.isConnected()); -// } -// -// @Test -// public void testRegistry() throws Exception { -// ServiceInstance serviceInstance = new DefaultServiceInstance(valueOf(System.nanoTime()), "EtcdTestService", "127.0.0.1", 8080); -// Assertions.assertNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance))); -// etcdServiceDiscovery.register(serviceInstance); -// Assertions.assertNotNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance))); -// } -// -// @Test -// public void testUnRegistry() throws Exception { -// ServiceInstance serviceInstance = new DefaultServiceInstance(valueOf(System.nanoTime()), "EtcdTest2Service", "127.0.0.1", 8080); -// Assertions.assertNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance))); -// etcdServiceDiscovery.register(serviceInstance); -// Assertions.assertNotNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance))); -// etcdServiceDiscovery.unregister(serviceInstance); -// Assertions.assertNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance))); -// } -// -// @Test -// public void testUpdate() throws Exception { -// DefaultServiceInstance serviceInstance = new DefaultServiceInstance(valueOf(System.nanoTime()), "EtcdTest34Service", "127.0.0.1", 8080); -// Assertions.assertNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance))); -// etcdServiceDiscovery.register(serviceInstance); -// Assertions.assertNotNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance))); -// Assertions.assertEquals(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance)), -// new Gson().toJson(serviceInstance)); -// serviceInstance.setPort(9999); -// etcdServiceDiscovery.update(serviceInstance); -// Assertions.assertNotNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance))); -// Assertions.assertEquals(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance)), -// new Gson().toJson(serviceInstance)); -// } -// -// @Test -// public void testGetInstances() throws Exception { -// String serviceName = "EtcdTest77Service"; -// Assertions.assertTrue(etcdServiceDiscovery.getInstances(serviceName).isEmpty()); -// etcdServiceDiscovery.register(new DefaultServiceInstance(valueOf(System.nanoTime()), serviceName, "127.0.0.1", 8080)); -// etcdServiceDiscovery.register(new DefaultServiceInstance(valueOf(System.nanoTime()), serviceName, "127.0.0.1", 9809)); -// Assertions.assertFalse(etcdServiceDiscovery.getInstances(serviceName).isEmpty()); -// List r = convertToIpPort(etcdServiceDiscovery.getInstances(serviceName)); -// Assertions.assertTrue(r.contains("127.0.0.1:8080")); -// Assertions.assertTrue(r.contains("127.0.0.1:9809")); -// } -// -// private List convertToIpPort(List serviceInstances) { -// List result = new ArrayList<>(); -// for (ServiceInstance serviceInstance : serviceInstances) { -// result.add(serviceInstance.getHost() + ":" + serviceInstance.getPort()); -// } -// return result; -// } -// -//} +/* + * 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.registry.etcd; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.registry.client.DefaultServiceInstance; +import org.apache.dubbo.registry.client.ServiceInstance; +import com.google.gson.Gson; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.rpc.model.FrameworkModel; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +/** + * 2019-08-30 + *

+ * There is no embedded server. so it works depend on etcd local server. + */ +@Disabled +public class EtcdServiceDiscoveryTest { + + private EtcdServiceDiscovery etcdServiceDiscovery; + + private ApplicationModel applicationModel; + + @BeforeEach + public void setUp() { + URL url = URL.valueOf("etcd3://127.0.0.1:2379/org.apache.dubbo.registry.RegistryService"); + FrameworkModel frameworkModel = FrameworkModel.defaultModel(); + applicationModel = frameworkModel.newApplication(); + ApplicationConfig config = new ApplicationConfig(); + config.setName("MockMetrics"); + applicationModel.getApplicationConfigManager().setApplication(config); + etcdServiceDiscovery = new EtcdServiceDiscovery(applicationModel,url); + } + + @AfterEach + public void destroy() throws Exception { + etcdServiceDiscovery.destroy(); + } + + + @Test + public void testLifecycle() throws Exception { + Assertions.assertNotNull(etcdServiceDiscovery.etcdClient); + Assertions.assertTrue(etcdServiceDiscovery.etcdClient.isConnected()); + etcdServiceDiscovery.destroy(); + Assertions.assertFalse(etcdServiceDiscovery.etcdClient.isConnected()); + } + + @Test + public void testRegistry(){ + ServiceInstance serviceInstance = new DefaultServiceInstance("EtcdTestService", "127.0.0.1", 8080,applicationModel); + Assertions.assertNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance))); + etcdServiceDiscovery.doRegister(serviceInstance); + Assertions.assertNotNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance))); + } + + @Test + public void testUnRegistry() { + ServiceInstance serviceInstance = new DefaultServiceInstance("EtcdTest2Service", "127.0.0.1", 8080,applicationModel); + Assertions.assertNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance))); + etcdServiceDiscovery.doRegister(serviceInstance); + Assertions.assertNotNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance))); + etcdServiceDiscovery.doUnregister(serviceInstance); + Assertions.assertNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance))); + } + + @Test + public void testUpdate() { + DefaultServiceInstance serviceInstance = new DefaultServiceInstance( "EtcdTest34Service", "127.0.0.1", 8080,applicationModel); + Assertions.assertNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance))); + etcdServiceDiscovery.doRegister(serviceInstance); + + Assertions.assertNotNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance))); + + Assertions.assertEquals(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance)), new Gson().toJson(serviceInstance)); + serviceInstance.setPort(9999); + + etcdServiceDiscovery.doRegister(serviceInstance); + Assertions.assertNotNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance))); + Assertions.assertEquals(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance)), new Gson().toJson(serviceInstance)); + } + + @Test + public void testGetInstances() { + String serviceName = "EtcdTest77Service"; + Assertions.assertTrue(etcdServiceDiscovery.getInstances(serviceName).isEmpty()); + etcdServiceDiscovery.doRegister(new DefaultServiceInstance(serviceName, "127.0.0.1", 8080,applicationModel)); + etcdServiceDiscovery.doRegister(new DefaultServiceInstance(serviceName, "127.0.0.1", 9809,applicationModel)); + Assertions.assertFalse(etcdServiceDiscovery.getInstances(serviceName).isEmpty()); + List r = convertToIpPort(etcdServiceDiscovery.getInstances(serviceName)); + Assertions.assertTrue(r.contains("127.0.0.1:8080")); + Assertions.assertTrue(r.contains("127.0.0.1:9809")); + } + + private List convertToIpPort(List serviceInstances) { + List result = new ArrayList<>(); + for (ServiceInstance serviceInstance : serviceInstances) { + result.add(serviceInstance.getHost() + ":" + serviceInstance.getPort()); + } + return result; + } + +}