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

jimin pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git


The following commit(s) were added to refs/heads/2.x by this push:
     new 6083fa1cbf test: add unit tests for Eureka module (#7255)
6083fa1cbf is described below

commit 6083fa1cbfeffca982651104196f0d5f6904a590
Author: wjwang00 <wjwan...@foxmail.com>
AuthorDate: Mon Mar 31 12:35:34 2025 +0800

    test: add unit tests for Eureka module (#7255)
---
 changes/en-us/2.x.md                               |  3 +++
 changes/zh-cn/2.x.md                               |  3 +++
 .../eureka/EurekaRegistryProviderTest.java         |  5 +++-
 .../eureka/EurekaRegistryServiceImplTest.java      | 29 ++++++++++++++++++++++
 4 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index da9bd5d898..8d9f67dd4a 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -103,6 +103,8 @@ Add changes here for all PR submitted to the 2.x branch.
 - [[#7221](https://github.com/apache/incubator-seata/pull/7221)] add UT for 
gRPC Encoder/Decode
 - [[#7227](https://github.com/apache/incubator-seata/pull/7227)] add mock test 
for seata-discovery-consul module
 - [[#7233][https://github.com/apache/incubator-seata/pull/7233]] add mock test 
for seata-discovery-etcd3
+- [[#7243](https://github.com/apache/incubator-seata/pull/7243)] add unit test 
for seata-discovery-eureka
+- [[#7255](https://github.com/apache/incubator-seata/pull/7255)] more unit 
tests for Discovery-Eureka
 
 ### refactor:
 
@@ -139,5 +141,6 @@ Thanks to these contributors for their code commits. Please 
report an unintended
 - [mehedikhan72](https://github.com/mehedikhan72)
 - [AndrewSf](https://github.com/andrewseif)
 - [bigcyy](https://github.com/bigcyy)
+- [wjwang00](https://github.com/wjwang00)
 
 Also, we receive many valuable issues, questions and advices from our 
community. Thanks for you all.
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index 2ea2ac5322..213b400665 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -102,6 +102,8 @@
 - [[#7221](https://github.com/apache/incubator-seata/pull/7221)] 增加 gRPC 
Encoder/Decoder的测试用例
 - [[#7227](https://github.com/apache/incubator-seata/pull/7227)] 为 
seata-discovery-consul 增加mock测试
 - [[#7233][https://github.com/apache/incubator-seata/pull/7233]] 增加对 
seata-discovery-etcd3 的mock测试
+- [[#7243](https://github.com/apache/incubator-seata/pull/7243)] 增加对 
seata-discovery-eureka的单测
+- [[#7255](https://github.com/apache/incubator-seata/pull/7255)] 
补充更多seata-discovery-eureka模块的单测提高覆盖率
 ### refactor:
 
 - [[#7145](https://github.com/apache/incubator-seata/pull/7145)] 重构不满足 license 
要求的代码
@@ -131,5 +133,6 @@
 - [YoWuwuuuw](https://github.com/YoWuwuuuw)
 - [AndrewSf](https://github.com/andrewseif)
 - [bigcyy](https://github.com/bigcyy)
+- [wjwang00](https://github.com/wjwang00)
 
 同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。
diff --git 
a/discovery/seata-discovery-eureka/src/test/java/org/apache/seata/discovery/registry/eureka/EurekaRegistryProviderTest.java
 
b/discovery/seata-discovery-eureka/src/test/java/org/apache/seata/discovery/registry/eureka/EurekaRegistryProviderTest.java
index 21e1dce7b4..a1f29bad25 100644
--- 
a/discovery/seata-discovery-eureka/src/test/java/org/apache/seata/discovery/registry/eureka/EurekaRegistryProviderTest.java
+++ 
b/discovery/seata-discovery-eureka/src/test/java/org/apache/seata/discovery/registry/eureka/EurekaRegistryProviderTest.java
@@ -24,6 +24,9 @@ public class EurekaRegistryProviderTest {
 
     @Test
     void testProvide(){
-        assertThat(new 
EurekaRegistryProvider()).isInstanceOf(EurekaRegistryProvider.class);
+        EurekaRegistryProvider provider = new EurekaRegistryProvider();
+        
assertThat(provider.provide()).isInstanceOf(EurekaRegistryServiceImpl.class);
+        assertThat(provider.provide()).isSameAs(provider.provide());
+
     }
 }
diff --git 
a/discovery/seata-discovery-eureka/src/test/java/org/apache/seata/discovery/registry/eureka/EurekaRegistryServiceImplTest.java
 
b/discovery/seata-discovery-eureka/src/test/java/org/apache/seata/discovery/registry/eureka/EurekaRegistryServiceImplTest.java
index ac6db51fcb..96caabf71e 100644
--- 
a/discovery/seata-discovery-eureka/src/test/java/org/apache/seata/discovery/registry/eureka/EurekaRegistryServiceImplTest.java
+++ 
b/discovery/seata-discovery-eureka/src/test/java/org/apache/seata/discovery/registry/eureka/EurekaRegistryServiceImplTest.java
@@ -23,6 +23,7 @@ import com.netflix.discovery.EurekaEventListener;
 import com.netflix.discovery.shared.Application;
 import org.apache.seata.config.Configuration;
 import org.apache.seata.config.ConfigurationFactory;
+import org.apache.seata.config.exception.ConfigNotFoundException;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
@@ -97,6 +98,16 @@ public class EurekaRegistryServiceImplTest {
         
verify(mockAppInfoManager).setInstanceStatus(InstanceInfo.InstanceStatus.UP);
     }
 
+    @Test
+    void testRegisterWhenEurekaClientIsNull() throws Exception {
+        setStaticField(EurekaRegistryServiceImpl.class, "eurekaClient", null);
+        InetSocketAddress address = new InetSocketAddress("127.0.0.1", 8091);
+        registryService.register(address);
+        verify(mockAppInfoManager, times(0)).setInstanceStatus(any());
+    }
+
+
+
     @Test
     void testSubscribe() throws Exception {
         String testCluster = "TEST_CLUSTER";
@@ -125,6 +136,13 @@ public class EurekaRegistryServiceImplTest {
         verify(mockEurekaClient, 
times(1)).unregisterEventListener(mockEventListener);
     }
 
+    @Test
+    void testUnsubscribeWhenEurekaClientIsNull() throws Exception {
+        setStaticField(EurekaRegistryServiceImpl.class, "eurekaClient", null);
+        registryService.unsubscribe("TEST_CLUSTER", mockEventListener);
+        verify(mockEurekaClient, times(0)).unregisterEventListener(any());
+    }
+
     @Test
     void testUnsubscribeWithNoExistingListeners() throws Exception {
         String testCluster = "NON_EXISTENT_CLUSTER";
@@ -165,6 +183,17 @@ public class EurekaRegistryServiceImplTest {
         Assertions.assertEquals(new InetSocketAddress("192.168.1.1", 8091), 
addresses.get(0));
     }
 }
+    @Test
+    void testLookUpWithNoClusterName(){
+        Configuration mockConfig = mock(Configuration.class);
+        
when(mockConfig.getConfig("service.vgroupMapping.test-group")).thenReturn(null);
+        try (MockedStatic<ConfigurationFactory> mockedFactory = 
mockStatic(ConfigurationFactory.class)) {
+            
mockedFactory.when(ConfigurationFactory::getInstance).thenReturn(mockConfig);
+            Assertions.assertThrows(ConfigNotFoundException.class,()->{
+                registryService.lookup("test-group");
+            });
+        }
+    }
 
     @Test
     public void testClose() throws Exception {


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org
For additional commands, e-mail: notifications-h...@seata.apache.org

Reply via email to