1616import org .junit .Test ;
1717
1818public class ContinueAsNewTest {
19+ static final SearchAttributeKey <String > CUSTOM_KEYWORD_SA =
20+ SearchAttributeKey .forKeyword ("CustomKeywordField" );
1921
2022 public static final int INITIAL_COUNT = 4 ;
2123
2224 @ Rule
2325 public SDKTestWorkflowRule testWorkflowRule =
24- SDKTestWorkflowRule .newBuilder ().setWorkflowTypes (TestContinueAsNewImpl .class ).build ();
26+ SDKTestWorkflowRule .newBuilder ()
27+ .setWorkflowTypes (TestContinueAsNewImpl .class )
28+ .setUseExternalService (true )
29+ .build ();
2530
2631 @ Test
2732 public void testContinueAsNew () {
@@ -30,6 +35,8 @@ public void testContinueAsNew() {
3035 options =
3136 WorkflowOptions .newBuilder (options )
3237 .setRetryOptions (RetryOptions .newBuilder ().setMaximumAttempts (10 ).build ())
38+ .setTypedSearchAttributes (
39+ SearchAttributes .newBuilder ().set (CUSTOM_KEYWORD_SA , "foo0" ).build ())
3340 .build ();
3441 TestContinueAsNew client =
3542 testWorkflowRule .getWorkflowClient ().newWorkflowStub (TestContinueAsNew .class , options );
@@ -68,8 +75,10 @@ public int execute(int count, String continueAsNewTaskQueue) {
6875 String taskQueue = Workflow .getInfo ().getTaskQueue ();
6976 if (count >= INITIAL_COUNT - 2 ) {
7077 assertEquals (10 , Workflow .getInfo ().getRetryOptions ().getMaximumAttempts ());
78+ assertEquals ("foo0" , Workflow .getTypedSearchAttributes ().get (CUSTOM_KEYWORD_SA ));
7179 } else {
7280 assertEquals (5 , Workflow .getInfo ().getRetryOptions ().getMaximumAttempts ());
81+ assertEquals ("foo1" , Workflow .getTypedSearchAttributes ().get (CUSTOM_KEYWORD_SA ));
7382 }
7483 if (count == 0 ) {
7584 assertEquals (continueAsNewTaskQueue , taskQueue );
@@ -78,22 +87,22 @@ public int execute(int count, String continueAsNewTaskQueue) {
7887 Map <String , Object > memo = new HashMap <>();
7988 memo .put ("myKey" , "MyValue" );
8089 RetryOptions retryOptions = null ;
90+ SearchAttributes searchAttributes = null ;
8191 // don't specify ContinueAsNewOptions on the first continue-as-new to test that RetryOptions
92+ // and SearchAttributes
8293 // are copied from the previous run.
8394 if (count == INITIAL_COUNT ) {
8495 TestContinueAsNew next = Workflow .newContinueAsNewStub (TestContinueAsNew .class );
8596 next .execute (count - 1 , continueAsNewTaskQueue );
8697 throw new RuntimeException ("unreachable" );
8798 }
88- // don't specify RetryOptions on the second continue-as-new to test that they are copied from
99+ // don't specify RetryOptions and SearchAttributes on the second continue-as-new to test that
100+ // they are copied from
89101 // the previous run.
90102 if (count < INITIAL_COUNT - 1 ) {
91103 retryOptions = RetryOptions .newBuilder ().setMaximumAttempts (5 ).build ();
104+ searchAttributes = SearchAttributes .newBuilder ().set (CUSTOM_KEYWORD_SA , "foo1" ).build ();
92105 }
93- SearchAttributes searchAttributes =
94- SearchAttributes .newBuilder ()
95- .set (SearchAttributeKey .forKeyword ("CustomKeywordField" ), "foo1" )
96- .build ();
97106 ContinueAsNewOptions options =
98107 ContinueAsNewOptions .newBuilder ()
99108 .setTaskQueue (continueAsNewTaskQueue )
0 commit comments