Skip to content

Commit 95cf37c

Browse files
committed
dramatically improve the apollo client unit test performance
1 parent 91f5b94 commit 95cf37c

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigServiceLocator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private synchronized void updateConfigServices() {
131131
}
132132

133133
try {
134-
TimeUnit.SECONDS.sleep(1);
134+
m_configUtil.getOnErrorRetryIntervalTimeUnit().sleep(m_configUtil.getOnErrorRetryInterval());
135135
} catch (InterruptedException ex) {
136136
//ignore
137137
}

apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ private ApolloConfig loadApolloConfig() {
228228
}
229229

230230
try {
231-
TimeUnit.SECONDS.sleep(1);
231+
m_configUtil.getOnErrorRetryIntervalTimeUnit().sleep(m_configUtil.getOnErrorRetryInterval());
232232
} catch (InterruptedException ex) {
233233
//ignore
234234
}

apollo-client/src/main/java/com/ctrip/framework/apollo/util/ConfigUtil.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public class ConfigUtil {
2929
private String cluster;
3030
private int loadConfigQPS = 2; //2 times per second
3131
private int longPollQPS = 2; //2 times per second
32+
//for on error retry
33+
private long onErrorRetryInterval = 1;//1 second
34+
private TimeUnit onErrorRetryIntervalTimeUnit = TimeUnit.SECONDS;//1 second
3235
//for typed config cache of parser result, e.g. integer, double, long, etc.
3336
private long maxConfigCacheSize = 500;//500 cache key
3437
private long configCacheExpireTime = 1;//1 minute
@@ -212,6 +215,14 @@ public int getLongPollQPS() {
212215
return longPollQPS;
213216
}
214217

218+
public long getOnErrorRetryInterval() {
219+
return onErrorRetryInterval;
220+
}
221+
222+
public TimeUnit getOnErrorRetryIntervalTimeUnit() {
223+
return onErrorRetryIntervalTimeUnit;
224+
}
225+
215226
public String getDefaultLocalCacheDir() {
216227
String cacheRoot = isOSWindows() ? "C:\\opt\\data\\%s" : "/opt/data/%s";
217228
return String.format(cacheRoot, getAppId());

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,16 @@ public int getLongPollQPS() {
182182
public String getDefaultLocalCacheDir() {
183183
return ClassLoaderUtil.getClassPath();
184184
}
185+
186+
@Override
187+
public long getOnErrorRetryInterval() {
188+
return 10;
189+
}
190+
191+
@Override
192+
public TimeUnit getOnErrorRetryIntervalTimeUnit() {
193+
return TimeUnit.MILLISECONDS;
194+
}
185195
}
186196

187197
/**

apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,16 @@ public int getLoadConfigQPS() {
233233
public int getLongPollQPS() {
234234
return 200;
235235
}
236+
237+
@Override
238+
public long getOnErrorRetryInterval() {
239+
return 10;
240+
}
241+
242+
@Override
243+
public TimeUnit getOnErrorRetryIntervalTimeUnit() {
244+
return TimeUnit.MILLISECONDS;
245+
}
236246
}
237247

238248
public static class MockConfigServiceLocator extends ConfigServiceLocator {

0 commit comments

Comments
 (0)