Skip to content

Commit

Permalink
Bump jetcd vertsion from 0.5.7 to 0.7.7 (#398)
Browse files Browse the repository at this point in the history
* update jetcd version

* rename the dubbo-registry-etcd extension name from etcd3 to etcd

* fix unit test failed

* compatible old version

* add ASF header
  • Loading branch information
aofall authored Jun 11, 2024
1 parent 6b534a8 commit c6dc17d
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 49 deletions.
5 changes: 5 additions & 0 deletions dubbo-configcenter-extensions/dubbo-configcenter-etcd/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
<artifactId>jetcd-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.etcd</groupId>
<artifactId>jetcd-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.apache.dubbo.common.config.configcenter.ConfigChangedEvent;
import org.apache.dubbo.common.config.configcenter.ConfigurationListener;
import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.remoting.etcd.StateListener;
import org.apache.dubbo.remoting.etcd.jetcd.JEtcdClient;
Expand All @@ -48,6 +50,8 @@
*/
public class EtcdDynamicConfiguration implements DynamicConfiguration {

private static final Logger logger = LoggerFactory.getLogger(EtcdDynamicConfiguration.class);

/**
* The final root path would be: /$NAME_SPACE/config
*/
Expand All @@ -71,7 +75,7 @@ public class EtcdDynamicConfiguration implements DynamicConfiguration {
try {
recover();
} catch (Exception e) {
// ignore
logger.error("add etcd watch failed", e);
}
}
});
Expand Down Expand Up @@ -164,7 +168,7 @@ public void onNext(WatchResponse watchResponse) {

@Override
public void onError(Throwable throwable) {
// ignore
logger.error("etcd watcher get an error", throwable);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.dubbo.configcenter.support.etcd;

import io.etcd.jetcd.test.EtcdClusterExtension;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.config.configcenter.ConfigChangedEvent;
import org.apache.dubbo.common.config.configcenter.ConfigurationListener;
Expand All @@ -25,7 +26,8 @@
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.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
Expand All @@ -47,12 +49,45 @@
*/
public class EtcdDynamicConfigurationTest {

private static final Logger logger = LoggerFactory.getLogger(EtcdDynamicConfigurationTest.class);

private static EtcdDynamicConfiguration config;

public EtcdCluster etcdCluster = EtcdClusterFactory.buildCluster(getClass().getSimpleName(), 3, false);
public EtcdCluster etcdCluster;

private static Client client;

@BeforeEach
public void setUp() {
EtcdClusterExtension clusterExtension = EtcdClusterExtension.builder()
.withClusterName(getClass().getSimpleName())
.withNodes(3)
.withSsl(false)
.build();
etcdCluster = clusterExtension.cluster();

etcdCluster.start();

client = Client.builder().endpoints(etcdCluster.clientEndpoints()).build();

List<URI> clientEndPoints = etcdCluster.clientEndpoints();

String ipAddress = clientEndPoints.get(0).getHost() + ":" + clientEndPoints.get(0).getPort();
String urlForDubbo = "etcd://" + ipAddress + "/org.apache.dubbo.etcd.testService";

// timeout in 15 seconds.
URL url = URL.valueOf(urlForDubbo)
.addParameter(SESSION_TIMEOUT_KEY, 15000);
config = new EtcdDynamicConfiguration(url);
}

@AfterEach
public void tearDown() {
if (etcdCluster != null) {
etcdCluster.close();
}
}

@Test
public void testGetConfig() {

Expand Down Expand Up @@ -124,31 +159,8 @@ private void put(String key, String value) {
try {
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.");
logger.error("Error put value to etcd.");
}
}

@BeforeEach
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(urlForDubbo)
.addParameter(SESSION_TIMEOUT_KEY, 15000);
config = new EtcdDynamicConfiguration(url);
}

@AfterEach
public void tearDown() {
etcdCluster.close();
}

}
10 changes: 7 additions & 3 deletions dubbo-extensions-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@
<mina_version>1.1.7</mina_version>
<slf4j_version>1.7.25</slf4j_version>
<grizzly_version>2.4.4</grizzly_version>
<jetcd_version>0.5.7</jetcd_version>
<jetcd_version>0.7.7</jetcd_version>
<grpc.version>1.53.0</grpc.version>
<etcd_launcher_version>0.5.7</etcd_launcher_version>
<netty4_version>4.1.66.Final</netty4_version>
<consul_process_version>2.2.1</consul_process_version>
<consul_version>1.4.2</consul_version>
Expand Down Expand Up @@ -409,6 +408,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.etcd</groupId>
<artifactId>jetcd-test</artifactId>
<version>${jetcd_version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
Expand Down Expand Up @@ -442,7 +446,7 @@
<dependency>
<groupId>io.etcd</groupId>
<artifactId>jetcd-launcher</artifactId>
<version>${etcd_launcher_version}</version>
<version>${jetcd_version}</version>
<exclusions>
<exclusion>
<groupId>com.github.spotbugs</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
<artifactId>jetcd-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.etcd</groupId>
<artifactId>jetcd-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.dubbo.metadata.store.etcd;

import io.etcd.jetcd.test.EtcdClusterExtension;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder;
Expand All @@ -30,7 +31,6 @@
import io.etcd.jetcd.Client;
import io.etcd.jetcd.kv.GetResponse;
import io.etcd.jetcd.launcher.EtcdCluster;
import io.etcd.jetcd.launcher.EtcdClusterFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -57,25 +57,31 @@ public class EtcdMetadataReportTest {

private static final String TEST_SERVICE = "org.apache.dubbo.metadata.store.etcd.EtcdMetadata4TstService";

private EtcdCluster etcdCluster = EtcdClusterFactory.buildCluster(getClass().getSimpleName(), 1, false);
private EtcdCluster etcdCluster;
private Client etcdClientForTest;
private EtcdMetadataReport etcdMetadataReport;
private URL registryUrl;
private EtcdMetadataReportFactory etcdMetadataReportFactory;

@BeforeEach
public void setUp() {
etcdCluster = EtcdClusterExtension.builder().withClusterName(getClass().getSimpleName())
.withNodes(1)
.withSsl(false)
.build().cluster();
etcdCluster.start();
etcdClientForTest = Client.builder().endpoints(etcdCluster.getClientEndpoints()).build();
List<URI> clientEndPoints = etcdCluster.getClientEndpoints();
etcdClientForTest = Client.builder().endpoints(etcdCluster.clientEndpoints()).build();
List<URI> clientEndPoints = etcdCluster.clientEndpoints();
this.registryUrl = URL.valueOf("etcd://" + clientEndPoints.get(0).getHost() + ":" + clientEndPoints.get(0).getPort());
etcdMetadataReportFactory = new EtcdMetadataReportFactory();
this.etcdMetadataReport = (EtcdMetadataReport) etcdMetadataReportFactory.createMetadataReport(registryUrl);
}

@AfterEach
public void tearDown() throws Exception {
etcdCluster.close();
if (etcdCluster != null) {
etcdCluster.stop();
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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;

public class EtcdCompatibleRegistryFactory extends EtcdServiceDiscoveryFactory {

// The extension name of dubbo-registry-etcd is etcd3 and user should config the URL as 'etcd3://localhost:2379'.
// But the extension name of dubbo-metadata-report-etcd and dubbo-configcenter-etcd are etcd
// and user should config the URL as 'etcd://localhost:2379'.
// To avoid confusion for users when configuring URLs in registry, rename the dubbo-registry-etcd extension name
// from etcd3 to etcd, and use extend class to compatible the old version of dubbo-registry-etcd.
// It can unify the extension name and avoid confusion for users and compatible the old version

}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
etcd3=org.apache.dubbo.registry.etcd.EtcdRegistryFactory
etcd=org.apache.dubbo.registry.etcd.EtcdRegistryFactory
etcd3=org.apache.dubbo.registry.etcd.EtcdCompatibleRegistryFactory
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public class EtcdRegistryTest {
URL serviceUrl = URL.valueOf("dubbo://" + NetUtils.getLocalHost() + "/" + service + "?methods=test1,test2");
URL serviceUrl2 = URL.valueOf("dubbo://" + NetUtils.getLocalHost() + "/" + service + "?methods=test1,test2,test3");
URL serviceUrl3 = URL.valueOf("dubbo://" + NetUtils.getLocalHost() + "/" + outerService + "?methods=test1,test2");
URL registryUrl = URL.valueOf("etcd3://127.0.0.1:2379/org.apache.dubbo.registry.RegistryService");
URL registryUrl = URL.valueOf("etcd://127.0.0.1:2379/org.apache.dubbo.registry.RegistryService");
URL consumerUrl = URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":2018" + "/" + service + "?methods=test1,test2");
RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getExtension("etcd3", false);
RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getExtension("etcd", false);
EtcdRegistry registry;
URL subscribe = new URL(
ADMIN_PROTOCOL, NetUtils.getLocalHost(), 0, "",
Expand Down
5 changes: 5 additions & 0 deletions dubbo-remoting-extensions/dubbo-remoting-etcd3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
<groupId>io.etcd</groupId>
<artifactId>jetcd-core</artifactId>
</dependency>
<dependency>
<groupId>io.etcd</groupId>
<artifactId>jetcd-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
import io.etcd.jetcd.KV;
import io.etcd.jetcd.Lease;
import io.etcd.jetcd.launcher.EtcdCluster;
import io.etcd.jetcd.launcher.EtcdClusterFactory;
import io.etcd.jetcd.lease.LeaseKeepAliveResponse;
import io.etcd.jetcd.options.PutOption;
import io.etcd.jetcd.support.CloseableClient;
import io.etcd.jetcd.support.Observers;
import io.etcd.jetcd.test.EtcdClusterExtension;
import io.grpc.stub.StreamObserver;
import org.junit.jupiter.api.AfterAll;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
Expand All @@ -65,6 +65,8 @@
@Disabled
public class LeaseTest {

private static final Logger logger = LoggerFactory.getLogger(LeaseTest.class);

private static EtcdCluster cluster;

private KV kvClient;
Expand All @@ -75,20 +77,31 @@ public class LeaseTest {
private static final ByteSequence KEY_2 = ByteSequence.from("foo2", Charsets.UTF_8);
private static final ByteSequence VALUE = ByteSequence.from("bar", Charsets.UTF_8);

@BeforeAll
public static void beforeClass() {
cluster = EtcdClusterFactory.buildCluster("etcd-lease", 3, false);
@BeforeEach
public void beforeClass() {
EtcdClusterExtension clusterExtension = EtcdClusterExtension.builder()
.withClusterName("etcd-lease")
.withNodes(3)
.withSsl(false)
.build();
try {
cluster = clusterExtension.cluster();
} catch (Exception e) {
logger.error("Init etcd cluster failed");
}
cluster.start();
}

@AfterAll
public static void afterClass() {
cluster.close();
@AfterEach
public void afterClass() {
if (cluster != null) {
cluster.stop();
}
}

@BeforeEach
public void setUp() {
client = Client.builder().endpoints(cluster.getClientEndpoints()).build();
client = Client.builder().endpoints(cluster.clientEndpoints()).build();
kvClient = client.getKVClient();
leaseClient = client.getLeaseClient();
}
Expand Down

0 comments on commit c6dc17d

Please sign in to comment.