Skip to content

Commit

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

* update jetcd version

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

* fix unit test failed

* compatible old version

* add ASF header

* ci: Upload coverage to Codecov after unit test
  • Loading branch information
aofall authored Jun 15, 2024
1 parent a227f52 commit 4c5a6df
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 55 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-and-test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ jobs:
with:
name: "checkstyle-file"
path: ${{ github.workspace }}/checkstyle.zip
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v4
- name: "Calculate Dubbo-SPI-Extensions Version"
id: dubbo-spi-extensions-version
run: |
Expand Down Expand Up @@ -295,6 +293,8 @@ jobs:
with:
name: coverage-result-${{ matrix.os }}-${{ matrix.jdk }}
path: "**/target/site/**/jacoco.xml"
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v4

# error-code-inspecting:
# needs: [check-license, build-tools]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-and-test-scheduled-3.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ jobs:
with:
name: "checkstyle-file"
path: ${{ github.workspace }}/checkstyle.zip
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v4
- name: "Calculate Dubbo-SPI-Extensions Version"
id: dubbo-spi-extensions-version
run: |
Expand Down Expand Up @@ -301,6 +299,8 @@ jobs:
with:
name: coverage-result-${{ matrix.os }}-${{ matrix.jdk }}
path: "**/target/site/**/jacoco.xml"
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v4

# error-code-inspecting:
# needs: [check-license, build-tools]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ jobs:
with:
name: "checkstyle-file"
path: ${{ github.workspace }}/checkstyle.zip
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v4
- name: "Calculate Dubbo-SPI-Extensions Version"
id: dubbo-spi-extensions-version
run: |
Expand Down Expand Up @@ -301,6 +299,8 @@ jobs:
with:
name: coverage-result-${{ matrix.os }}-${{ matrix.jdk }}
path: "**/target/site/**/jacoco.xml"
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v4

# error-code-inspecting:
# needs: [check-license, build-tools]
Expand Down
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
Loading

0 comments on commit 4c5a6df

Please sign in to comment.