Skip to content

Commit cb1c4c5

Browse files
committed
addressed copilot comments
1 parent 40270bd commit cb1c4c5

5 files changed

Lines changed: 95 additions & 12 deletions

File tree

client/src/main/java/com/microsoft/durabletask/ListInstanceIdsQuery.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import javax.annotation.Nullable;
66
import java.time.Instant;
77
import java.util.ArrayList;
8+
import java.util.Collections;
89
import java.util.List;
910

1011
/**
@@ -93,26 +94,46 @@ public ListInstanceIdsQuery setContinuationToken(@Nullable String continuationTo
9394
return this;
9495
}
9596

96-
List<OrchestrationRuntimeStatus> getRuntimeStatusList() {
97-
return this.runtimeStatusList;
97+
/**
98+
* Gets the configured terminal runtime status filter, or an empty list if none was configured.
99+
* @return an unmodifiable view of the configured terminal runtime status filter
100+
*/
101+
public List<OrchestrationRuntimeStatus> getRuntimeStatusList() {
102+
return Collections.unmodifiableList(this.runtimeStatusList);
98103
}
99104

105+
/**
106+
* Gets the configured minimum completion time, or {@code null} if none was configured.
107+
* @return the configured minimum completion time, or {@code null} if none was configured
108+
*/
100109
@Nullable
101-
Instant getCompletedTimeFrom() {
110+
public Instant getCompletedTimeFrom() {
102111
return this.completedTimeFrom;
103112
}
104113

114+
/**
115+
* Gets the configured maximum completion time, or {@code null} if none was configured.
116+
* @return the configured maximum completion time, or {@code null} if none was configured
117+
*/
105118
@Nullable
106-
Instant getCompletedTimeTo() {
119+
public Instant getCompletedTimeTo() {
107120
return this.completedTimeTo;
108121
}
109122

110-
int getPageSize() {
123+
/**
124+
* Gets the configured maximum number of instance IDs to return per page.
125+
* @return the configured page size
126+
*/
127+
public int getPageSize() {
111128
return this.pageSize;
112129
}
113130

131+
/**
132+
* Gets the configured pagination cursor, or {@code null} if none was configured.
133+
* @return the configured pagination cursor, or {@code null} if none was configured
134+
*/
114135
@Nullable
115-
String getContinuationToken() {
136+
public String getContinuationToken() {
116137
return this.continuationToken;
117138
}
118139
}

client/src/main/java/com/microsoft/durabletask/history/OrchestrationState.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public OrchestrationState(
8484
this.failureDetails = failureDetails;
8585
this.executionId = executionId;
8686
this.parentInstanceId = parentInstanceId;
87-
this.tags = tags == null ? null : Collections.unmodifiableMap(new HashMap<>(tags));
87+
this.tags = tags != null ? Collections.unmodifiableMap(new HashMap<>(tags)) : Collections.emptyMap();
8888
}
8989

9090
/** @return the orchestration instance ID. */
@@ -168,8 +168,7 @@ public String getParentInstanceId() {
168168
return this.parentInstanceId;
169169
}
170170

171-
/** @return an unmodifiable view of the orchestration tags, or {@code null} if not set. */
172-
@Nullable
171+
/** @return the orchestration tags (never {@code null}; empty when none). */
173172
public Map<String, String> getTags() {
174173
return this.tags;
175174
}

client/src/test/java/com/microsoft/durabletask/IntegrationTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,14 +1320,12 @@ void listInstanceIdsByCompletionWindow() throws TimeoutException {
13201320

13211321
DurableTaskClient client = this.createClientBuilder().build();
13221322
try (worker; client) {
1323-
Instant from = Instant.now().minus(Duration.ofMinutes(1));
1324-
13251323
String instanceId = client.scheduleNewOrchestrationInstance(orchestratorName, 0);
13261324
OrchestrationMetadata metadata = client.waitForInstanceCompletion(instanceId, defaultTimeout, false);
13271325
assertEquals(OrchestrationRuntimeStatus.COMPLETED, metadata.getRuntimeStatus());
13281326

13291327
ListInstanceIdsResult result = client.listInstanceIds(new ListInstanceIdsQuery()
1330-
.setCompletedTimeFrom(from)
1328+
.setCompletedTimeFrom(metadata.getCreatedAt())
13311329
.setRuntimeStatusList(Collections.singletonList(OrchestrationRuntimeStatus.COMPLETED))
13321330
.setPageSize(100));
13331331

client/src/test/java/com/microsoft/durabletask/ListInstanceIdsQueryTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import org.junit.jupiter.api.Test;
66

7+
import java.time.Instant;
78
import java.util.ArrayList;
89
import java.util.Arrays;
910
import java.util.List;
@@ -43,6 +44,30 @@ void setRuntimeStatusList_copiesInput_soExternalMutationDoesNotAffectQuery() {
4344
assertEquals(Arrays.asList(OrchestrationRuntimeStatus.COMPLETED), query.getRuntimeStatusList());
4445
}
4546

47+
@Test
48+
void getRuntimeStatusList_returnsUnmodifiableView() {
49+
ListInstanceIdsQuery query = new ListInstanceIdsQuery()
50+
.setRuntimeStatusList(Arrays.asList(OrchestrationRuntimeStatus.COMPLETED));
51+
52+
assertThrows(
53+
UnsupportedOperationException.class,
54+
() -> query.getRuntimeStatusList().add(OrchestrationRuntimeStatus.FAILED));
55+
}
56+
57+
@Test
58+
void getters_returnConfiguredValues() {
59+
Instant completedTimeFrom = Instant.parse("2026-01-01T00:00:00Z");
60+
Instant completedTimeTo = Instant.parse("2026-01-02T00:00:00Z");
61+
ListInstanceIdsQuery query = new ListInstanceIdsQuery()
62+
.setCompletedTimeFrom(completedTimeFrom)
63+
.setCompletedTimeTo(completedTimeTo)
64+
.setContinuationToken("next-page");
65+
66+
assertEquals(completedTimeFrom, query.getCompletedTimeFrom());
67+
assertEquals(completedTimeTo, query.getCompletedTimeTo());
68+
assertEquals("next-page", query.getContinuationToken());
69+
}
70+
4671
@Test
4772
void setPageSize_positiveValue_updatesPageSize() {
4873
ListInstanceIdsQuery query = new ListInstanceIdsQuery().setPageSize(25);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
package com.microsoft.durabletask.history;
4+
5+
import com.microsoft.durabletask.OrchestrationRuntimeStatus;
6+
import org.junit.jupiter.api.Test;
7+
8+
import static org.junit.jupiter.api.Assertions.assertNotNull;
9+
import static org.junit.jupiter.api.Assertions.assertThrows;
10+
import static org.junit.jupiter.api.Assertions.assertTrue;
11+
12+
/**
13+
* Unit tests for {@link OrchestrationState}.
14+
*/
15+
public class OrchestrationStateTest {
16+
17+
@Test
18+
void nullTagsNormalizeToEmptyUnmodifiableMap() {
19+
OrchestrationState state = new OrchestrationState(
20+
"instance-id",
21+
"orchestration-name",
22+
null,
23+
OrchestrationRuntimeStatus.COMPLETED,
24+
null,
25+
null,
26+
null,
27+
null,
28+
null,
29+
null,
30+
null,
31+
null,
32+
null,
33+
null,
34+
null);
35+
36+
assertNotNull(state.getTags());
37+
assertTrue(state.getTags().isEmpty());
38+
assertThrows(UnsupportedOperationException.class, () -> state.getTags().put("env", "prod"));
39+
}
40+
}

0 commit comments

Comments
 (0)