This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 7aa8018679e Add more test cases on 
PrometheusPluginLifecycleServiceTest (#37695)
7aa8018679e is described below

commit 7aa8018679e0236e5e5cb61f4bb6bb58b128692a
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Jan 9 12:16:52 2026 +0800

    Add more test cases on PrometheusPluginLifecycleServiceTest (#37695)
---
 .../PrometheusPluginLifecycleServiceTest.java      | 26 ++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git 
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleServiceTest.java
 
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleServiceTest.java
index 1dcfcaf8e8d..1ed3b198f13 100644
--- 
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleServiceTest.java
+++ 
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleServiceTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.agent.plugin.metrics.prometheus;
 
+import io.prometheus.client.CollectorRegistry;
 import org.apache.shardingsphere.agent.api.PluginConfiguration;
 import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
 import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
@@ -41,6 +42,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
+import java.net.ServerSocket;
 import java.net.Socket;
 
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
@@ -56,18 +58,38 @@ class PrometheusPluginLifecycleServiceTest {
     @AfterEach
     void close() {
         pluginLifecycleService.close();
+        CollectorRegistry.defaultRegistry.clear();
     }
     
     @Test
     void assertStart() throws IOException {
-        ContextManager contextManager = mockContextManager();
+        final ContextManager contextManager = mockContextManager();
         
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
-        pluginLifecycleService.start(new PluginConfiguration("localhost", 
8090, "", PropertiesBuilder.build(new 
Property("JVM_INFORMATION_COLLECTOR_ENABLED", Boolean.TRUE.toString()))), true);
+        pluginLifecycleService.start(new PluginConfiguration("localhost", 
8090, "", PropertiesBuilder.build(new 
Property("jvm-information-collector-enabled", Boolean.TRUE.toString()))), true);
         try (Socket socket = new Socket()) {
             assertDoesNotThrow(() -> socket.connect(new 
InetSocketAddress("localhost", 8090)));
         }
     }
     
+    @Test
+    void assertStartForJDBCWithNullHost() throws IOException {
+        int port;
+        try (ServerSocket serverSocket = new ServerSocket(0)) {
+            port = serverSocket.getLocalPort();
+        }
+        pluginLifecycleService.start(new PluginConfiguration(null, port, "", 
PropertiesBuilder.build()), false);
+        try (Socket socket = new Socket()) {
+            assertDoesNotThrow(() -> socket.connect(new 
InetSocketAddress("localhost", port)));
+        }
+    }
+    
+    @Test
+    void assertStartWhenPortIsOccupied() throws IOException {
+        try (ServerSocket serverSocket = new ServerSocket(0)) {
+            assertDoesNotThrow(() -> pluginLifecycleService.start(new 
PluginConfiguration(null, serverSocket.getLocalPort(), "", 
PropertiesBuilder.build()), false));
+        }
+    }
+    
     private ContextManager mockContextManager() {
         ShardingSphereMetaData metaData = new ShardingSphereMetaData();
         MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, new 
ShardingSphereStatistics());

Reply via email to