|
6 | 6 | import org.apache.http.HttpStatus; |
7 | 7 | import org.apache.http.StatusLine; |
8 | 8 | import org.apache.http.client.methods.CloseableHttpResponse; |
| 9 | +import org.apache.http.conn.ConnectTimeoutException; |
9 | 10 | import org.apache.http.impl.client.CloseableHttpClient; |
10 | 11 | import org.apache.http.impl.client.HttpClientBuilder; |
11 | 12 | import org.apache.http.message.BasicStatusLine; |
@@ -102,4 +103,28 @@ public void testExecuteGet_StatusOk() throws IOException { |
102 | 103 | ServiceNowTableAPIClientImpl client = new ServiceNowTableAPIClientImpl(config, true); |
103 | 104 | client.executeGet(request); |
104 | 105 | } |
| 106 | + |
| 107 | + @Test |
| 108 | + public void testExecuteGet_throwConnectTimeoutException_markAsRetryable() throws IOException { |
| 109 | + CloseableHttpClient httpClient = Mockito.mock(CloseableHttpClient.class); |
| 110 | + HttpClientBuilder httpClientBuilder = Mockito.mock(HttpClientBuilder.class); |
| 111 | + PowerMockito.mockStatic(HttpClientBuilder.class); |
| 112 | + PowerMockito.when(HttpClientBuilder.create()).thenReturn(httpClientBuilder); |
| 113 | + Mockito.when(httpClientBuilder.build()).thenReturn(httpClient); |
| 114 | + Mockito.when(httpClient.execute(Mockito.any())) |
| 115 | + .thenThrow(new ConnectTimeoutException("Connection timed out")); |
| 116 | + |
| 117 | + |
| 118 | + ServiceNowTableAPIRequestBuilder builder = new ServiceNowTableAPIRequestBuilder("url"); |
| 119 | + RestAPIRequest request = builder.build(); |
| 120 | + |
| 121 | + ServiceNowConnectorConfig config = Mockito.mock(ServiceNowConnectorConfig.class); |
| 122 | + ServiceNowTableAPIClientImpl client = new ServiceNowTableAPIClientImpl(config, true); |
| 123 | + RestAPIResponse actualResponse = client.executeGet(request); |
| 124 | + Assert.assertNotNull(actualResponse.getException()); |
| 125 | + Assert.assertTrue(actualResponse.getException().isErrorRetryable()); |
| 126 | + Throwable ex = actualResponse.getException().getCause(); |
| 127 | + Assert.assertTrue("Expected ConnectTimeoutException or similar, got: " + ex, |
| 128 | + ex instanceof ConnectTimeoutException || ex.getMessage().toLowerCase().contains("Connection timed out")); |
| 129 | + } |
105 | 130 | } |
0 commit comments