diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b186ca6..ffa3390 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,29 +20,28 @@ jobs: tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' - - name: Build with Gradle - uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0 - with: - arguments: jacocoTestReport + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + - name: Build and test + run: ./gradlew test javadoc: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - - name: Build with Gradle - uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0 - with: - arguments: javadoc - - + - name: Checkout sources + uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + - name: Build and test + run: ./gradlew javadoc \ No newline at end of file diff --git a/src/main/java/org/broadinstitute/http/nio/RetryHandler.java b/src/main/java/org/broadinstitute/http/nio/RetryHandler.java index e379ce3..404c099 100644 --- a/src/main/java/org/broadinstitute/http/nio/RetryHandler.java +++ b/src/main/java/org/broadinstitute/http/nio/RetryHandler.java @@ -12,6 +12,7 @@ import java.net.SocketException; import java.net.SocketTimeoutException; import java.net.URI; +import java.nio.channels.ClosedChannelException; import java.time.Duration; import java.time.Instant; import java.util.Collection; @@ -31,8 +32,10 @@ public class RetryHandler { /** * the default set of exception messages which are retried when encountered */ - public static final Set DEFALT_RETRYABLE_MESSAGES = Set.of("protocol error:"); - //IOExceptions with the string `protocol error` can happen when there is bad data returned during an http request + public static final Set DEFALT_RETRYABLE_MESSAGES = Set.of( + "protocol error:", //IOExceptions with the string `protocol error` can happen when there is bad data returned during an http request + "Connection reset by peer"); + /** * default set of exception types which will be retried when encountered @@ -42,7 +45,8 @@ public class RetryHandler { EOFException.class, SocketException.class, SocketTimeoutException.class, - InterruptedIOException.class + InterruptedIOException.class, + ClosedChannelException.class ); /** diff --git a/src/test/java/org/broadinstitute/http/nio/MockedIntegrationTest.java b/src/test/java/org/broadinstitute/http/nio/MockedIntegrationTest.java index 73c139f..f6eb47a 100644 --- a/src/test/java/org/broadinstitute/http/nio/MockedIntegrationTest.java +++ b/src/test/java/org/broadinstitute/http/nio/MockedIntegrationTest.java @@ -33,6 +33,7 @@ public class MockedIntegrationTest extends BaseTest { public static final UrlPattern FILE_URL = urlEqualTo("/file.txt"); public static final String BODY = "Hello"; + public static final String LOCAL_HOST = "127.0.0.1"; // the string localhost seems to be problematic on github actions but the IP may work better WireMockServer wireMockServer; WireMock wireMock; @@ -42,8 +43,8 @@ void start(){ .wireMockConfig() .dynamicPort()); wireMockServer.start(); - configureFor("localhost", wireMockServer.port()); - wireMock = new WireMock("localhost", wireMockServer.port()); + configureFor(LOCAL_HOST, wireMockServer.port()); + wireMock = new WireMock(LOCAL_HOST, wireMockServer.port()); } @AfterMethod @@ -76,7 +77,6 @@ public Object[][] getFaults(){ } @Test(dataProvider = "getFaults", expectedExceptions = OutOfRetriesException.class) public void testConnectionReset(Fault fault) throws IOException { - final String body = "Hello"; final UrlPattern fileUrl = urlEqualTo("/file.txt"); wireMockServer.stubFor(get(fileUrl) .willReturn(aResponse().withFault(fault))); @@ -89,12 +89,13 @@ public void testConnectionReset(Fault fault) throws IOException { @Test public void testRetryFixesError() throws IOException { final String body = "Hello"; + final long bodyLength = body.getBytes(StandardCharsets.UTF_8).length; + wireMockServer.stubFor(get(FILE_URL).inScenario("fail once") .whenScenarioStateIs(Scenario.STARTED) .willReturn(aResponse().withFault(Fault.CONNECTION_RESET_BY_PEER)) .willSetStateTo("errored")); - final long bodyLength = body.getBytes(StandardCharsets.UTF_8).length; wireMockServer.stubFor(get(FILE_URL).inScenario("fail once") .whenScenarioStateIs("errored") .willReturn(ok(body).withHeader("content-length", String.valueOf(bodyLength))) @@ -114,7 +115,7 @@ public void testRetryFixesError() throws IOException { final URI uri = getUri("/file.txt"); final HttpFileSystemProviderSettings settings = new HttpFileSystemProviderSettings(Duration.ofSeconds(2), HttpClient.Redirect.NORMAL, - new HttpFileSystemProviderSettings.RetrySettings(1, RetryHandler.DEFAULT_RETRYABLE_HTTP_CODES, + new HttpFileSystemProviderSettings.RetrySettings(2, RetryHandler.DEFAULT_RETRYABLE_HTTP_CODES, RetryHandler.DEFAULT_RETRYABLE_EXCEPTIONS, RetryHandler.DEFALT_RETRYABLE_MESSAGES, e -> false)); diff --git a/src/test/java/org/broadinstitute/http/nio/RetryHandlerUnitTest.java b/src/test/java/org/broadinstitute/http/nio/RetryHandlerUnitTest.java index 9f7dea5..e5aa3c0 100644 --- a/src/test/java/org/broadinstitute/http/nio/RetryHandlerUnitTest.java +++ b/src/test/java/org/broadinstitute/http/nio/RetryHandlerUnitTest.java @@ -37,7 +37,7 @@ public static Object[][] getExceptionalConditions() { {new SocketException(), true}, {new SocketTimeoutException(), true}, {new IOException(new SocketException()), true}, - {new IOException(new ClosedChannelException()), false}, + {new IOException(new ClosedChannelException()), true}, {new IOException(new IOException()), false}, }; }