From acfadbfd4dbb764cec184f680951df435dede842 Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Wed, 16 Oct 2024 10:17:17 -0700 Subject: [PATCH] Avoid spamming retries in nexusOperationApplicationFailureFailureConversion (#2272) Avoid spamming retries in nexusOperationApplicationFailureFailureConversion --- .../nexus/OperationFailureConversionTest.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/nexus/OperationFailureConversionTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/nexus/OperationFailureConversionTest.java index 763ae43c9..9a1717a49 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/nexus/OperationFailureConversionTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/nexus/OperationFailureConversionTest.java @@ -28,12 +28,13 @@ import io.temporal.client.WorkflowFailedException; import io.temporal.failure.ApplicationFailure; import io.temporal.failure.NexusOperationFailure; -import io.temporal.failure.TimeoutFailure; import io.temporal.testing.internal.SDKTestWorkflowRule; import io.temporal.workflow.*; import io.temporal.workflow.shared.TestNexusServices; import io.temporal.workflow.shared.TestWorkflows.TestWorkflow1; import java.time.Duration; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; @@ -82,7 +83,10 @@ public void nexusOperationApplicationFailureFailureConversion() { WorkflowFailedException.class, () -> workflowStub.execute("ApplicationFailure")); Assert.assertTrue(exception.getCause() instanceof NexusOperationFailure); NexusOperationFailure nexusFailure = (NexusOperationFailure) exception.getCause(); - Assert.assertTrue(nexusFailure.getCause() instanceof TimeoutFailure); + Assert.assertTrue(nexusFailure.getCause() instanceof ApplicationFailure); + ApplicationFailure applicationFailure = (ApplicationFailure) nexusFailure.getCause(); + Assert.assertTrue( + applicationFailure.getOriginalMessage().contains("exceeded invocation count")); } public static class TestNexus implements TestWorkflow1 { @@ -104,11 +108,21 @@ public String execute(String testcase) { @ServiceImpl(service = TestNexusServices.TestNexusService1.class) public class TestNexusServiceImpl { + Map invocationCount = new ConcurrentHashMap<>(); + @OperationImpl public OperationHandler operation() { return OperationHandler.sync( (ctx, details, name) -> { + invocationCount.put( + details.getRequestId(), + invocationCount.getOrDefault(details.getRequestId(), 0) + 1); if (name.equals("ApplicationFailure")) { + // Limit the number of retries to 2 to avoid overwhelming the test server + if (invocationCount.get(details.getRequestId()) >= 2) { + throw ApplicationFailure.newNonRetryableFailure( + "exceeded invocation count", "ExceededInvocationCount"); + } throw ApplicationFailure.newFailure("failed to call operation", "TestFailure"); } else if (name.equals("ApplicationFailureNonRetryable")) { throw ApplicationFailure.newNonRetryableFailure(