Skip to content

Commit

Permalink
Merge branch '3.2.0' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
songxiaosheng committed Dec 18, 2023
2 parents 5850eb9 + db84301 commit 44265c4
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,57 @@
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metadata-api</artifactId>
<version>3.2.7</version>
<exclusions>
<exclusion>
<artifactId>dubbo-rpc-api</artifactId>
<groupId>org.apache.dubbo</groupId>
</exclusion>
<exclusion>
<artifactId>dubbo-common</artifactId>
<groupId>org.apache.dubbo</groupId>
</exclusion>
<exclusion>
<artifactId>dubbo-cluster</artifactId>
<groupId>org.apache.dubbo</groupId>
</exclusion>
</exclusions>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-api</artifactId>
<version>3.2.7</version>
<exclusions>
<exclusion>
<artifactId>dubbo-common</artifactId>
<groupId>org.apache.dubbo</groupId>
</exclusion>
</exclusions>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-cluster</artifactId>
<version>3.2.7</version>
<exclusions>
<exclusion>
<artifactId>dubbo-rpc-api</artifactId>
<groupId>org.apache.dubbo</groupId>
</exclusion>
</exclusions>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-common</artifactId>
<version>3.2.7</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.apache.dubbo.extensions</groupId>
<artifactId>dubbo-remoting-etcd3</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,6 +40,8 @@

import static org.junit.jupiter.api.Assertions.assertEquals;


@Disabled
public class ConsulServiceDiscoveryTest {

private URL url;
Expand Down
11 changes: 11 additions & 0 deletions dubbo-registry-extensions/dubbo-registry-etcd3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,27 @@
<description>The etcd3 registry module of Dubbo project</description>

<dependencies>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-api</artifactId>
<version>3.2.7</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-common</artifactId>
<version>3.2.7</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.dubbo.extensions</groupId>
<artifactId>dubbo-remoting-etcd3</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
// * <p>
// * 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<String> 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<String> convertToIpPort(List<ServiceInstance> serviceInstances) {
// List<String> 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
* <p>
* 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<String> 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<String> convertToIpPort(List<ServiceInstance> serviceInstances) {
List<String> result = new ArrayList<>();
for (ServiceInstance serviceInstance : serviceInstances) {
result.add(serviceInstance.getHost() + ":" + serviceInstance.getPort());
}
return result;
}

}

0 comments on commit 44265c4

Please sign in to comment.