BJ-228: Add error mapping for UnknownHostException (#28)

This commit is contained in:
Vladimir Pankrashkin 2017-09-22 12:50:16 +03:00 committed by GitHub
parent d9ecb9fbb1
commit 5c027dbbfc
6 changed files with 29 additions and 6 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>woody</artifactId>
<groupId>com.rbkmoney.woody</groupId>
<version>1.1.8</version>
<version>1.1.9</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -12,7 +12,7 @@
<packaging>pom</packaging>
<groupId>com.rbkmoney.woody</groupId>
<artifactId>woody</artifactId>
<version>1.1.8</version>
<version>1.1.9</version>
<description>Java implementation for Woody spec</description>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>woody</artifactId>
<groupId>com.rbkmoney.woody</groupId>
<version>1.1.8</version>
<version>1.1.9</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>woody</artifactId>
<groupId>com.rbkmoney.woody</groupId>
<version>1.1.8</version>
<version>1.1.9</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,6 @@ import com.rbkmoney.woody.api.flow.error.WErrorMapper;
import com.rbkmoney.woody.api.flow.error.WErrorSource;
import com.rbkmoney.woody.api.flow.error.WErrorType;
import com.rbkmoney.woody.api.trace.ContextSpan;
import org.apache.http.NoHttpResponseException;
import java.net.SocketTimeoutException;
import java.util.regex.Pattern;
@ -21,7 +20,8 @@ public class THTransportErrorMapper implements WErrorMapper {
return def;
}),
new ErrorAnalyzer(Pattern.compile("java.net.Socket.*"), THTransportErrorMapper::genUnavailableResult),
new ErrorAnalyzer(Pattern.compile(NoHttpResponseException.class.getName()), THTransportErrorMapper::genUnavailableResult),
new ErrorAnalyzer(Pattern.compile(org.apache.http.NoHttpResponseException.class.getName()), THTransportErrorMapper::genUnavailableResult),
new ErrorAnalyzer(Pattern.compile(java.net.UnknownHostException.class.getName()), THTransportErrorMapper::genUnavailableResult),
};
private static WErrorDefinition genUnavailableResult(Throwable t, ContextSpan c) {

View File

@ -5,6 +5,7 @@ import com.rbkmoney.woody.api.flow.error.WErrorSource;
import com.rbkmoney.woody.api.flow.error.WErrorType;
import com.rbkmoney.woody.api.flow.error.WRuntimeException;
import com.rbkmoney.woody.api.generator.TimestampIdGenerator;
import com.rbkmoney.woody.api.trace.ContextUtils;
import com.rbkmoney.woody.rpc.Owner;
import com.rbkmoney.woody.rpc.OwnerServiceSrv;
import com.rbkmoney.woody.rpc.test_error;
@ -12,6 +13,7 @@ import com.rbkmoney.woody.thrift.impl.http.event.THClientEvent;
import org.apache.thrift.TException;
import org.junit.Test;
import java.net.UnknownHostException;
import java.util.concurrent.Semaphore;
import static org.junit.Assert.*;
@ -76,6 +78,15 @@ public class TestTransportErrorMapper extends AbstractTest {
}
});
OwnerServiceSrv.Iface unknownHostClient = createThriftRPCClient(OwnerServiceSrv.Iface.class, new TimestampIdGenerator(), (ClientEventListener<THClientEvent>) (THClientEvent thClientEvent) -> {
switch (thClientEvent.getEventType()) {
case ERROR:
assertFalse(thClientEvent.isSuccessfulCall());
assertEquals(WErrorType.UNAVAILABLE_RESULT, thClientEvent.getErrorDefinition().getErrorType());
break;
}
}, "http://wronghost:" + serverPort);
@Test
public void testSocketTimeoutError() throws TException {
//Socket timeout expected
@ -115,4 +126,16 @@ public class TestTransportErrorMapper extends AbstractTest {
t.join();
}
@Test
public void testUnknownHostError() throws TException {
try {
unknownHostClient.getOwner(0);
fail();
} catch (WRuntimeException e) {
assertEquals("Network timeout expected", WErrorType.UNAVAILABLE_RESULT, e.getErrorDefinition().getErrorType());
assertEquals("Error returned for root client request", WErrorSource.INTERNAL, e.getErrorDefinition().getErrorSource());
assertEquals("Generation source is external for all network errors", WErrorSource.EXTERNAL, e.getErrorDefinition().getGenerationSource());
}
}
}