|
13 | 13 | import org.slf4j.Logger; |
14 | 14 | import org.slf4j.LoggerFactory; |
15 | 15 |
|
| 16 | +import java.net.SocketException; |
16 | 17 | import java.time.Instant; |
17 | 18 | import java.util.Date; |
18 | 19 | import java.util.Optional; |
19 | 20 |
|
20 | 21 | import static org.hamcrest.MatcherAssert.assertThat; |
| 22 | +import static org.hamcrest.Matchers.instanceOf; |
21 | 23 | import static org.hamcrest.Matchers.is; |
22 | 24 | import static org.junit.jupiter.api.Assertions.assertFalse; |
| 25 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
23 | 26 |
|
24 | 27 | /** |
25 | 28 | * |
@@ -96,4 +99,35 @@ public void testParseRetryAfterSeconds() |
96 | 99 | Instant expected = Instant.ofEpochMilli(now).plusSeconds(120); |
97 | 100 | assertThat(retryAfter, is(expected)); |
98 | 101 | } |
| 102 | + |
| 103 | + @Test |
| 104 | + public void defaultExceptionResolverBrokenPipe() |
| 105 | + { |
| 106 | + SocketException socketException = new SocketException("Broken pipe"); |
| 107 | + TDClientException result = TDRequestErrorHandler.defaultExceptionResolver(socketException); |
| 108 | + assertThat(result, instanceOf(TDClientSocketException.class)); |
| 109 | + } |
| 110 | + |
| 111 | + @Test |
| 112 | + public void defaultExceptionResolverConnectionReset() |
| 113 | + { |
| 114 | + SocketException socketException = new SocketException("Connection reset"); |
| 115 | + TDClientException result = TDRequestErrorHandler.defaultExceptionResolver(socketException); |
| 116 | + assertThat(result, instanceOf(TDClientSocketException.class)); |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + public void defaultExceptionResolverSocketClosed() |
| 121 | + { |
| 122 | + SocketException socketException = new SocketException("Socket closed"); |
| 123 | + TDClientException result = TDRequestErrorHandler.defaultExceptionResolver(socketException); |
| 124 | + assertThat(result, instanceOf(TDClientSocketException.class)); |
| 125 | + } |
| 126 | + |
| 127 | + @Test |
| 128 | + public void defaultExceptionResolverUnknownSocketException() |
| 129 | + { |
| 130 | + SocketException socketException = new SocketException("Unknown socket error"); |
| 131 | + assertThrows(TDClientSocketException.class, () -> TDRequestErrorHandler.defaultExceptionResolver(socketException)); |
| 132 | + } |
99 | 133 | } |
0 commit comments