29
29
import io .temporal .activity .*;
30
30
import io .temporal .api .common .v1 .Payload ;
31
31
import io .temporal .api .common .v1 .WorkflowExecution ;
32
+ import io .temporal .api .enums .v1 .EventType ;
32
33
import io .temporal .client .*;
33
- import io .temporal .client .schedules .*;
34
34
import io .temporal .common .converter .*;
35
35
import io .temporal .failure .CanceledFailure ;
36
36
import io .temporal .payload .codec .PayloadCodec ;
46
46
import java .io .IOException ;
47
47
import java .time .Duration ;
48
48
import java .util .*;
49
+ import java .util .concurrent .atomic .AtomicInteger ;
49
50
import java .util .stream .Collectors ;
50
51
import javax .annotation .Nonnull ;
51
52
import javax .annotation .Nullable ;
@@ -71,15 +72,17 @@ public class WorkflowIdSignedPayloadsTest {
71
72
private static final DataConverter codecDataConverter =
72
73
new CodecDataConverter (
73
74
DefaultDataConverter .STANDARD_INSTANCE ,
74
- Collections .singletonList (new PayloadEncoderWithWorkflowIdSignature ()));
75
+ Collections .singletonList (new PayloadEncoderWithWorkflowIdSignature ()),
76
+ true );
75
77
76
78
@ Rule
77
79
public SDKTestWorkflowRule testWorkflowRule =
78
80
SDKTestWorkflowRule .newBuilder ()
79
81
.setWorkflowTypes (
80
82
SimpleWorkflowWithAnActivity .class ,
81
83
TestWorkflowWithCronScheduleImpl .class ,
82
- DynamicWorkflowImpl .class )
84
+ DynamicWorkflowImpl .class ,
85
+ WorkflowWithQuery .class )
83
86
.setWorkflowClientOptions (
84
87
WorkflowClientOptions .newBuilder ().setDataConverter (codecDataConverter ).build ())
85
88
.setActivityImplementations (
@@ -173,6 +176,26 @@ public void testDynamicWorkflow() {
173
176
assertEquals ("Hello World" , workflow .getResult (String .class ));
174
177
}
175
178
179
+ @ Test
180
+ public void testWorkflowWithTaskFailure () {
181
+ WorkflowOptions options =
182
+ SDKTestOptions .newWorkflowOptionsWithTimeouts (testWorkflowRule .getTaskQueue ());
183
+ TestWorkflows .TestWorkflowReturnString workflow =
184
+ testWorkflowRule
185
+ .getWorkflowClient ()
186
+ .newWorkflowStub (TestWorkflows .TestWorkflowReturnString .class , options );
187
+ assertEquals ("Hello World" , workflow .execute ());
188
+ // Test that the task failure is recorded in the history
189
+ // if the serialization fails the workflow task will timeout.
190
+ assertEquals (
191
+ 1 ,
192
+ testWorkflowRule
193
+ .getHistoryEvents (
194
+ WorkflowStub .fromTyped (workflow ).getExecution ().getWorkflowId (),
195
+ EventType .EVENT_TYPE_WORKFLOW_TASK_FAILED )
196
+ .size ());
197
+ }
198
+
176
199
@ ActivityInterface
177
200
public interface SimpleActivity {
178
201
@ ActivityMethod (name = "simple" )
@@ -213,6 +236,18 @@ public String execute(String input) {
213
236
}
214
237
}
215
238
239
+ public static class WorkflowWithQuery implements TestWorkflows .TestWorkflowReturnString {
240
+ static AtomicInteger taskRetryCount = new AtomicInteger ();
241
+
242
+ @ Override
243
+ public String execute () {
244
+ if (taskRetryCount .incrementAndGet () == 1 ) {
245
+ throw new RuntimeException ("test" );
246
+ }
247
+ return "Hello World" ;
248
+ }
249
+ }
250
+
216
251
public static class SimpleWorkflowWithAnActivity implements TestWorkflows .TestWorkflow1 {
217
252
218
253
private final SimpleActivity activity =
0 commit comments