Skip to content

Commit 041fdf4

Browse files
committed
fix potential test error issue
1 parent 0560bf5 commit 041fdf4

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

apollo-client/src/test/java/com/ctrip/framework/apollo/BaseIntegrationTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.ctrip.framework.apollo;
1818

1919
import com.ctrip.framework.apollo.core.ConfigConsts;
20+
import com.ctrip.framework.apollo.core.MetaDomainConsts;
2021
import java.io.IOException;
2122
import java.net.ServerSocket;
2223
import java.util.concurrent.TimeUnit;
@@ -43,6 +44,7 @@
4344
import com.ctrip.framework.apollo.util.ConfigUtil;
4445
import com.google.common.collect.Lists;
4546
import com.google.gson.Gson;
47+
import org.springframework.test.util.ReflectionTestUtils;
4648

4749
/**
4850
* @author Jason Song([email protected])
@@ -90,6 +92,7 @@ public void tearDown() throws Exception {
9092
//as ConfigService is singleton, so we must manually clear its container
9193
ConfigService.reset();
9294
MockInjector.reset();
95+
ReflectionTestUtils.invokeMethod(MetaDomainConsts.class, "reset");
9396

9497
if (server != null && server.isStarted()) {
9598
server.stop();

apollo-client/src/test/java/com/ctrip/framework/apollo/ConfigServiceTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static org.junit.Assert.assertEquals;
2020

21+
import com.ctrip.framework.apollo.core.MetaDomainConsts;
2122
import com.ctrip.framework.apollo.enums.ConfigSourceType;
2223
import java.util.Set;
2324

@@ -31,6 +32,7 @@
3132
import com.ctrip.framework.apollo.internals.AbstractConfig;
3233
import com.ctrip.framework.apollo.spi.ConfigFactory;
3334
import com.ctrip.framework.apollo.util.ConfigUtil;
35+
import org.springframework.test.util.ReflectionTestUtils;
3436

3537
/**
3638
* @author Jason Song([email protected])
@@ -50,6 +52,7 @@ public void tearDown() throws Exception {
5052
//as ConfigService is singleton, so we must manually clear its container
5153
ConfigService.reset();
5254
MockInjector.reset();
55+
ReflectionTestUtils.invokeMethod(MetaDomainConsts.class, "reset");
5356
}
5457

5558
@Test

apollo-core/src/main/java/com/ctrip/framework/apollo/core/MetaDomainConsts.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,12 @@ public void run() {
229229
}
230230
}, REFRESH_INTERVAL_IN_SECOND, REFRESH_INTERVAL_IN_SECOND, TimeUnit.SECONDS);
231231
}
232+
233+
// for test only
234+
static void reset() {
235+
metaServerAddressCache.clear();
236+
selectedMetaServerAddressCache.clear();
237+
metaServerProviders = null;
238+
periodicRefreshStarted.set(false);
239+
}
232240
}

0 commit comments

Comments
 (0)