|
15 | 15 |
|
16 | 16 | package software.amazon.awssdk.protocol.tests.timeout.async;
|
17 | 17 |
|
18 |
| -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; |
19 |
| -import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl; |
20 |
| -import static com.github.tomakehurst.wiremock.client.WireMock.post; |
21 |
| -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; |
22 | 18 | import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
23 | 19 | import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
24 | 20 |
|
|
36 | 32 | import software.amazon.awssdk.core.async.AsyncResponseTransformer;
|
37 | 33 | import software.amazon.awssdk.core.exception.ApiCallTimeoutException;
|
38 | 34 | import software.amazon.awssdk.core.retry.RetryPolicy;
|
| 35 | +import software.amazon.awssdk.http.HttpExecuteResponse; |
| 36 | +import software.amazon.awssdk.http.SdkHttpResponse; |
39 | 37 | import software.amazon.awssdk.protocol.tests.timeout.BaseApiCallTimeoutTest;
|
| 38 | +import software.amazon.awssdk.protocol.tests.util.MockAsyncHttpClient; |
40 | 39 | import software.amazon.awssdk.regions.Region;
|
41 | 40 | import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClient;
|
42 | 41 | import software.amazon.awssdk.services.protocolrestjson.model.AllTypesResponse;
|
@@ -104,13 +103,34 @@ protected WireMockRule wireMock() {
|
104 | 103 |
|
105 | 104 | @Test
|
106 | 105 | public void increaseTimeoutInRequestOverrideConfig_shouldTakePrecedence() {
|
107 |
| - stubFor(post(anyUrl()) |
108 |
| - .willReturn(aResponse().withStatus(200).withBody("{}").withFixedDelay(DELAY_AFTER_TIMEOUT))); |
| 106 | + MockAsyncHttpClient mockClient = new MockAsyncHttpClient(); |
| 107 | + ProtocolRestJsonAsyncClient asyncClient = createClientWithMockClient(mockClient); |
| 108 | + mockClient.stubNextResponse(mockResponse(200)); |
| 109 | + mockClient.withFixedDelay(DELAY_AFTER_TIMEOUT); |
| 110 | + |
109 | 111 | CompletableFuture<AllTypesResponse> allTypesResponseCompletableFuture =
|
110 |
| - client.allTypes(b -> b.overrideConfiguration(c -> c.apiCallTimeout(Duration.ofMillis(DELAY_AFTER_TIMEOUT + 1000)))); |
| 112 | + asyncClient.allTypes(b -> b.overrideConfiguration(c -> c.apiCallTimeout(Duration.ofMillis(DELAY_AFTER_TIMEOUT + 1000)))); |
111 | 113 |
|
112 | 114 | AllTypesResponse response = allTypesResponseCompletableFuture.join();
|
113 | 115 | assertThat(response).isNotNull();
|
114 | 116 | }
|
115 | 117 |
|
| 118 | + public ProtocolRestJsonAsyncClient createClientWithMockClient(MockAsyncHttpClient mockClient) { |
| 119 | + return ProtocolRestJsonAsyncClient.builder() |
| 120 | + .region(Region.US_WEST_1) |
| 121 | + .httpClient(mockClient) |
| 122 | + .credentialsProvider(() -> AwsBasicCredentials.create("akid", "skid")) |
| 123 | + .overrideConfiguration(b -> b.apiCallTimeout(Duration.ofMillis(TIMEOUT)) |
| 124 | + .retryPolicy(RetryPolicy.none())) |
| 125 | + .build(); |
| 126 | + } |
| 127 | + |
| 128 | + private HttpExecuteResponse mockResponse(int statusCode) { |
| 129 | + return HttpExecuteResponse.builder() |
| 130 | + .response(SdkHttpResponse.builder() |
| 131 | + .statusCode(statusCode) |
| 132 | + .build()) |
| 133 | + .build(); |
| 134 | + } |
| 135 | + |
116 | 136 | }
|
0 commit comments