25
25
import ch .qos .logback .classic .Logger ;
26
26
import ch .qos .logback .classic .spi .ILoggingEvent ;
27
27
import ch .qos .logback .core .read .ListAppender ;
28
+ import io .temporal .activity .ActivityOptions ;
29
+ import io .temporal .api .common .v1 .WorkflowExecution ;
30
+ import io .temporal .client .WorkflowClient ;
28
31
import io .temporal .client .WorkflowException ;
32
+ import io .temporal .common .RetryOptions ;
33
+ import io .temporal .failure .ActivityFailure ;
29
34
import io .temporal .failure .ApplicationFailure ;
30
35
import io .temporal .internal .Issue ;
31
36
import io .temporal .testing .internal .SDKTestWorkflowRule ;
37
+ import io .temporal .workflow .Workflow ;
38
+ import io .temporal .workflow .shared .TestActivities ;
32
39
import io .temporal .workflow .shared .TestWorkflows ;
40
+ import java .time .Duration ;
33
41
import java .util .concurrent .atomic .AtomicInteger ;
34
42
import org .junit .Before ;
35
43
import org .junit .Rule ;
@@ -49,7 +57,10 @@ public class DirectQueryReplaysDontSpamLogWithWorkflowExecutionExceptionsTest {
49
57
50
58
@ Rule
51
59
public SDKTestWorkflowRule testWorkflowRule =
52
- SDKTestWorkflowRule .newBuilder ().setWorkflowTypes (TestWorkflowNonRetryableFlag .class ).build ();
60
+ SDKTestWorkflowRule .newBuilder ()
61
+ .setWorkflowTypes (TestWorkflowNonRetryableFlag .class , LogAndKeepRunningWorkflow .class )
62
+ .setActivityImplementations (new TestActivities .TestActivitiesImpl ())
63
+ .build ();
53
64
54
65
@ Before
55
66
public void setUp () throws Exception {
@@ -79,6 +90,72 @@ public void queriedWorkflowFailureDoesntProduceAdditionalLogs() {
79
90
workflowExecuteRunnableLoggerAppender .list .size ());
80
91
}
81
92
93
+ @ Test
94
+ public void queriedWorkflowFailureDoesntProduceAdditionalLogsWhenWorkflowIsNotCompleted () {
95
+ TestWorkflows .QueryableWorkflow workflow =
96
+ testWorkflowRule .newWorkflowStub (TestWorkflows .QueryableWorkflow .class );
97
+
98
+ WorkflowExecution execution = WorkflowClient .start (workflow ::execute );
99
+
100
+ assertEquals ("my-state" , workflow .getState ());
101
+ assertEquals ("There was only one execution." , 1 , workflowCodeExecutionCount .get ());
102
+
103
+ testWorkflowRule .invalidateWorkflowCache ();
104
+ assertEquals ("my-state" , workflow .getState ());
105
+ assertEquals (
106
+ "There was two executions - one original and one full replay for query." ,
107
+ 2 ,
108
+ workflowCodeExecutionCount .get ());
109
+
110
+ workflow .mySignal ("exit" );
111
+ assertEquals ("my-state" , workflow .getState ());
112
+ assertEquals (
113
+ "There was three executions - one original and two full replays for query." ,
114
+ 3 ,
115
+ workflowCodeExecutionCount .get ());
116
+ assertEquals (
117
+ "Only the original exception should be logged." ,
118
+ 1 ,
119
+ workflowExecuteRunnableLoggerAppender .list .size ());
120
+ }
121
+
122
+ public static class LogAndKeepRunningWorkflow implements TestWorkflows .QueryableWorkflow {
123
+ private final org .slf4j .Logger logger =
124
+ Workflow .getLogger ("io.temporal.internal.sync.WorkflowExecutionHandler" );
125
+ private final TestActivities .VariousTestActivities activities =
126
+ Workflow .newActivityStub (
127
+ TestActivities .VariousTestActivities .class ,
128
+ ActivityOptions .newBuilder ()
129
+ .setStartToCloseTimeout (Duration .ofSeconds (10 ))
130
+ .setRetryOptions (RetryOptions .newBuilder ().setMaximumAttempts (1 ).build ())
131
+ .build ());
132
+ private boolean exit ;
133
+
134
+ @ Override
135
+ public String execute () {
136
+ workflowCodeExecutionCount .incrementAndGet ();
137
+ while (true ) {
138
+ try {
139
+ activities .throwIO ();
140
+ } catch (ActivityFailure e ) {
141
+ logger .error ("Unexpected error on activity" , e );
142
+ Workflow .await (() -> exit );
143
+ return "exit" ;
144
+ }
145
+ }
146
+ }
147
+
148
+ @ Override
149
+ public String getState () {
150
+ return "my-state" ;
151
+ }
152
+
153
+ @ Override
154
+ public void mySignal (String value ) {
155
+ exit = true ;
156
+ }
157
+ }
158
+
82
159
public static class TestWorkflowNonRetryableFlag implements TestWorkflows .TestWorkflowWithQuery {
83
160
84
161
@ Override
0 commit comments