Commit 2b14a3df authored by 吴梦升's avatar 吴梦升 Committed by Jason Song

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

parent aa184a2e
...@@ -182,6 +182,7 @@ public class RemoteConfigRepository extends AbstractConfigRepository { ...@@ -182,6 +182,7 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
List<ServiceDTO> configServices = getConfigServices(); List<ServiceDTO> configServices = getConfigServices();
String url = null; String url = null;
retryLoopLabel:
for (int i = 0; i < maxRetries; i++) { for (int i = 0; i < maxRetries; i++) {
List<ServiceDTO> randomConfigServices = Lists.newLinkedList(configServices); List<ServiceDTO> randomConfigServices = Lists.newLinkedList(configServices);
Collections.shuffle(randomConfigServices); Collections.shuffle(randomConfigServices);
...@@ -249,6 +250,9 @@ public class RemoteConfigRepository extends AbstractConfigRepository { ...@@ -249,6 +250,9 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
Tracer.logEvent("ApolloConfigException", ExceptionUtil.getDetailMessage(statusCodeException)); Tracer.logEvent("ApolloConfigException", ExceptionUtil.getDetailMessage(statusCodeException));
transaction.setStatus(statusCodeException); transaction.setStatus(statusCodeException);
exception = statusCodeException; exception = statusCodeException;
if(ex.getStatusCode() == 404) {
break retryLoopLabel;
}
} catch (Throwable ex) { } catch (Throwable ex) {
Tracer.logEvent("ApolloConfigException", ExceptionUtil.getDetailMessage(ex)); Tracer.logEvent("ApolloConfigException", ExceptionUtil.getDetailMessage(ex));
transaction.setStatus(ex); transaction.setStatus(ex);
......
...@@ -22,6 +22,7 @@ import com.ctrip.framework.apollo.core.dto.ServiceDTO; ...@@ -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.core.signature.Signature;
import com.ctrip.framework.apollo.enums.ConfigSourceType; import com.ctrip.framework.apollo.enums.ConfigSourceType;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException; 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.ConfigUtil;
import com.ctrip.framework.apollo.util.OrderedProperties; import com.ctrip.framework.apollo.util.OrderedProperties;
import com.ctrip.framework.apollo.util.factory.PropertiesFactory; import com.ctrip.framework.apollo.util.factory.PropertiesFactory;
...@@ -208,6 +209,19 @@ public class RemoteConfigRepositoryTest { ...@@ -208,6 +209,19 @@ public class RemoteConfigRepositoryTest {
remoteConfigRepository.getConfig(); 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 @Test
public void testRepositoryChangeListener() throws Exception { public void testRepositoryChangeListener() throws Exception {
Map<String, String> configurations = ImmutableMap.of("someKey", "someValue"); Map<String, String> configurations = ImmutableMap.of("someKey", "someValue");
...@@ -394,7 +408,8 @@ public class RemoteConfigRepositoryTest { ...@@ -394,7 +408,8 @@ public class RemoteConfigRepositoryTest {
if (someResponse.getStatusCode() == 200 || someResponse.getStatusCode() == 304) { if (someResponse.getStatusCode() == 200 || someResponse.getStatusCode() == 304) {
return (HttpResponse<T>) someResponse; 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())); someResponse.getStatusCode()));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment