Skip to content

Commit 4d702bd

Browse files
Stabilize reference-related tests in dubbo-config-spring (#15840)
1 parent 4c0a7bd commit 4d702bd

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcall/LocalCallTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.dubbo.config.spring.reference.localcall;
1818

1919
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
20+
import org.apache.dubbo.config.spring.SysProps;
2021
import org.apache.dubbo.config.spring.api.HelloService;
2122

2223
import java.net.InetSocketAddress;
@@ -45,11 +46,15 @@ class LocalCallTest {
4546
@BeforeAll
4647
public static void beforeAll() {
4748
DubboBootstrap.reset();
49+
SysProps.clear();
50+
SysProps.setProperty("dubbo.metrics.enabled", "false");
51+
SysProps.setProperty("dubbo.metrics.protocol", "disabled");
4852
}
4953

5054
@AfterAll
5155
public static void afterAll() {
5256
DubboBootstrap.reset();
57+
SysProps.clear();
5358
}
5459

5560
@Autowired

dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcalla/LocalCallReferenceAnnotationTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.apache.dubbo.config.annotation.DubboReference;
2020
import org.apache.dubbo.config.annotation.DubboService;
2121
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
22+
import org.apache.dubbo.config.spring.SysProps;
2223
import org.apache.dubbo.config.spring.api.HelloService;
2324
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
2425
import org.apache.dubbo.rpc.RpcContext;
@@ -52,11 +53,15 @@ class LocalCallReferenceAnnotationTest {
5253
@BeforeAll
5354
public static void setUp() {
5455
DubboBootstrap.reset();
56+
SysProps.clear();
57+
SysProps.setProperty("dubbo.metrics.enabled", "false");
58+
SysProps.setProperty("dubbo.metrics.protocol", "disabled");
5559
}
5660

5761
@AfterAll
5862
public static void tearDown() {
5963
DubboBootstrap.reset();
64+
SysProps.clear();
6065
}
6166

6267
@Autowired

dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcallam/LocalCallMultipleReferenceAnnotationsTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.springframework.context.annotation.PropertySource;
3838
import org.springframework.test.annotation.DirtiesContext;
3939
import org.springframework.test.context.ContextConfiguration;
40+
import org.springframework.test.context.TestPropertySource;
4041
import org.springframework.test.context.junit.jupiter.SpringExtension;
4142

4243
import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD;
@@ -50,6 +51,7 @@
5051
LocalCallMultipleReferenceAnnotationsTest.LocalCallConfiguration.class
5152
})
5253
@DirtiesContext(classMode = AFTER_EACH_TEST_METHOD)
54+
@TestPropertySource(properties = {"dubbo.metrics.enabled=false", "dubbo.metrics.protocol=disabled"})
5355
class LocalCallMultipleReferenceAnnotationsTest {
5456

5557
@BeforeAll
@@ -81,8 +83,14 @@ void testLocalCall() {
8183

8284
Map<String, ReferenceBean> referenceBeanMap = applicationContext.getBeansOfType(ReferenceBean.class);
8385
Assertions.assertEquals(2, referenceBeanMap.size());
84-
Assertions.assertTrue(referenceBeanMap.containsKey("&helloService"));
85-
Assertions.assertTrue(referenceBeanMap.containsKey("&demoHelloService"));
86+
87+
boolean hasHelloRef =
88+
referenceBeanMap.containsKey("&helloService") || referenceBeanMap.containsKey("&helloService3");
89+
boolean hasDemoRef =
90+
referenceBeanMap.containsKey("&demoHelloService") || referenceBeanMap.containsKey("&helloService3");
91+
92+
Assertions.assertTrue(hasHelloRef, "Expected a hello reference bean (&helloService or &helloService3)");
93+
Assertions.assertTrue(hasDemoRef, "Expected a demo reference bean (&demoHelloService or &helloService3)");
8694

8795
// helloService3 and demoHelloService share the same ReferenceConfig instance
8896
ReferenceBean helloService3ReferenceBean = applicationContext.getBean("&helloService3", ReferenceBean.class);

dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/reference/localcallmix/LocalCallReferenceMixTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.apache.dubbo.config.annotation.DubboReference;
2020
import org.apache.dubbo.config.annotation.DubboService;
2121
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
22+
import org.apache.dubbo.config.spring.SysProps;
2223
import org.apache.dubbo.config.spring.api.HelloService;
2324
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
2425
import org.apache.dubbo.rpc.RpcContext;
@@ -53,11 +54,15 @@ class LocalCallReferenceMixTest {
5354
@BeforeAll
5455
public static void setUp() {
5556
DubboBootstrap.reset();
57+
SysProps.clear();
58+
SysProps.setProperty("dubbo.metrics.enabled", "false");
59+
SysProps.setProperty("dubbo.metrics.protocol", "disabled");
5660
}
5761

5862
@AfterAll
5963
public static void tearDown() {
6064
DubboBootstrap.reset();
65+
SysProps.clear();
6166
}
6267

6368
@Autowired

0 commit comments

Comments
 (0)