2525import io .temporal .workflow .shared .TestWorkflows .TestWorkflowWithCronSchedule ;
2626import java .text .SimpleDateFormat ;
2727import java .util .Date ;
28+ import java .util .HashMap ;
2829import java .util .Map ;
2930import java .util .Optional ;
3031import java .util .concurrent .ConcurrentHashMap ;
3435public class TestWorkflowWithCronScheduleImpl implements TestWorkflowWithCronSchedule {
3536
3637 public static final Map <String , AtomicInteger > retryCount = new ConcurrentHashMap <>();
37- public static String lastCompletionResult ;
38+ public static final Map <String , Map <Integer , String >> lastCompletionResults =
39+ new ConcurrentHashMap <>();
3840 public static Optional <Exception > lastFail ;
3941
4042 @ Override
@@ -46,23 +48,19 @@ public String execute(String testName) {
4648 return null ;
4749 }
4850
49- lastCompletionResult = Workflow .getLastCompletionResult (String .class );
5051 lastFail = Workflow .getPreviousRunFailure ();
52+ int count = retryCount .computeIfAbsent (testName , k -> new AtomicInteger ()).incrementAndGet ();
53+ lastCompletionResults
54+ .computeIfAbsent (testName , k -> new HashMap <>())
55+ .put (count , Workflow .getLastCompletionResult (String .class ));
5156
52- AtomicInteger count = retryCount .get (testName );
53- if (count == null ) {
54- count = new AtomicInteger ();
55- retryCount .put (testName , count );
56- }
57- int c = count .incrementAndGet ();
58-
59- if (c == 3 ) {
57+ if (count == 3 ) {
6058 throw ApplicationFailure .newFailure ("simulated error" , "test" );
6159 }
6260
6361 SimpleDateFormat sdf = new SimpleDateFormat ("MMM dd,yyyy HH:mm:ss.SSS" );
6462 Date now = new Date (Workflow .currentTimeMillis ());
6563 log .debug ("TestWorkflowWithCronScheduleImpl run at " + sdf .format (now ));
66- return "run " + c ;
64+ return "run " + count ;
6765 }
6866}
0 commit comments