Skip to content

Commit

Permalink
feat: clean up fault-tolerant executor exception handling
Browse files Browse the repository at this point in the history
This removes the extra throw of ConnectException on an unknown
exception. By allowing Exception to be thrown in the interface,
we can allow any non-R4J exception to be handled up the stack.
  • Loading branch information
mattnichols authored and meotchwilliams committed Mar 21, 2024
1 parent d72d5f7 commit d1188da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
import lombok.AccessLevel;
import lombok.Setter;

import com.mx.path.core.common.accessor.PathResponseStatus;
import com.mx.path.core.common.configuration.Configuration;
import com.mx.path.core.common.connect.ConnectException;
import com.mx.path.core.common.connect.ServiceUnavailableException;
import com.mx.path.core.common.connect.TooManyRequestsException;
import com.mx.path.core.common.exception.PathRequestException;
import com.mx.path.core.common.exception.PathSystemException;
import com.mx.path.core.common.process.FaultTolerantExecutor;
import com.mx.path.core.common.process.FaultTolerantTask;
import com.mx.path.service.facility.fault_tolerant_executor.resilience4j.configuration.Configurations;
Expand All @@ -36,7 +32,7 @@ public Resilience4jFaultTolerantExecutor(@Configuration Configurations configura

@SuppressWarnings("PMD.CyclomaticComplexity")
@Override
public void submit(String scope, FaultTolerantTask task) {
public void submit(String scope, FaultTolerantTask task) throws Exception {
try {
executeDecoratorStack(scope, task);
} catch (BulkheadFullException e) {
Expand All @@ -51,13 +47,6 @@ public void submit(String scope, FaultTolerantTask task) {
throw new com.mx.path.core.common.connect.TimeoutException(
"Resilience4j triggered a timeout.",
e);
} catch (PathRequestException | PathSystemException e) {
throw e; // rethrow Path exceptions
} catch (Exception e) {
throw new ConnectException(
"An unknown error occurred",
PathResponseStatus.INTERNAL_ERROR,
e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import java.time.Duration
import java.util.concurrent.TimeoutException

import com.mx.path.core.common.accessor.PathResponseStatus
import com.mx.path.core.common.accessor.UpstreamSystemMaintenance
import com.mx.path.core.common.connect.ConnectException
import com.mx.path.core.common.connect.ServiceUnavailableException
import com.mx.path.core.common.connect.TooManyRequestsException
Expand Down Expand Up @@ -39,16 +40,19 @@ class Resilience4jFaultTolerantExecutorTest extends Specification {
subject.submit("DEFAULT", { config -> })

then:
def exception = thrown(ConnectException)
exception.status == failureStatus
exception.cause == originalException
def exception = thrown(expectedType)
failureStatus == null ? !exception.hasProperty("status") : exception.status == failureStatus
!wrapsOriginalException || exception.cause == originalException
wrapsOriginalException || exception.cause == null

where:
originalException || failureStatus
mock(BulkheadFullException) || PathResponseStatus.UPSTREAM_SERVICE_UNAVAILABLE
mock(CallNotPermittedException) || PathResponseStatus.UPSTREAM_SERVICE_UNAVAILABLE
new TimeoutException() || PathResponseStatus.UPSTREAM_SERVICE_UNAVAILABLE
new RuntimeException() || PathResponseStatus.INTERNAL_ERROR
originalException || wrapsOriginalException || expectedType || failureStatus
mock(BulkheadFullException) || true || TooManyRequestsException || PathResponseStatus.UPSTREAM_SERVICE_UNAVAILABLE
mock(CallNotPermittedException) || true || ServiceUnavailableException || PathResponseStatus.UPSTREAM_SERVICE_UNAVAILABLE
new TimeoutException() || true || com.mx.path.core.common.connect.TimeoutException || PathResponseStatus.UPSTREAM_SERVICE_UNAVAILABLE
new UpstreamSystemMaintenance("upstream is being maintained") || false || UpstreamSystemMaintenance || PathResponseStatus.UPSTREAM_SERVICE_UNAVAILABLE
new RuntimeException() || false || RuntimeException || null
new NullPointerException() || false || NullPointerException || null
}

def "runs a submitted task"() {
Expand Down

0 comments on commit d1188da

Please sign in to comment.