Skip to content

Commit 7bcade2

Browse files
authored
Fix UpdateWithStart workflow args (#2286)
1 parent 0ce1d6e commit 7bcade2

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

temporal-sdk/src/main/java/io/temporal/client/UpdateWithStartWorkflowOperation.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,12 @@ public static <R> Builder<R> newBuilder(String updateName, Class<R> resultClass,
276276

277277
private UpdateOptions<R> options;
278278

279+
// set by constructor (untyped) or `prepareUpdate` (typed)
279280
private Object[] updateArgs;
280281

282+
// set by `prepareStart`
283+
private Object[] workflowArgs;
284+
281285
private final CompletableFuture<WorkflowUpdateHandle<R>> handle;
282286

283287
private final Functions.Proc request;
@@ -294,9 +298,13 @@ WorkflowUpdateHandle<R> invoke(Functions.Proc workflow) {
294298
WorkflowInvocationHandler.initAsyncInvocation(
295299
WorkflowInvocationHandler.InvocationType.UPDATE_WITH_START, this);
296300
try {
301+
// invokes `prepareUpdate` via WorkflowInvocationHandler.UpdateWithStartInvocationHandler
297302
request.apply();
303+
304+
// invokes `prepareStart` via WorkflowInvocationHandler.UpdateWithStartInvocationHandler
298305
workflow.apply();
299-
stub.updateWithStart(this, this.updateArgs);
306+
307+
stub.updateWithStart(this, this.workflowArgs);
300308
return this.handle.get();
301309
} catch (InterruptedException e) {
302310
Thread.currentThread().interrupt();
@@ -311,6 +319,7 @@ WorkflowUpdateHandle<R> invoke(Functions.Proc workflow) {
311319
}
312320
}
313321

322+
/** Invoked by {@link WorkflowInvocationHandler.UpdateWithStartInvocationHandler}. */
314323
void prepareUpdate(
315324
WorkflowStub stub, String updateName, Class resultClass, Type resultType, Object[] args) {
316325
setStub(stub);
@@ -323,8 +332,10 @@ void prepareUpdate(
323332
.build();
324333
}
325334

326-
void prepareStart(WorkflowStub stub) {
335+
/** Invoked by {@link WorkflowInvocationHandler.UpdateWithStartInvocationHandler}. */
336+
void prepareStart(WorkflowStub stub, Object[] args) {
327337
setStub(stub);
338+
this.workflowArgs = args;
328339
}
329340

330341
/** Returns the result of the update request. */

temporal-sdk/src/main/java/io/temporal/client/WorkflowInvocationHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ public void invoke(
490490
throw new IllegalArgumentException(
491491
"Method '" + method.getName() + "' is not a WorkflowMethod");
492492
}
493-
this.operation.prepareStart(untyped);
493+
this.operation.prepareStart(untyped, args);
494494
state = State.UPDATE_RECEIVED;
495495
} else {
496496
throw new IllegalArgumentException(

temporal-sdk/src/test/java/io/temporal/workflow/updateTest/UpdateWithStartTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,19 @@ public void startVariousFuncs() throws ExecutionException, InterruptedException
218218
WorkflowClient.updateWithStart(stubF6::func6, "1", 2, 3, 4, 5, 6, updateOp6);
219219

220220
assertEquals("0", handle0.getResultAsync().get());
221+
assertEquals("func", WorkflowStub.fromTyped(stubF).getResult(String.class));
221222
assertEquals("1", handle1.getResultAsync().get());
223+
assertEquals("1", WorkflowStub.fromTyped(stubF1).getResult(String.class));
222224
assertEquals("2", handle2.getResultAsync().get());
225+
assertEquals("12", WorkflowStub.fromTyped(stubF2).getResult(String.class));
223226
assertEquals("3", handle3.getResultAsync().get());
227+
assertEquals("123", WorkflowStub.fromTyped(stubF3).getResult(String.class));
224228
assertEquals("4", handle4.getResultAsync().get());
229+
assertEquals("1234", WorkflowStub.fromTyped(stubF4).getResult(String.class));
225230
assertEquals("5", handle5.getResultAsync().get());
231+
assertEquals("12345", WorkflowStub.fromTyped(stubF5).getResult(String.class));
226232
assertEquals("6", handle6.getResultAsync().get());
233+
assertEquals("123456", WorkflowStub.fromTyped(stubF6).getResult(String.class));
227234
}
228235

229236
@Test

0 commit comments

Comments
 (0)