Skip to content

Commit 9d44dd4

Browse files
authored
Add test covering the default retry behavior of HTTP client 5 (#1004)
1 parent 2eb0713 commit 9d44dd4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cloudplatform/connectivity-apache-httpclient5/src/test/java/com/sap/cloud/sdk/cloudplatform/connectivity/DefaultApacheHttpClient5FactoryTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.sap.cloud.sdk.cloudplatform.connectivity;
22

3+
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
34
import static com.github.tomakehurst.wiremock.client.WireMock.get;
45
import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;
56
import static com.github.tomakehurst.wiremock.client.WireMock.ok;
@@ -213,6 +214,21 @@ void testProxyConfigurationIsConsidered()
213214
}
214215
}
215216

217+
@Test
218+
@SneakyThrows
219+
void verifyDefaultRetryMechanism()
220+
{
221+
WIRE_MOCK_SERVER.stubFor(get(urlEqualTo("/too-many-requests")).willReturn(aResponse().withStatus(429)));
222+
WIRE_MOCK_SERVER.stubFor(get(urlEqualTo("/temporary-error")).willReturn(aResponse().withStatus(503)));
223+
224+
final HttpClient client = sut.createHttpClient();
225+
client.execute(new HttpGet(WIRE_MOCK_SERVER.url("/too-many-requests")), ignored -> ignored);
226+
client.execute(new HttpGet(WIRE_MOCK_SERVER.url("/temporary-error")), ignored -> ignored);
227+
228+
WIRE_MOCK_SERVER.verify(2, getRequestedFor(urlEqualTo("/too-many-requests")));
229+
WIRE_MOCK_SERVER.verify(2, getRequestedFor(urlEqualTo("/temporary-error")));
230+
}
231+
216232
@SneakyThrows
217233
private void assertCannotBeExecutedInParallel(
218234
@Nonnull final ClassicHttpRequest firstRequest,

0 commit comments

Comments
 (0)