28
28
import io .temporal .client .WorkflowFailedException ;
29
29
import io .temporal .failure .ApplicationFailure ;
30
30
import io .temporal .failure .NexusOperationFailure ;
31
- import io .temporal .failure .TimeoutFailure ;
32
31
import io .temporal .testing .internal .SDKTestWorkflowRule ;
33
32
import io .temporal .workflow .*;
34
33
import io .temporal .workflow .shared .TestNexusServices ;
35
34
import io .temporal .workflow .shared .TestWorkflows .TestWorkflow1 ;
36
35
import java .time .Duration ;
36
+ import java .util .Map ;
37
+ import java .util .concurrent .ConcurrentHashMap ;
37
38
import org .junit .Assert ;
38
39
import org .junit .Rule ;
39
40
import org .junit .Test ;
@@ -82,7 +83,10 @@ public void nexusOperationApplicationFailureFailureConversion() {
82
83
WorkflowFailedException .class , () -> workflowStub .execute ("ApplicationFailure" ));
83
84
Assert .assertTrue (exception .getCause () instanceof NexusOperationFailure );
84
85
NexusOperationFailure nexusFailure = (NexusOperationFailure ) exception .getCause ();
85
- Assert .assertTrue (nexusFailure .getCause () instanceof TimeoutFailure );
86
+ Assert .assertTrue (nexusFailure .getCause () instanceof ApplicationFailure );
87
+ ApplicationFailure applicationFailure = (ApplicationFailure ) nexusFailure .getCause ();
88
+ Assert .assertTrue (
89
+ applicationFailure .getOriginalMessage ().contains ("exceeded invocation count" ));
86
90
}
87
91
88
92
public static class TestNexus implements TestWorkflow1 {
@@ -104,11 +108,21 @@ public String execute(String testcase) {
104
108
105
109
@ ServiceImpl (service = TestNexusServices .TestNexusService1 .class )
106
110
public class TestNexusServiceImpl {
111
+ Map <String , Integer > invocationCount = new ConcurrentHashMap <>();
112
+
107
113
@ OperationImpl
108
114
public OperationHandler <String , String > operation () {
109
115
return OperationHandler .sync (
110
116
(ctx , details , name ) -> {
117
+ invocationCount .put (
118
+ details .getRequestId (),
119
+ invocationCount .getOrDefault (details .getRequestId (), 0 ) + 1 );
111
120
if (name .equals ("ApplicationFailure" )) {
121
+ // Limit the number of retries to 2 to avoid overwhelming the test server
122
+ if (invocationCount .get (details .getRequestId ()) >= 2 ) {
123
+ throw ApplicationFailure .newNonRetryableFailure (
124
+ "exceeded invocation count" , "ExceededInvocationCount" );
125
+ }
112
126
throw ApplicationFailure .newFailure ("failed to call operation" , "TestFailure" );
113
127
} else if (name .equals ("ApplicationFailureNonRetryable" )) {
114
128
throw ApplicationFailure .newNonRetryableFailure (
0 commit comments