Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class HistoryJsonUtils {
Configuration.builder().options(Option.SUPPRESS_EXCEPTIONS).build();

public static String protoJsonToHistoryFormatJson(String protoJson) {
DocumentContext parsed = JsonPath.parse(protoJson);
DocumentContext parsed = JsonPath.parse(protoJson, JSON_PATH_CONFIGURATION);
parsed.map(
EVENT_TYPE_PATH,
(currentValue, configuration) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@

package io.temporal.internal.common;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;

import com.google.common.io.CharStreams;
import io.temporal.testing.WorkflowHistoryLoader;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.net.URL;
import java.nio.file.Files;
import org.junit.Test;

public class WorkflowExecutionHistoryTest {
Expand All @@ -44,4 +50,24 @@ public void addingANewFieldToHistoryJsonShouldProduceTheSameResult() throws IOEx

assertEquals(originalHistory.getLastEvent(), historyWithAnAddedNewField.getLastEvent());
}

@Test
public void deserializeAndSerializeBack() throws IOException {
final String HISTORY_RESOURCE_NAME = "simpleHistory1.json";

ClassLoader classLoader = WorkflowExecutionUtils.class.getClassLoader();
URL resource = classLoader.getResource(HISTORY_RESOURCE_NAME);
String historyUrl = resource.getFile();
File historyFile = new File(historyUrl);
String originalSerializedJsonHistory;
try (Reader reader = Files.newBufferedReader(historyFile.toPath(), UTF_8)) {
originalSerializedJsonHistory = CharStreams.toString(reader);
}

WorkflowExecutionHistory history =
WorkflowHistoryLoader.readHistoryFromResource(HISTORY_RESOURCE_NAME);

String serializedHistory = history.toJson(true);
assertEquals(originalSerializedJsonHistory, serializedHistory);
}
}
46 changes: 23 additions & 23 deletions temporal-sdk/src/test/resources/simpleHistory1.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"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"
},
"input": null,
"workflowExecutionTimeout": "300s",
"workflowTaskTimeout": "60s",
"originalExecutionRunId": "1fd5d4c8-1590-4a0a-8027-535e8729de8e",
"identity":"",
"firstExecutionRunId": "1fd5d4c8-1590-4a0a-8027-535e8729de8e",
"attempt": 1,
"firstWorkflowTaskBackoff": "0s"
"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"
}
}
}]
]
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"events": [{
"eventId": "1",
"eventTime": "2020-07-30T00:30:03.082421843Z",
"eventType": "WorkflowExecutionStarted",
"version": "-24",
"taskId": "5242897",
"someNewFieldThatIsAbsentFromTheCurrentProtoSchema": "100500",
"workflowExecutionStartedEventAttributes": {
"events": [
{
"eventId": "1",
"eventTime": "2020-07-30T00:30:03.082421843Z",
"eventType": "WorkflowExecutionStarted",
"version": "-24",
"taskId": "5242897",
"someNewFieldThatIsAbsentFromTheCurrentProtoSchema": "100500",
"workflowType": {
"name": "SomeName"
},
"taskQueue": {
"name": "SomeQueueName",
"kind": "Normal"
},
"input": null,
"workflowExecutionTimeout": "300s",
"workflowTaskTimeout": "60s",
"originalExecutionRunId": "1fd5d4c8-1590-4a0a-8027-535e8729de8e",
"identity":"",
"firstExecutionRunId": "1fd5d4c8-1590-4a0a-8027-535e8729de8e",
"attempt": 1,
"firstWorkflowTaskBackoff": "0s"
"workflowExecutionStartedEventAttributes": {
"someNewFieldThatIsAbsentFromTheCurrentProtoSchema": "100500",
"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"
}
}
}]
]
}