Include HTTP/2 stream idle timeouts in IOExceptionMapper

This commit is contained in:
Chris Eager authored and Chris Eager committed 2024-03-06 11:11:39 -06:00
1 parent 3cc740cda3
commit 9f6a6d7f5b
2 files changed
+54 -2

No files matched your search

@@ -0,0 +1,41 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.textsecuregcm.mappers;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import java.util.stream.Stream;
import javax.ws.rs.core.Response;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
class IOExceptionMapperTest {
@ParameterizedTest
@MethodSource
void testExceptionParsing(final IOException exception, final int expectedStatus) {
try (Response response = new IOExceptionMapper().toResponse(exception)) {
assertEquals(expectedStatus, response.getStatus());
}
}
static Stream<Arguments> testExceptionParsing() {
return Stream.of(
Arguments.of(new IOException(), 503),
Arguments.of(new IOException(new TimeoutException("A timeout")), 503),
Arguments.of(new IOException(new TimeoutException()), 503),
Arguments.of(new IOException(new TimeoutException("Idle timeout 30000 ms elapsed")), 408),
Arguments.of(new IOException(new TimeoutException("Idle timeout expired")), 408),
Arguments.of(new IOException(new RuntimeException(new TimeoutException("Idle timeout expired"))), 503),
Arguments.of(new IOException(new TimeoutException("Idle timeout of another kind expired")), 503)
);
}
}