Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,19 @@ public WorkflowExecutionHistory(History history, String workflowId) {
* @return WorkflowExecutionHistory
*/
public static WorkflowExecutionHistory fromJson(String serialized) {
return fromJson(serialized, DEFAULT_WORKFLOW_ID);
String protoJson = HistoryJsonUtils.historyFormatJsonToProtoJson(serialized);

JsonFormat.Parser parser = JsonFormat.parser().ignoringUnknownFields();
History.Builder historyBuilder = History.newBuilder();
try {
parser.merge(protoJson, historyBuilder);
} catch (InvalidProtocolBufferException e) {
throw new DataConverterException(e);
}
History history = historyBuilder.build();
String workflowId =
io.temporal.internal.common.WorkflowExecutionHistory.extractWorkflowId(history);
return new WorkflowExecutionHistory(history, workflowId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class WorkflowExecutionHistory {
private final String workflowId;

public WorkflowExecutionHistory(History history) {
this(history, DEFAULT_WORKFLOW_ID);
this(history, extractWorkflowId(history));
}

public WorkflowExecutionHistory(History history, String workflowId) {
Expand All @@ -44,9 +44,17 @@ public WorkflowExecutionHistory(History history, String workflowId) {
this.workflowId = workflowId;
}

public static String extractWorkflowId(History history) {
HistoryEvent startedEvent = history.getEvents(0);
String id = startedEvent.getWorkflowExecutionStartedEventAttributes().getWorkflowId();
return id.isEmpty() ? DEFAULT_WORKFLOW_ID : id;
}

public static WorkflowExecutionHistory fromJson(String serialized) {
return new WorkflowExecutionHistory(
io.temporal.common.WorkflowExecutionHistory.fromJson(serialized).getHistory());
io.temporal.common.WorkflowExecutionHistory parsed =
io.temporal.common.WorkflowExecutionHistory.fromJson(serialized);
History history = parsed.getHistory();
return new WorkflowExecutionHistory(history, extractWorkflowId(history));
}

private static void checkHistory(History history) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public void deserializeAndSerializeBackComplexHistory() throws IOException {
deserializeAndSerializeBack("complexHistory1.json");
}

@Test
public void workflowIdIsExtractedWhenPresent() throws IOException {
WorkflowExecutionHistory history =
WorkflowHistoryLoader.readHistoryFromResource("simpleHistory_withWorkflowId.json");
assertEquals(
"ff28c127-56ff-416f-8630-53fa4f4cf79a", history.getWorkflowExecution().getWorkflowId());
}

public void deserializeAndSerializeBack(String resourceName) throws IOException {
// Load legacy-format history
ClassLoader classLoader = WorkflowExecutionUtils.class.getClassLoader();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.temporal.workflow.activityTests;

import static org.junit.Assert.assertThrows;

import io.temporal.activity.LocalActivityOptions;
import io.temporal.api.enums.v1.EventType;
import io.temporal.api.enums.v1.ParentClosePolicy;
Expand Down Expand Up @@ -44,13 +42,10 @@ public void localActivityAfterChildWorkflowCanceled() {
}

@Test
public void testLocalActivityAfterChildWorkflowCanceledReplay() {
assertThrows(
RuntimeException.class,
() ->
WorkflowReplayer.replayWorkflowExecutionFromResource(
"testLocalActivityAfterCancelTest.json",
LocalActivityAfterCancelTest.TestLocalActivityRetry.class));
public void testLocalActivityAfterChildWorkflowCanceledReplay() throws Exception {
WorkflowReplayer.replayWorkflowExecutionFromResource(
"testLocalActivityAfterCancelTest.json",
LocalActivityAfterCancelTest.TestLocalActivityRetry.class);
}

@WorkflowInterface
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"events": [
{
"eventId": "1",
"eventTime": "2020-07-30T00:30:03.082421843Z",
"eventType": "WorkflowExecutionStarted",
"version": "-24",
"taskId": "5242897",
"workflowExecutionStartedEventAttributes": {
"workflowType": {
"name": "SomeName"
},
"taskQueue": {
"name": "SomeQueueName",
"kind": "Normal"
},
"workflowExecutionTimeout": "300s",
"workflowTaskTimeout": "60s",
"originalExecutionRunId": "1fd5d4c8-1590-4a0a-8027-535e8729de8e",
"firstExecutionRunId": "1fd5d4c8-1590-4a0a-8027-535e8729de8e",
"attempt": 1,
"firstWorkflowTaskBackoff": "0s",
"workflowId": "ff28c127-56ff-416f-8630-53fa4f4cf79a"
}
}
]
}
Loading