Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 7 additions & 3 deletions src/main/java/org/broadinstitute/http/nio/RetryHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,8 +32,10 @@ public class RetryHandler {
/**
* the default set of exception messages which are retried when encountered
*/
public static final Set<String> 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<String> 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
Expand All @@ -42,7 +45,8 @@ public class RetryHandler {
EOFException.class,
SocketException.class,
SocketTimeoutException.class,
InterruptedIOException.class
InterruptedIOException.class,
ClosedChannelException.class
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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)));
Expand All @@ -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)))
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
}
Expand Down