Skip to content

Commit e384b67

Browse files
committed
Fix Jackson serialization of ScheduleOperationRequest
1 parent 62d1c23 commit e384b67

2 files changed

Lines changed: 58 additions & 7 deletions

File tree

scheduledtasks/src/main/java/com/microsoft/durabletask/scheduledtasks/ExecuteScheduleOperationOrchestrator.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ final class ScheduleOperationRequest {
4040
private Object input;
4141

4242
/** Creates an empty {@code ScheduleOperationRequest} (for deserialization). */
43-
ScheduleOperationRequest() {
43+
public ScheduleOperationRequest() {
4444
}
4545

4646
ScheduleOperationRequest(EntityInstanceId entityId, String operationName, @Nullable Object input) {
@@ -49,28 +49,28 @@ final class ScheduleOperationRequest {
4949
this.input = input;
5050
}
5151

52-
EntityInstanceId getEntityId() {
52+
public EntityInstanceId getEntityId() {
5353
return this.entityId;
5454
}
5555

56-
void setEntityId(EntityInstanceId entityId) {
56+
public void setEntityId(EntityInstanceId entityId) {
5757
this.entityId = entityId;
5858
}
5959

60-
String getOperationName() {
60+
public String getOperationName() {
6161
return this.operationName;
6262
}
6363

64-
void setOperationName(String operationName) {
64+
public void setOperationName(String operationName) {
6565
this.operationName = operationName;
6666
}
6767

6868
@Nullable
69-
Object getInput() {
69+
public Object getInput() {
7070
return this.input;
7171
}
7272

73-
void setInput(@Nullable Object input) {
73+
public void setInput(@Nullable Object input) {
7474
this.input = input;
7575
}
7676
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
package com.microsoft.durabletask.scheduledtasks;
4+
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
import com.fasterxml.jackson.databind.json.JsonMapper;
7+
import com.microsoft.durabletask.EntityInstanceId;
8+
import org.junit.jupiter.api.Test;
9+
10+
import java.time.Duration;
11+
12+
import static org.junit.jupiter.api.Assertions.assertEquals;
13+
import static org.junit.jupiter.api.Assertions.assertNotNull;
14+
15+
/**
16+
* Verifies {@link ScheduleOperationRequest} serializes through the same Jackson configuration the worker uses.
17+
* <p>
18+
* Regression guard: the request is the orchestration input for every mutating client operation, so if it has no
19+
* Jackson-discoverable properties the client fails at {@code scheduleNewOrchestrationInstance} before reaching the
20+
* backend. This is only exercised end-to-end, so it must be covered here.
21+
*/
22+
class ScheduleOperationRequestSerializationTest {
23+
24+
private static final ObjectMapper MAPPER = JsonMapper.builder().findAndAddModules().build();
25+
26+
@Test
27+
void serializesWithOptionsPayload() throws Exception {
28+
ScheduleOperationRequest request = new ScheduleOperationRequest(
29+
new EntityInstanceId(Schedule.NAME, "s1"),
30+
ScheduleTransitions.CREATE_SCHEDULE,
31+
new ScheduleCreationOptions("s1", "orch", Duration.ofSeconds(30)).setOrchestrationInput("world"));
32+
33+
String json = MAPPER.writeValueAsString(request);
34+
assertNotNull(json);
35+
36+
ScheduleOperationRequest restored = MAPPER.readValue(json, ScheduleOperationRequest.class);
37+
assertEquals("s1", restored.getEntityId().getKey());
38+
assertEquals(ScheduleTransitions.CREATE_SCHEDULE, restored.getOperationName());
39+
assertNotNull(restored.getInput());
40+
}
41+
42+
@Test
43+
void serializesWithNullInput() throws Exception {
44+
ScheduleOperationRequest request = new ScheduleOperationRequest(
45+
new EntityInstanceId(Schedule.NAME, "s1"), ScheduleTransitions.PAUSE_SCHEDULE, null);
46+
47+
ScheduleOperationRequest restored =
48+
MAPPER.readValue(MAPPER.writeValueAsString(request), ScheduleOperationRequest.class);
49+
assertEquals(ScheduleTransitions.PAUSE_SCHEDULE, restored.getOperationName());
50+
}
51+
}

0 commit comments

Comments
 (0)