36
36
import java .util .ArrayList ;
37
37
import java .util .List ;
38
38
import java .util .UUID ;
39
+ import java .util .concurrent .CompletableFuture ;
40
+ import java .util .concurrent .ExecutionException ;
39
41
import org .junit .After ;
40
42
import org .junit .Before ;
41
43
import org .junit .Test ;
@@ -71,13 +73,21 @@ public void tearDown() throws Exception {
71
73
72
74
@ WorkflowInterface
73
75
public interface TestWorkflow {
76
+ @ UpdateMethod
77
+ void update (String id );
78
+
74
79
@ WorkflowMethod
75
80
void execute (String id );
76
81
}
77
82
78
83
public static class TestLoggingInWorkflow implements LoggerTest .TestWorkflow {
79
84
private final Logger workflowLogger = Workflow .getLogger (TestLoggingInWorkflow .class );
80
85
86
+ @ Override
87
+ public void update (String id ) {
88
+ workflowLogger .info ("Updating workflow {}." , id );
89
+ }
90
+
81
91
@ Override
82
92
public void execute (String id ) {
83
93
workflowLogger .info ("Start executing workflow {}." , id );
@@ -107,7 +117,7 @@ public void executeChild(String id) {
107
117
}
108
118
109
119
@ Test
110
- public void testWorkflowLogger () {
120
+ public void testWorkflowLogger () throws ExecutionException , InterruptedException {
111
121
Worker worker = env .newWorker (taskQueue );
112
122
worker .registerWorkflowImplementationTypes (
113
123
TestLoggingInWorkflow .class , TestLoggerInChildWorkflow .class );
@@ -122,14 +132,18 @@ public void testWorkflowLogger() {
122
132
LoggerTest .TestWorkflow workflow =
123
133
workflowClient .newWorkflowStub (LoggerTest .TestWorkflow .class , options );
124
134
String wfId = UUID .randomUUID ().toString ();
125
- workflow .execute (wfId );
126
-
127
- assertEquals (1 , matchingLines (String .format ("Start executing workflow %s." , wfId )));
128
- assertEquals (1 , matchingLines (String .format ("Executing child workflow %s." , wfId )));
129
- assertEquals (1 , matchingLines (String .format ("Done executing workflow %s." , wfId )));
135
+ CompletableFuture <Void > result = WorkflowClient .execute (workflow ::execute , wfId );
136
+ workflow .update (wfId );
137
+ result .get ();
138
+
139
+ assertEquals (1 , matchingLines (String .format ("Start executing workflow %s." , wfId ), false ));
140
+ assertEquals (1 , matchingLines (String .format ("Executing child workflow %s." , wfId ), false ));
141
+ assertEquals (1 , matchingLines (String .format ("Done executing workflow %s." , wfId ), false ));
142
+ // Assert the update log is present
143
+ assertEquals (1 , matchingLines (String .format ("Updating workflow %s." , wfId ), true ));
130
144
}
131
145
132
- private int matchingLines (String message ) {
146
+ private int matchingLines (String message , boolean isUpdateMethod ) {
133
147
int i = 0 ;
134
148
// Make copy to avoid ConcurrentModificationException
135
149
List <ILoggingEvent > list = new ArrayList <>(listAppender .list );
@@ -139,6 +153,10 @@ private int matchingLines(String message) {
139
153
assertTrue (event .getMDCPropertyMap ().containsKey (LoggerTag .WORKFLOW_TYPE ));
140
154
assertTrue (event .getMDCPropertyMap ().containsKey (LoggerTag .RUN_ID ));
141
155
assertTrue (event .getMDCPropertyMap ().containsKey (LoggerTag .TASK_QUEUE ));
156
+ if (isUpdateMethod ) {
157
+ assertTrue (event .getMDCPropertyMap ().containsKey (LoggerTag .UPDATE_ID ));
158
+ assertTrue (event .getMDCPropertyMap ().containsKey (LoggerTag .UPDATE_NAME ));
159
+ }
142
160
i ++;
143
161
}
144
162
}
0 commit comments