Skip to content

Commit 6b39e44

Browse files
Align Update API across test server and real server (#2153)
Align test server update APIs with real server update APIs
1 parent eabd51f commit 6b39e44

File tree

7 files changed

+1059
-169
lines changed

7 files changed

+1059
-169
lines changed

temporal-sdk/src/main/java/io/temporal/internal/statemachines/WorkflowStateMachines.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ private void handleSingleEventLookahead(HistoryEvent event) {
387387
// other state machines because a rejected update produces no event in history.
388388
protocolStateMachines.entrySet().removeIf(entry -> entry.getValue().isFinalState());
389389
break;
390+
default:
391+
break;
390392
}
391393
}
392394

@@ -625,6 +627,9 @@ public List<Message> takeMessages() {
625627
List<Message> result = new ArrayList<>(messageOutbox.size());
626628
result.addAll(messageOutbox);
627629
messageOutbox.clear();
630+
// Remove any finished update protocol state machines. We can't remove them on an event like
631+
// other state machines because a rejected update produces no event in history.
632+
protocolStateMachines.entrySet().removeIf(entry -> entry.getValue().isFinalState());
628633
return result;
629634
}
630635

temporal-sdk/src/test/java/io/temporal/internal/testing/WorkflowTestingTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@
6060
import java.util.UUID;
6161
import java.util.concurrent.CompletableFuture;
6262
import java.util.concurrent.ExecutionException;
63-
import org.junit.After;
64-
import org.junit.Before;
65-
import org.junit.Ignore;
66-
import org.junit.Rule;
67-
import org.junit.Test;
63+
import org.junit.*;
6864
import org.junit.rules.TestWatcher;
6965
import org.junit.rules.Timeout;
7066
import org.junit.runner.Description;

temporal-test-server/src/main/java/io/temporal/internal/testservice/StateMachines.java

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -423,19 +423,19 @@ public String toString() {
423423
/** Represents an accepted update workflow execution request */
424424
static final class UpdateWorkflowExecutionData {
425425
final String id;
426-
final CompletableFuture<UpdateWorkflowExecutionResponse> acceptance;
427-
final CompletableFuture<UpdateWorkflowExecutionResponse> complete;
426+
final CompletableFuture<Boolean> accepted;
427+
final CompletableFuture<Outcome> outcome;
428428
final Request initialRequest;
429429

430430
public UpdateWorkflowExecutionData(
431431
String id,
432432
Request initialRequest,
433-
CompletableFuture<UpdateWorkflowExecutionResponse> acceptance,
434-
CompletableFuture<UpdateWorkflowExecutionResponse> complete) {
433+
CompletableFuture<Boolean> accepted,
434+
CompletableFuture<Outcome> outcome) {
435435
this.id = id;
436436
this.initialRequest = initialRequest;
437-
this.acceptance = acceptance;
438-
this.complete = complete;
437+
this.accepted = accepted;
438+
this.outcome = outcome;
439439
}
440440

441441
@Override
@@ -560,10 +560,10 @@ public static StateMachine<ChildWorkflowData> newChildWorkflowStateMachine(
560560
public static StateMachine<UpdateWorkflowExecutionData> newUpdateWorkflowExecution(
561561
String updateId,
562562
Request initialRequest,
563-
CompletableFuture<UpdateWorkflowExecutionResponse> acceptance,
564-
CompletableFuture<UpdateWorkflowExecutionResponse> complete) {
563+
CompletableFuture<Boolean> accepted,
564+
CompletableFuture<Outcome> outcome) {
565565
return new StateMachine<>(
566-
new UpdateWorkflowExecutionData(updateId, initialRequest, acceptance, complete))
566+
new UpdateWorkflowExecutionData(updateId, initialRequest, accepted, outcome))
567567
.add(NONE, START, STARTED, StateMachines::acceptUpdate)
568568
.add(STARTED, COMPLETE, COMPLETED, StateMachines::completeUpdate);
569569
}
@@ -1805,19 +1805,10 @@ private static void acceptUpdate(
18051805
if (!ctx.getWorkflowMutableState().isTerminalState()) {
18061806
ctx.addEvent(event);
18071807
}
1808-
1809-
UpdateWorkflowExecutionResponse response =
1810-
UpdateWorkflowExecutionResponse.newBuilder()
1811-
.setUpdateRef(
1812-
UpdateRef.newBuilder()
1813-
.setWorkflowExecution(ctx.getExecution())
1814-
.setUpdateId(data.id))
1815-
.setStage(
1816-
UpdateWorkflowExecutionLifecycleStage
1817-
.UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_ACCEPTED)
1818-
.build();
1819-
1820-
data.acceptance.complete(response);
1808+
ctx.onCommit(
1809+
(int historySize) -> {
1810+
data.accepted.complete(true);
1811+
});
18211812
} catch (InvalidProtocolBufferException e) {
18221813
throw new RuntimeException(e);
18231814
}
@@ -1849,20 +1840,10 @@ private static void completeUpdate(
18491840
if (!ctx.getWorkflowMutableState().isTerminalState()) {
18501841
ctx.addEvent(event);
18511842
}
1852-
1853-
UpdateWorkflowExecutionResponse updateResponse =
1854-
UpdateWorkflowExecutionResponse.newBuilder()
1855-
.setUpdateRef(
1856-
UpdateRef.newBuilder()
1857-
.setWorkflowExecution(ctx.getExecution())
1858-
.setUpdateId(data.id))
1859-
.setOutcome(response.getOutcome())
1860-
.setStage(
1861-
UpdateWorkflowExecutionLifecycleStage
1862-
.UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_COMPLETED)
1863-
.build();
1864-
1865-
data.complete.complete(updateResponse);
1843+
ctx.onCommit(
1844+
(int historySize) -> {
1845+
data.outcome.complete(response.getOutcome());
1846+
});
18661847
} catch (InvalidProtocolBufferException e) {
18671848
throw new RuntimeException(e);
18681849
}

0 commit comments

Comments
 (0)