diff --git a/dubbo-remoting/dubbo-remoting-api/pom.xml b/dubbo-remoting/dubbo-remoting-api/pom.xml
index 73e160136e7..a083b2051ca 100644
--- a/dubbo-remoting/dubbo-remoting-api/pom.xml
+++ b/dubbo-remoting/dubbo-remoting-api/pom.xml
@@ -58,5 +58,11 @@
log4j-slf4j-impl
test
+
+ org.apache.dubbo
+ dubbo-test-check
+ ${project.parent.version}
+ test
+
diff --git a/dubbo-remoting/dubbo-remoting-http12/pom.xml b/dubbo-remoting/dubbo-remoting-http12/pom.xml
index 4d16603471c..64725c11e0e 100644
--- a/dubbo-remoting/dubbo-remoting-http12/pom.xml
+++ b/dubbo-remoting/dubbo-remoting-http12/pom.xml
@@ -85,5 +85,11 @@
log4j-slf4j-impl
test
+
+ org.apache.dubbo
+ dubbo-test-check
+ ${project.parent.version}
+ test
+
diff --git a/dubbo-remoting/dubbo-remoting-http3/pom.xml b/dubbo-remoting/dubbo-remoting-http3/pom.xml
index 4955a9ed08c..e9d2041e2f5 100644
--- a/dubbo-remoting/dubbo-remoting-http3/pom.xml
+++ b/dubbo-remoting/dubbo-remoting-http3/pom.xml
@@ -52,5 +52,11 @@
log4j-slf4j-impl
test
+
+ org.apache.dubbo
+ dubbo-test-check
+ ${project.parent.version}
+ test
+
diff --git a/dubbo-remoting/dubbo-remoting-netty/pom.xml b/dubbo-remoting/dubbo-remoting-netty/pom.xml
index 94f3924efa7..b5b43f59aae 100644
--- a/dubbo-remoting/dubbo-remoting-netty/pom.xml
+++ b/dubbo-remoting/dubbo-remoting-netty/pom.xml
@@ -57,5 +57,11 @@
${project.parent.version}
test
+
+ org.apache.dubbo
+ dubbo-test-check
+ ${project.parent.version}
+ test
+
diff --git a/dubbo-remoting/dubbo-remoting-netty4/pom.xml b/dubbo-remoting/dubbo-remoting-netty4/pom.xml
index 06d548d1bdf..82aa4b2a0c9 100644
--- a/dubbo-remoting/dubbo-remoting-netty4/pom.xml
+++ b/dubbo-remoting/dubbo-remoting-netty4/pom.xml
@@ -68,6 +68,12 @@
${project.parent.version}
test
+
+ org.apache.dubbo
+ dubbo-test-check
+ ${project.parent.version}
+ test
+
org.apache.logging.log4j
log4j-slf4j-impl
diff --git a/dubbo-remoting/dubbo-remoting-websocket/pom.xml b/dubbo-remoting/dubbo-remoting-websocket/pom.xml
index b27869d056a..551e8f195a5 100644
--- a/dubbo-remoting/dubbo-remoting-websocket/pom.xml
+++ b/dubbo-remoting/dubbo-remoting-websocket/pom.xml
@@ -37,5 +37,11 @@
dubbo-remoting-http12
${project.parent.version}
+
+ org.apache.dubbo
+ dubbo-test-check
+ ${project.parent.version}
+ test
+
diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-curator5/pom.xml b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/pom.xml
index 54de827c327..5556f236b56 100644
--- a/dubbo-remoting/dubbo-remoting-zookeeper-curator5/pom.xml
+++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/pom.xml
@@ -39,13 +39,6 @@
${project.parent.version}
-
- org.apache.dubbo
- dubbo-test-common
- ${project.parent.version}
- test
-
-
org.apache.curator
curator-framework
diff --git a/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClientTest.java b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClientTest.java
index e515fc6504b..059b7ad50da 100644
--- a/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClientTest.java
+++ b/dubbo-remoting/dubbo-remoting-zookeeper-curator5/src/test/java/org/apache/dubbo/remoting/zookeeper/curator5/Curator5ZookeeperClientTest.java
@@ -16,10 +16,17 @@
*/
package org.apache.dubbo.remoting.zookeeper.curator5;
+import org.apache.curator.framework.CuratorFrameworkFactory.Builder;
+
+import org.apache.curator.framework.api.CreateBuilder;
+import org.apache.curator.framework.api.ExistsBuilder;
+import org.apache.curator.framework.listen.StandardListenerManager;
+
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.config.configcenter.ConfigItem;
import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
@@ -35,31 +42,67 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.Spy;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
class Curator5ZookeeperClientTest {
private static Curator5ZookeeperClient curatorClient;
private static CuratorFramework client = null;
- private static int zookeeperServerPort1;
+ private static int zookeeperServerMockPort1;
private static String zookeeperConnectionAddress1;
+ @Spy
+ CuratorFrameworkFactory.Builder spyBuilder = CuratorFrameworkFactory.builder();
+
@BeforeAll
public static void setUp() throws Exception {
- zookeeperConnectionAddress1 = System.getProperty("zookeeper.connection.address.1");
- zookeeperServerPort1 = Integer.parseInt(
- zookeeperConnectionAddress1.substring(zookeeperConnectionAddress1.lastIndexOf(":") + 1));
+ zookeeperServerMockPort1 = 2181;
+ zookeeperConnectionAddress1 = "zookeeper://localhost:" + zookeeperServerMockPort1;
+
+ // mock begin
+ // create mock bean begin
+ CuratorFrameworkFactory.Builder realBuilder = CuratorFrameworkFactory.builder();
+ CuratorFrameworkFactory.Builder spyBuilder = spy(realBuilder);
+ CreateBuilder mockCreateBuilder = mock(CreateBuilder.class);
+ ExistsBuilder mockExistsBuilder = mock(ExistsBuilder.class);
+ CuratorFramework mockCuratorFramework = Mockito.mock(CuratorFramework.class);
+ MockedStatic curatorFrameworkFactoryMockedStatic = Mockito.mockStatic(CuratorFrameworkFactory.class);
+ curatorFrameworkFactoryMockedStatic.when(CuratorFrameworkFactory::builder).thenReturn(spyBuilder);
+ doReturn(mockCuratorFramework).when(spyBuilder).build();
+ Mockito.when(mockCuratorFramework.blockUntilConnected(anyInt(), any())).thenReturn(true);
+ Mockito.when(mockCuratorFramework.getConnectionStateListenable()).thenReturn(StandardListenerManager.standard());
+ Mockito.when(mockCuratorFramework.create()).thenReturn(mockCreateBuilder);
+ Mockito.when(mockCuratorFramework.checkExists()).thenReturn(mockExistsBuilder);
+ List paths = new ArrayList<>();
+ Mockito.when(mockCreateBuilder.forPath(anyString())).thenAnswer(i-> {
+ paths.add(i.getArgument(0));
+ return i.getArgument(0);
+ });
+ Mockito.when(mockExistsBuilder.forPath(anyString())).thenAnswer(i-> {
+ if (paths.contains(i.getArgument(0))) {
+ return new Stat();
+ }
+ return null;
+ });
+
+
curatorClient = new Curator5ZookeeperClient(
URL.valueOf(zookeeperConnectionAddress1 + "/org.apache.dubbo.registry.RegistryService"));
- client = CuratorFrameworkFactory.newClient(
- "127.0.0.1:" + zookeeperServerPort1, new ExponentialBackoffRetry(1000, 3));
- client.start();
+
}
@Test
diff --git a/dubbo-remoting/pom.xml b/dubbo-remoting/pom.xml
index 2546529bda7..3114ba96b28 100644
--- a/dubbo-remoting/pom.xml
+++ b/dubbo-remoting/pom.xml
@@ -40,12 +40,5 @@
false
-
-
- org.apache.dubbo
- dubbo-test-check
- ${project.parent.version}
- test
-
-
+