Skip to content

Commit a5722bd

Browse files
committed
add test
1 parent 32afe08 commit a5722bd

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/test/java/com/getindata/connectors/http/internal/table/lookup/JavaNetHttpPollingClientConnectionTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
import com.github.tomakehurst.wiremock.WireMockServer;
99
import com.github.tomakehurst.wiremock.client.MappingBuilder;
10+
import com.github.tomakehurst.wiremock.http.Fault;
1011
import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder;
12+
import com.github.tomakehurst.wiremock.stubbing.Scenario;
1113
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
1214
import org.apache.flink.api.common.serialization.DeserializationSchema;
1315
import org.apache.flink.api.common.serialization.SerializationSchema;
@@ -290,6 +292,45 @@ public void shouldConnectWithBasicAuth(String authorizationHeaderValue,
290292
assertThat(nestedDetailsRow.getString(0).toString()).isEqualTo("$1,729.34");
291293
}
292294

295+
@Test
296+
void shouldRetryOnIOExceptionAndSucceedOnSecondAttempt() {
297+
// GIVEN
298+
this.stubMapping = setUpServerStubForIOExceptionOnFirstAttempt();
299+
Properties properties = new Properties();
300+
properties.setProperty(
301+
HttpConnectorConfigConstants.LOOKUP_HTTP_MAX_RETRIES,
302+
"3"
303+
);
304+
JavaNetHttpPollingClient pollingClient = setUpPollingClient(
305+
getBaseUrl(), properties, setUpGetRequestFactory(properties));
306+
307+
// WHEN
308+
Optional<RowData> poll = pollingClient.pull(lookupRowData);
309+
310+
// THEN
311+
wireMockServer.verify(2, RequestPatternBuilder.forCustomMatcher(stubMapping.getRequest()));
312+
313+
assertThat(poll.isPresent()).isTrue();
314+
}
315+
316+
private StubMapping setUpServerStubForIOExceptionOnFirstAttempt() {
317+
wireMockServer.stubFor(
318+
get(urlEqualTo(ENDPOINT + "?id=1&uuid=2"))
319+
.inScenario("Retry Scenario")
320+
.whenScenarioStateIs(Scenario.STARTED) // Initial state
321+
.willReturn(aResponse()
322+
.withFault(Fault.CONNECTION_RESET_BY_PEER)) // Fail the first request
323+
.willSetStateTo("Second Attempt")); // Set the next state
324+
325+
return wireMockServer.stubFor(
326+
get(urlEqualTo(ENDPOINT + "?id=1&uuid=2"))
327+
.inScenario("Retry Scenario")
328+
.whenScenarioStateIs("Second Attempt") // When the state is "Second Attempt"
329+
.willReturn(aResponse()
330+
.withStatus(200)
331+
.withBody(readTestFile(SAMPLES_FOLDER + "HttpResult.json"))));
332+
}
333+
293334
private String getBaseUrl() {
294335
return wireMockServer.baseUrl() + ENDPOINT;
295336
}

0 commit comments

Comments
 (0)