Skip to content

Commit bd31359

Browse files
committed
Refactor due to PR comment
1 parent c2ebcf5 commit bd31359

2 files changed

Lines changed: 22 additions & 76 deletions

File tree

temporal-sdk/src/test/java/io/temporal/client/nexus/NexusClientInterceptorChainTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ public class NexusClientInterceptorChainTest {
2929

3030
@Rule
3131
public SDKTestWorkflowRule testWorkflowRule =
32-
SDKTestWorkflowRule.newBuilder()
33-
.setWorkflowTypes(PlaceholderWorkflowImpl.class)
34-
.build();
32+
SDKTestWorkflowRule.newBuilder().setWorkflowTypes(PlaceholderWorkflowImpl.class).build();
3533

3634
@BeforeClass
3735
public static void requireExternalService() {

temporal-sdk/src/test/java/io/temporal/client/nexus/NexusOperationHandleTest.java

Lines changed: 21 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -47,142 +47,93 @@ public static void requireExternalService() {
4747

4848
@Test
4949
public void describeReturnsDescriptionForStartedOperation() {
50-
StartedOperation started = startOperation();
51-
UntypedNexusOperationHandle handle =
52-
started.client.getHandle(started.operationId, started.runId);
50+
UntypedNexusOperationHandle handle = startOperation();
5351

5452
NexusOperationExecutionDescription description = handle.describe();
5553

5654
Assert.assertNotNull(description);
5755
Assert.assertNotNull(description.getRunId());
58-
Assert.assertEquals(started.runId, description.getRunId());
56+
Assert.assertEquals(handle.getNexusOperationRunId(), description.getRunId());
5957
Assert.assertNotNull(description.getRawResponse());
6058
}
6159

6260
@Test
6361
public void describeWithoutRunIdTargetsLatest() {
64-
StartedOperation started = startOperation();
65-
// Handle with no pinned run ID — server should resolve to the latest run.
66-
UntypedNexusOperationHandle handle = started.client.getHandle(started.operationId);
62+
UntypedNexusOperationHandle started = startOperation();
63+
// Re-bind a handle with no pinned run ID — server should resolve to the latest run.
64+
UntypedNexusOperationHandle handle =
65+
testWorkflowRule.getNexusClient().getHandle(started.getNexusOperationId());
6766

6867
NexusOperationExecutionDescription description = handle.describe();
6968

7069
Assert.assertNotNull(description);
71-
Assert.assertEquals(started.runId, description.getRunId());
70+
Assert.assertEquals(started.getNexusOperationRunId(), description.getRunId());
7271
}
7372

7473
@Test
7574
public void cancelSucceedsForStartedOperation() {
76-
StartedOperation started = startOperation();
77-
UntypedNexusOperationHandle handle =
78-
started.client.getHandle(started.operationId, started.runId);
79-
80-
handle.cancel();
75+
startOperation().cancel();
8176
// No exception — server accepted the cancel request.
8277
}
8378

8479
@Test
8580
public void cancelWithReasonSucceedsForStartedOperation() {
86-
StartedOperation started = startOperation();
87-
UntypedNexusOperationHandle handle =
88-
started.client.getHandle(started.operationId, started.runId);
89-
90-
handle.cancel("test-cancel-reason");
81+
startOperation().cancel("test-cancel-reason");
9182
}
9283

9384
@Test
9485
public void cancelWithNullReasonSucceeds() {
95-
StartedOperation started = startOperation();
96-
UntypedNexusOperationHandle handle =
97-
started.client.getHandle(started.operationId, started.runId);
98-
99-
handle.cancel(null);
86+
startOperation().cancel(null);
10087
}
10188

10289
@Test
10390
public void terminateSucceedsForStartedOperation() {
104-
StartedOperation started = startOperation();
105-
UntypedNexusOperationHandle handle =
106-
started.client.getHandle(started.operationId, started.runId);
107-
108-
handle.terminate();
91+
startOperation().terminate();
10992
}
11093

11194
@Test
11295
public void terminateWithReasonSucceedsForStartedOperation() {
113-
StartedOperation started = startOperation();
114-
UntypedNexusOperationHandle handle =
115-
started.client.getHandle(started.operationId, started.runId);
116-
117-
handle.terminate("test-terminate-reason");
96+
startOperation().terminate("test-terminate-reason");
11897
}
11998

12099
@Test
121100
public void terminateWithNullReasonSucceeds() {
122-
StartedOperation started = startOperation();
123-
UntypedNexusOperationHandle handle =
124-
started.client.getHandle(started.operationId, started.runId);
125-
126-
handle.terminate(null);
101+
startOperation().terminate(null);
127102
}
128103

129104
@Test
130105
public void getResultReturnsTypedResultForSyncOperation() {
131-
StartedOperation started = startOperation();
132-
UntypedNexusOperationHandle untyped =
133-
started.client.getHandle(started.operationId, started.runId);
134-
135-
String result = NexusOperationHandle.fromUntyped(untyped, String.class).getResult();
106+
String result = NexusOperationHandle.fromUntyped(startOperation(), String.class).getResult();
136107

137108
Assert.assertNotNull(result);
138109
Assert.assertTrue("expected echo: prefix, got: " + result, result.startsWith("echo:ping-"));
139110
}
140111

141112
@Test
142113
public void getResultUntypedReturnsResultForSyncOperation() {
143-
StartedOperation started = startOperation();
144-
UntypedNexusOperationHandle handle =
145-
started.client.getHandle(started.operationId, started.runId);
146-
147-
String result = handle.getResult(String.class);
114+
String result = startOperation().getResult(String.class);
148115

149116
Assert.assertNotNull(result);
150117
Assert.assertTrue(result.startsWith("echo:ping-"));
151118
}
152119

153120
@Test
154121
public void getResultAsyncReturnsTypedResultForSyncOperation() throws Exception {
155-
StartedOperation started = startOperation();
156-
UntypedNexusOperationHandle untyped =
157-
started.client.getHandle(started.operationId, started.runId);
158-
159122
String result =
160-
NexusOperationHandle.fromUntyped(untyped, String.class)
123+
NexusOperationHandle.fromUntyped(startOperation(), String.class)
161124
.getResultAsync()
162125
.get(60, java.util.concurrent.TimeUnit.SECONDS);
163126

164127
Assert.assertNotNull(result);
165128
Assert.assertTrue(result.startsWith("echo:ping-"));
166129
}
167130

168-
/** Holder for state used to drive a single test against one started operation. */
169-
private static final class StartedOperation {
170-
final NexusClient client;
171-
final String operationId;
172-
final String runId;
173-
174-
StartedOperation(NexusClient client, String operationId, String runId) {
175-
this.client = client;
176-
this.operationId = operationId;
177-
this.runId = runId;
178-
}
179-
}
180-
181-
private StartedOperation startOperation() {
131+
private UntypedNexusOperationHandle startOperation() {
182132
return startOperation(null);
183133
}
184134

185-
private StartedOperation startOperation(@javax.annotation.Nullable String inputOverride) {
135+
private UntypedNexusOperationHandle startOperation(
136+
@javax.annotation.Nullable String inputOverride) {
186137
NexusClient client = testWorkflowRule.getNexusClient();
187138
Endpoint endpoint = testWorkflowRule.getNexusEndpoint();
188139
String inputValue =
@@ -199,8 +150,7 @@ private StartedOperation startOperation(@javax.annotation.Nullable String inputO
199150
UntypedNexusOperationHandle handle = svcClient.start("operation", opts, inputValue);
200151

201152
Assert.assertNotNull("expected start to return a run ID", handle.getNexusOperationRunId());
202-
return new StartedOperation(
203-
client, handle.getNexusOperationId(), handle.getNexusOperationRunId());
153+
return handle;
204154
}
205155

206156
public static class PlaceholderWorkflowImpl implements TestWorkflows.TestWorkflow1 {
@@ -231,9 +181,7 @@ public OperationHandler<String, String> operation() {
231181

232182
@Test
233183
public void getResultPropagatesOperationFailure() {
234-
StartedOperation started = startOperation(TestNexusServiceImpl.FAIL_PREFIX + "boom");
235-
UntypedNexusOperationHandle handle =
236-
started.client.getHandle(started.operationId, started.runId);
184+
UntypedNexusOperationHandle handle = startOperation(TestNexusServiceImpl.FAIL_PREFIX + "boom");
237185

238186
try {
239187
handle.getResult(String.class);

0 commit comments

Comments
 (0)