17
17
package com .alipay .sofa .rpc .bootstrap .dubbo ;
18
18
19
19
import com .alibaba .dubbo .common .Constants ;
20
- import com . alibaba .dubbo .common .utils . ConfigUtils ;
20
+ import org . apache .dubbo .common .constants . CommonConstants ;
21
21
import com .alibaba .dubbo .rpc .RpcContext ;
22
22
import com .alibaba .dubbo .rpc .service .GenericService ;
23
23
import com .alipay .sofa .rpc .bootstrap .dubbo .demo .DemoService ;
32
32
import com .alipay .sofa .rpc .context .RpcInvokeContext ;
33
33
import com .alipay .sofa .rpc .context .RpcRunningState ;
34
34
import com .alipay .sofa .rpc .context .RpcRuntimeContext ;
35
+ import org .apache .dubbo .config .ConfigKeys ;
36
+ import org .apache .dubbo .config .context .ConfigMode ;
35
37
import org .junit .After ;
36
38
import org .junit .AfterClass ;
37
39
import org .junit .Assert ;
@@ -52,10 +54,50 @@ public class DubooServerTest {
52
54
53
55
ConsumerConfig <DemoService > consumerConfig ;
54
56
57
+ private static String OLD_VALUE_SHUTDOWN_WAIT_KEY ;
58
+ private static String OLD_VALUE_DUBBO_CONFIG_IGNORE_DUPLICATED_INTERFACE ;
59
+ private static String OLD_VALUE_DUBBO_CONFIG_MODE ;
60
+
55
61
//dubbo close wait time
56
- @ AfterClass
62
+ @ BeforeClass
57
63
public static void before () {
58
- ConfigUtils .getProperties ().put (Constants .SHUTDOWN_WAIT_KEY , "1" );
64
+ RpcRunningState .setUnitTestMode (true );
65
+ OLD_VALUE_SHUTDOWN_WAIT_KEY = System .getProperty (CommonConstants .SHUTDOWN_WAIT_KEY );
66
+ OLD_VALUE_DUBBO_CONFIG_IGNORE_DUPLICATED_INTERFACE = System
67
+ .getProperty (ConfigKeys .DUBBO_CONFIG_IGNORE_DUPLICATED_INTERFACE );
68
+ OLD_VALUE_DUBBO_CONFIG_MODE = System .getProperty (ConfigKeys .DUBBO_CONFIG_MODE );
69
+
70
+ System .setProperty (CommonConstants .SHUTDOWN_WAIT_KEY , "1" );
71
+ System .setProperty (ConfigKeys .DUBBO_CONFIG_IGNORE_DUPLICATED_INTERFACE , "true" );
72
+ System .setProperty (ConfigKeys .DUBBO_CONFIG_MODE , ConfigMode .IGNORE .name ());
73
+ }
74
+
75
+ @ AfterClass
76
+ public static void after () {
77
+ if (OLD_VALUE_SHUTDOWN_WAIT_KEY == null ) {
78
+ System .clearProperty (CommonConstants .SHUTDOWN_WAIT_KEY );
79
+ } else {
80
+ System .setProperty (CommonConstants .SHUTDOWN_WAIT_KEY , OLD_VALUE_SHUTDOWN_WAIT_KEY );
81
+ }
82
+
83
+ if (OLD_VALUE_DUBBO_CONFIG_IGNORE_DUPLICATED_INTERFACE == null ) {
84
+ System .clearProperty (ConfigKeys .DUBBO_CONFIG_IGNORE_DUPLICATED_INTERFACE );
85
+ } else {
86
+ System .setProperty (ConfigKeys .DUBBO_CONFIG_IGNORE_DUPLICATED_INTERFACE ,
87
+ OLD_VALUE_DUBBO_CONFIG_IGNORE_DUPLICATED_INTERFACE );
88
+ }
89
+
90
+ if (OLD_VALUE_DUBBO_CONFIG_MODE == null ) {
91
+ System .clearProperty (ConfigKeys .DUBBO_CONFIG_MODE );
92
+ } else {
93
+ System .setProperty (ConfigKeys .DUBBO_CONFIG_MODE , OLD_VALUE_DUBBO_CONFIG_MODE );
94
+ }
95
+ }
96
+
97
+ @ After
98
+ public void afterMethod () {
99
+ RpcInternalContext .removeAllContext ();
100
+ RpcInvokeContext .removeContext ();
59
101
}
60
102
61
103
@ Test
@@ -288,7 +330,7 @@ public void testWithParameterWithVersion() {
288
330
}
289
331
}
290
332
291
- @ Test (expected = com . alibaba .dubbo .rpc .RpcException .class )
333
+ @ Test (expected = org . apache .dubbo .rpc .RpcException .class )
292
334
//同步调用,直连,dubbo 消费没有指定dubbo服务版本version
293
335
public void testConsumerWithNoDubboServiceVersion () {
294
336
// 只有1个线程 执行
@@ -324,17 +366,4 @@ public void testConsumerWithNoDubboServiceVersion() {
324
366
Assert .assertTrue (result .equalsIgnoreCase ("hello xxx" ));
325
367
326
368
}
327
-
328
- @ BeforeClass
329
- public static void adBeforeClass () {
330
- RpcRunningState .setUnitTestMode (true );
331
- }
332
-
333
- @ After
334
- public void afterMethod () {
335
- DubboSingleton .destroyAll ();
336
- RpcRuntimeContext .destroy ();
337
- RpcInternalContext .removeAllContext ();
338
- RpcInvokeContext .removeContext ();
339
- }
340
369
}
0 commit comments