@@ -378,6 +378,56 @@ public void testActivityRetry() {
378
378
assertEquals (activitiesImpl .toString (), 3 , activitiesImpl .invocations .size ());
379
379
}
380
380
381
+ public static class TestActivityRetryOptionsChange implements TestWorkflow1 {
382
+
383
+ @ Override
384
+ public String execute (String taskList ) {
385
+ ActivityOptions .Builder options =
386
+ new ActivityOptions .Builder ()
387
+ .setTaskList (taskList )
388
+ .setHeartbeatTimeout (Duration .ofSeconds (5 ))
389
+ .setScheduleToCloseTimeout (Duration .ofSeconds (5 ))
390
+ .setScheduleToStartTimeout (Duration .ofSeconds (5 ))
391
+ .setStartToCloseTimeout (Duration .ofSeconds (10 ));
392
+ RetryOptions retryOptions ;
393
+ if (Workflow .isReplaying ()) {
394
+ retryOptions =
395
+ new RetryOptions .Builder ()
396
+ .setMinimumAttempts (1 )
397
+ .setMaximumInterval (Duration .ofSeconds (1 ))
398
+ .setInitialInterval (Duration .ofSeconds (1 ))
399
+ .setMaximumAttempts (3 )
400
+ .build ();
401
+ } else {
402
+ retryOptions =
403
+ new RetryOptions .Builder ()
404
+ .setMinimumAttempts (2 )
405
+ .setMaximumInterval (Duration .ofSeconds (1 ))
406
+ .setInitialInterval (Duration .ofSeconds (1 ))
407
+ .setMaximumAttempts (2 )
408
+ .build ();
409
+ }
410
+ TestActivities activities = Workflow .newActivityStub (TestActivities .class , options .build ());
411
+ Workflow .retry (retryOptions , () -> activities .throwIO ());
412
+ return "ignored" ;
413
+ }
414
+ }
415
+
416
+ @ Test
417
+ public void testActivityRetryOptionsChange () {
418
+ startWorkerFor (TestActivityRetryOptionsChange .class );
419
+ TestWorkflow1 workflowStub =
420
+ workflowClient .newWorkflowStub (
421
+ TestWorkflow1 .class , newWorkflowOptionsBuilder (taskList ).build ());
422
+ try {
423
+ workflowStub .execute (taskList );
424
+ fail ("unreachable" );
425
+ } catch (WorkflowException e ) {
426
+ assertTrue (e .getCause ().getCause () instanceof IOException );
427
+ }
428
+ assertEquals (activitiesImpl .toString (), 2 , activitiesImpl .invocations .size ());
429
+ }
430
+
381
431
public static class TestUntypedActivityRetry implements TestWorkflow1 {
382
432
383
433
@ Override
@@ -490,6 +540,57 @@ public void testAsyncActivityRetry() {
490
540
assertEquals (activitiesImpl .toString (), 3 , activitiesImpl .invocations .size ());
491
541
}
492
542
543
+ public static class TestAsyncActivityRetryOptionsChange implements TestWorkflow1 {
544
+
545
+ private TestActivities activities ;
546
+
547
+ @ Override
548
+ public String execute (String taskList ) {
549
+ ActivityOptions .Builder options =
550
+ new ActivityOptions .Builder ()
551
+ .setTaskList (taskList )
552
+ .setHeartbeatTimeout (Duration .ofSeconds (5 ))
553
+ .setScheduleToCloseTimeout (Duration .ofSeconds (5 ))
554
+ .setScheduleToStartTimeout (Duration .ofSeconds (5 ))
555
+ .setStartToCloseTimeout (Duration .ofSeconds (10 ));
556
+ if (Workflow .isReplaying ()) {
557
+ options .setRetryOptions (
558
+ new RetryOptions .Builder ()
559
+ .setMinimumAttempts (1 )
560
+ .setMaximumInterval (Duration .ofSeconds (1 ))
561
+ .setInitialInterval (Duration .ofSeconds (1 ))
562
+ .setMaximumAttempts (3 )
563
+ .build ());
564
+ } else {
565
+ options .setRetryOptions (
566
+ new RetryOptions .Builder ()
567
+ .setMinimumAttempts (2 )
568
+ .setMaximumInterval (Duration .ofSeconds (1 ))
569
+ .setInitialInterval (Duration .ofSeconds (1 ))
570
+ .setMaximumAttempts (2 )
571
+ .build ());
572
+ }
573
+ this .activities = Workflow .newActivityStub (TestActivities .class , options .build ());
574
+ Async .procedure (activities ::throwIO ).get ();
575
+ return "ignored" ;
576
+ }
577
+ }
578
+
579
+ @ Test
580
+ public void testAsyncActivityRetryOptionsChange () {
581
+ startWorkerFor (TestAsyncActivityRetryOptionsChange .class );
582
+ TestWorkflow1 workflowStub =
583
+ workflowClient .newWorkflowStub (
584
+ TestWorkflow1 .class , newWorkflowOptionsBuilder (taskList ).build ());
585
+ try {
586
+ workflowStub .execute (taskList );
587
+ fail ("unreachable" );
588
+ } catch (WorkflowException e ) {
589
+ assertTrue (e .getCause ().getCause () instanceof IOException );
590
+ }
591
+ assertEquals (activitiesImpl .toString (), 2 , activitiesImpl .invocations .size ());
592
+ }
593
+
493
594
public static class TestHeartbeatTimeoutDetails implements TestWorkflow1 {
494
595
495
596
@ Override
@@ -1470,6 +1571,75 @@ public void testAsyncRetry() {
1470
1571
assertTrue (trace .get (2 ).startsWith ("retry at " ));
1471
1572
}
1472
1573
1574
+ public static class TestAsyncRetryOptionsChangeWorkflow implements TestWorkflow2 {
1575
+
1576
+ private final List <String > trace = new ArrayList <>();
1577
+
1578
+ @ Override
1579
+ public String execute (boolean useExternalService ) {
1580
+ RetryOptions retryOptions ;
1581
+ if (Workflow .isReplaying ()) {
1582
+ retryOptions =
1583
+ new RetryOptions .Builder ()
1584
+ .setMinimumAttempts (1 )
1585
+ .setMaximumInterval (Duration .ofSeconds (1 ))
1586
+ .setInitialInterval (Duration .ofSeconds (1 ))
1587
+ .setMaximumAttempts (3 )
1588
+ .build ();
1589
+ } else {
1590
+ retryOptions =
1591
+ new RetryOptions .Builder ()
1592
+ .setMinimumAttempts (2 )
1593
+ .setMaximumInterval (Duration .ofSeconds (1 ))
1594
+ .setInitialInterval (Duration .ofSeconds (1 ))
1595
+ .setMaximumAttempts (2 )
1596
+ .build ();
1597
+ }
1598
+
1599
+ trace .clear (); // clear because of replay
1600
+ trace .add ("started" );
1601
+ Async .retry (
1602
+ retryOptions ,
1603
+ () -> {
1604
+ trace .add ("retry at " + Workflow .currentTimeMillis ());
1605
+ return Workflow .newFailedPromise (new IllegalThreadStateException ("simulated" ));
1606
+ })
1607
+ .get ();
1608
+ trace .add ("beforeSleep" );
1609
+ Workflow .sleep (60000 );
1610
+ trace .add ("done" );
1611
+ return "" ;
1612
+ }
1613
+
1614
+ @ Override
1615
+ public List <String > getTrace () {
1616
+ return trace ;
1617
+ }
1618
+ }
1619
+
1620
+ /** @see DeterministicRunnerTest#testRetry() */
1621
+ @ Test
1622
+ public void testAsyncRetryOptionsChange () {
1623
+ startWorkerFor (TestAsyncRetryOptionsChangeWorkflow .class );
1624
+ TestWorkflow2 client =
1625
+ workflowClient .newWorkflowStub (
1626
+ TestWorkflow2 .class , newWorkflowOptionsBuilder (taskList ).build ());
1627
+ String result = null ;
1628
+ try {
1629
+ result = client .execute (useExternalService );
1630
+ fail ("unreachable" );
1631
+ } catch (WorkflowException e ) {
1632
+ assertTrue (e .getCause () instanceof IllegalThreadStateException );
1633
+ assertEquals ("simulated" , e .getCause ().getMessage ());
1634
+ }
1635
+ assertNull (result );
1636
+ List <String > trace = client .getTrace ();
1637
+ assertEquals (trace .toString (), 3 , trace .size ());
1638
+ assertEquals ("started" , trace .get (0 ));
1639
+ assertTrue (trace .get (1 ).startsWith ("retry at " ));
1640
+ assertTrue (trace .get (2 ).startsWith ("retry at " ));
1641
+ }
1642
+
1473
1643
public interface TestExceptionPropagation {
1474
1644
1475
1645
@ WorkflowMethod
0 commit comments