提交 2b14a3df 编写于 作者: WMS's avatar WMS 提交者: Jason Song

[修改]针对配置未发布场景取消重试和mockhttputil异常与业务实现保持一致

上级 aa184a2e
......@@ -182,6 +182,7 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
List<ServiceDTO> configServices = getConfigServices();
String url = null;
retryLoopLabel:
for (int i = 0; i < maxRetries; i++) {
List<ServiceDTO> randomConfigServices = Lists.newLinkedList(configServices);
Collections.shuffle(randomConfigServices);
......@@ -249,6 +250,9 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
Tracer.logEvent("ApolloConfigException", ExceptionUtil.getDetailMessage(statusCodeException));
transaction.setStatus(statusCodeException);
exception = statusCodeException;
if(ex.getStatusCode() == 404) {
break retryLoopLabel;
}
} catch (Throwable ex) {
Tracer.logEvent("ApolloConfigException", ExceptionUtil.getDetailMessage(ex));
transaction.setStatus(ex);
......
......@@ -22,6 +22,7 @@ import com.ctrip.framework.apollo.core.dto.ServiceDTO;
import com.ctrip.framework.apollo.core.signature.Signature;
import com.ctrip.framework.apollo.enums.ConfigSourceType;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.exceptions.ApolloConfigStatusCodeException;
import com.ctrip.framework.apollo.util.ConfigUtil;
import com.ctrip.framework.apollo.util.OrderedProperties;
import com.ctrip.framework.apollo.util.factory.PropertiesFactory;
......@@ -208,6 +209,19 @@ public class RemoteConfigRepositoryTest {
remoteConfigRepository.getConfig();
}
@Test(expected = ApolloConfigException.class)
public void testGetRemoteConfigWithNotFount() throws Exception {
when(someResponse.getStatusCode()).thenReturn(404);
RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someNamespace);
//must stop the long polling before exception occurred
remoteConfigLongPollService.stopLongPollingRefresh();
remoteConfigRepository.getConfig();
}
@Test
public void testRepositoryChangeListener() throws Exception {
Map<String, String> configurations = ImmutableMap.of("someKey", "someValue");
......@@ -394,7 +408,8 @@ public class RemoteConfigRepositoryTest {
if (someResponse.getStatusCode() == 200 || someResponse.getStatusCode() == 304) {
return (HttpResponse<T>) someResponse;
}
throw new ApolloConfigException(String.format("Http request failed due to status code: %d",
throw new ApolloConfigStatusCodeException(someResponse.getStatusCode(),
String.format("Http request failed due to status code: %d",
someResponse.getStatusCode()));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册