Skip to content

Commit e67bc61

Browse files
FIx test
1 parent 0256a9c commit e67bc61

7 files changed

Lines changed: 50 additions & 110 deletions

File tree

temporal-sdk/src/main/java/io/temporal/client/TemporalNexusServiceClientOptions.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,36 @@ public static Builder newBuilder() {
1515
this.taskQueue = taskQueue;
1616
}
1717

18-
String getEndpoint() {
18+
public String getEndpoint() {
1919
return endpoint;
2020
}
2121

22-
String getTaskQueue() {
22+
public String getTaskQueue() {
2323
return taskQueue;
2424
}
2525

2626
public static final class Builder {
2727
private String endpoint;
2828
private String taskQueue;
2929

30-
Builder setTaskQueue(String taskQueue) {
30+
public Builder setTaskQueue(String taskQueue) {
3131
this.taskQueue = taskQueue;
3232
return this;
3333
}
3434

35-
Builder setEndpoint(String endpoint) {
35+
public Builder setEndpoint(String endpoint) {
3636
this.endpoint = endpoint;
3737
return this;
3838
}
3939

40-
TemporalNexusServiceClientOptions build() {
40+
public TemporalNexusServiceClientOptions build() {
4141
if (Strings.isNullOrEmpty(endpoint) && Strings.isNullOrEmpty(taskQueue)) {
4242
throw new IllegalArgumentException("Must provide either a task queue or an endpoint");
4343
} else if (!Strings.isNullOrEmpty(endpoint) && !Strings.isNullOrEmpty(taskQueue)) {
4444
throw new IllegalArgumentException("Must provide only a task queue or an endpoint");
4545
}
4646

47-
48-
return new TemporalNexusServiceClientOptions(
49-
endpoint, taskQueue
50-
);
47+
return new TemporalNexusServiceClientOptions(endpoint, taskQueue);
5148
}
5249
}
5350
}

temporal-sdk/src/main/java/io/temporal/client/WorkflowClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ static WorkflowClient newInstance(WorkflowServiceStubs service, WorkflowClientOp
136136
* @return A new {@link ServiceClient} instance backed by this {@link WorkflowClient} instance.
137137
*/
138138
@Experimental
139-
<T> ServiceClient<T> newNexusServiceClient(Class<T> nexusServiceInterface, TemporalNexusServiceClientOptions options);
139+
<T> ServiceClient<T> newNexusServiceClient(
140+
Class<T> nexusServiceInterface, TemporalNexusServiceClientOptions options);
140141

141142
/**
142143
* Creates a new {@link CompletionClient} that can be used to complete or fail async operations

temporal-sdk/src/main/java/io/temporal/client/WorkflowClientInternalImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,17 @@ public <T> ServiceClient<T> newNexusServiceClient(
110110
Class<T> nexusServiceInterface, TemporalNexusServiceClientOptions serviceClientOptions) {
111111
return new ServiceClient<>(
112112
ServiceClientOptions.newBuilder(nexusServiceInterface)
113-
.setTransport(new workflowServiceNexusTransport(genericClient, serviceClientOptions, options))
113+
.setTransport(
114+
new workflowServiceNexusTransport(genericClient, serviceClientOptions, options))
114115
.setSerializer(new PayloadSerializer(options.getDataConverter()))
115116
.build());
116117
}
117118

118119
@Override
119120
public CompletionClient newNexusCompletionClient() {
120-
return new CompletionClient(new workflowServiceNexusTransport(genericClient, "", options));
121+
return new CompletionClient(
122+
new workflowServiceNexusTransport(
123+
genericClient, TemporalNexusServiceClientOptions.newBuilder().build(), options));
121124
}
122125

123126
@Override

temporal-sdk/src/main/java/io/temporal/client/workflowServiceNexusTransport.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,17 @@ public class workflowServiceNexusTransport implements Transport {
4444
private final TaskDispatchTarget dispatchTarget;
4545

4646
public workflowServiceNexusTransport(
47-
GenericWorkflowClient client, TemporalNexusServiceClientOptions serviceClientOptions, WorkflowClientOptions options) {
47+
GenericWorkflowClient client,
48+
TemporalNexusServiceClientOptions serviceClientOptions,
49+
WorkflowClientOptions options) {
4850
this.client = client;
4951
this.clientOptions = options;
5052
if (serviceClientOptions.getEndpoint() != null) {
51-
this.dispatchTarget = TaskDispatchTarget.newBuilder().setEndpoint(serviceClientOptions.getEndpoint()).build();
53+
this.dispatchTarget =
54+
TaskDispatchTarget.newBuilder().setEndpoint(serviceClientOptions.getEndpoint()).build();
5255
} else if (serviceClientOptions.getTaskQueue() != null) {
53-
this.dispatchTarget = TaskDispatchTarget.newBuilder().setTaskQueue(serviceClientOptions.getTaskQueue()).build();
56+
this.dispatchTarget =
57+
TaskDispatchTarget.newBuilder().setTaskQueue(serviceClientOptions.getTaskQueue()).build();
5458
} else {
5559
throw new IllegalArgumentException("No target specified");
5660
}

temporal-sdk/src/test/java/io/temporal/client/NexusServiceClientSyncOperationTest.java

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ public void executeSyncOperation()
3030
ExecutionException,
3131
InterruptedException {
3232
ServiceClient<TestNexusServices.TestNexusService1> serviceClient =
33-
testWorkflowRule
34-
.getWorkflowClient()
35-
.newNexusServiceClient(
36-
TestNexusServices.TestNexusService1.class,
37-
testWorkflowRule.getNexusEndpoint().getSpec().getName());
33+
testWorkflowRule.newNexusServiceClient(TestNexusServices.TestNexusService1.class);
3834

3935
String result =
4036
serviceClient.executeOperation(TestNexusServices.TestNexusService1::operation, "World");
@@ -50,11 +46,7 @@ public void executeSyncOperation()
5046
@Test
5147
public void executeSyncOperationFail() {
5248
ServiceClient<TestNexusServices.TestNexusService1> serviceClient =
53-
testWorkflowRule
54-
.getWorkflowClient()
55-
.newNexusServiceClient(
56-
TestNexusServices.TestNexusService1.class,
57-
testWorkflowRule.getNexusEndpoint().getSpec().getName());
49+
testWorkflowRule.newNexusServiceClient(TestNexusServices.TestNexusService1.class);
5850

5951
OperationException oe =
6052
Assert.assertThrows(
@@ -77,11 +69,7 @@ public void executeSyncOperationFail() {
7769
@Test
7870
public void executeSyncOperationHandlerError() {
7971
ServiceClient<TestNexusServices.TestNexusService1> serviceClient =
80-
testWorkflowRule
81-
.getWorkflowClient()
82-
.newNexusServiceClient(
83-
TestNexusServices.TestNexusService1.class,
84-
testWorkflowRule.getNexusEndpoint().getSpec().getName());
72+
testWorkflowRule.newNexusServiceClient(TestNexusServices.TestNexusService1.class);
8573

8674
HandlerException he =
8775
Assert.assertThrows(
@@ -95,11 +83,7 @@ public void executeSyncOperationHandlerError() {
9583
@Test
9684
public void executeSyncOperationCancel() {
9785
ServiceClient<TestNexusServices.TestNexusService1> serviceClient =
98-
testWorkflowRule
99-
.getWorkflowClient()
100-
.newNexusServiceClient(
101-
TestNexusServices.TestNexusService1.class,
102-
testWorkflowRule.getNexusEndpoint().getSpec().getName());
86+
testWorkflowRule.newNexusServiceClient(TestNexusServices.TestNexusService1.class);
10387

10488
OperationException oe =
10589
Assert.assertThrows(
@@ -123,11 +107,7 @@ public void executeSyncOperationCancel() {
123107
@Test
124108
public void startSyncOperation() throws OperationException {
125109
ServiceClient<TestNexusServices.TestNexusService1> serviceClient =
126-
testWorkflowRule
127-
.getWorkflowClient()
128-
.newNexusServiceClient(
129-
TestNexusServices.TestNexusService1.class,
130-
testWorkflowRule.getNexusEndpoint().getSpec().getName());
110+
testWorkflowRule.newNexusServiceClient(TestNexusServices.TestNexusService1.class);
131111

132112
StartOperationResponse<String> result =
133113
serviceClient.startOperation(TestNexusServices.TestNexusService1::operation, "World");
@@ -146,11 +126,7 @@ public void startSyncOperation() throws OperationException {
146126
@Test
147127
public void startSyncOperationFail() {
148128
ServiceClient<TestNexusServices.TestNexusService1> serviceClient =
149-
testWorkflowRule
150-
.getWorkflowClient()
151-
.newNexusServiceClient(
152-
TestNexusServices.TestNexusService1.class,
153-
testWorkflowRule.getNexusEndpoint().getSpec().getName());
129+
testWorkflowRule.newNexusServiceClient(TestNexusServices.TestNexusService1.class);
154130

155131
OperationException oe =
156132
Assert.assertThrows(
@@ -173,11 +149,7 @@ public void startSyncOperationFail() {
173149
@Test
174150
public void startSyncOperationCancel() {
175151
ServiceClient<TestNexusServices.TestNexusService1> serviceClient =
176-
testWorkflowRule
177-
.getWorkflowClient()
178-
.newNexusServiceClient(
179-
TestNexusServices.TestNexusService1.class,
180-
testWorkflowRule.getNexusEndpoint().getSpec().getName());
152+
testWorkflowRule.newNexusServiceClient(TestNexusServices.TestNexusService1.class);
181153

182154
OperationException oe =
183155
Assert.assertThrows(

temporal-sdk/src/test/java/io/temporal/client/NexusServiceClientWorkflowOperationTest.java

Lines changed: 11 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ public class NexusServiceClientWorkflowOperationTest {
3535
public void executeWorkflowOperationSuccess()
3636
throws OperationStillRunningException, OperationException {
3737
ServiceClient<TestNexusServices.TestNexusService1> serviceClient =
38-
testWorkflowRule
39-
.getWorkflowClient()
40-
.newNexusServiceClient(
41-
TestNexusServices.TestNexusService1.class,
42-
testWorkflowRule.getNexusEndpoint().getSpec().getName());
38+
testWorkflowRule.newNexusServiceClient(TestNexusServices.TestNexusService1.class);
4339

4440
Assert.assertEquals(
4541
"Hello World",
@@ -59,11 +55,7 @@ public void executeWorkflowOperationSuccess()
5955
@Test
6056
public void executeWorkflowOperationFail() {
6157
ServiceClient<TestNexusServices.TestNexusService1> serviceClient =
62-
testWorkflowRule
63-
.getWorkflowClient()
64-
.newNexusServiceClient(
65-
TestNexusServices.TestNexusService1.class,
66-
testWorkflowRule.getNexusEndpoint().getSpec().getName());
58+
testWorkflowRule.newNexusServiceClient(TestNexusServices.TestNexusService1.class);
6759

6860
OperationException oe =
6961
Assert.assertThrows(
@@ -92,12 +84,7 @@ public void executeWorkflowOperationFail() {
9284
@Test
9385
public void executeWorkflowOperationStillRunning() {
9486
ServiceClient<TestNexusServices.TestNexusService1> serviceClient =
95-
testWorkflowRule
96-
.getWorkflowClient()
97-
.newNexusServiceClient(
98-
TestNexusServices.TestNexusService1.class,
99-
testWorkflowRule.getNexusEndpoint().getSpec().getName());
100-
87+
testWorkflowRule.newNexusServiceClient(TestNexusServices.TestNexusService1.class);
10188
Assert.assertThrows(
10289
OperationStillRunningException.class,
10390
() ->
@@ -120,11 +107,7 @@ public void executeWorkflowOperationStillRunning() {
120107
public void createHandle()
121108
throws OperationException, OperationStillRunningException, InterruptedException {
122109
ServiceClient<TestNexusServices.TestNexusService1> serviceClient =
123-
testWorkflowRule
124-
.getWorkflowClient()
125-
.newNexusServiceClient(
126-
TestNexusServices.TestNexusService1.class,
127-
testWorkflowRule.getNexusEndpoint().getSpec().getName());
110+
testWorkflowRule.newNexusServiceClient(TestNexusServices.TestNexusService1.class);
128111

129112
StartOperationResponse<String> startResult =
130113
serviceClient.startOperation(TestNexusServices.TestNexusService1::operation, "World");
@@ -145,11 +128,7 @@ public void createHandle()
145128
public void createHandleUntyped()
146129
throws OperationException, OperationStillRunningException, InterruptedException {
147130
ServiceClient<TestNexusServices.TestNexusService1> serviceClient =
148-
testWorkflowRule
149-
.getWorkflowClient()
150-
.newNexusServiceClient(
151-
TestNexusServices.TestNexusService1.class,
152-
testWorkflowRule.getNexusEndpoint().getSpec().getName());
131+
testWorkflowRule.newNexusServiceClient(TestNexusServices.TestNexusService1.class);
153132

154133
StartOperationResponse<String> startResult =
155134
serviceClient.startOperation(TestNexusServices.TestNexusService1::operation, "World");
@@ -170,11 +149,7 @@ public void createHandleUntyped()
170149
@Test
171150
public void createInvalidHandle() throws JsonProcessingException {
172151
ServiceClient<TestNexusServices.TestNexusService1> serviceClient =
173-
testWorkflowRule
174-
.getWorkflowClient()
175-
.newNexusServiceClient(
176-
TestNexusServices.TestNexusService1.class,
177-
testWorkflowRule.getNexusEndpoint().getSpec().getName());
152+
testWorkflowRule.newNexusServiceClient(TestNexusServices.TestNexusService1.class);
178153

179154
OperationHandle<String> badHandle =
180155
serviceClient.newHandle(TestNexusServices.TestNexusService1::operation, "BAD_TOKEN");
@@ -211,11 +186,7 @@ public void createInvalidHandle() throws JsonProcessingException {
211186
@Test
212187
public void startAsyncOperation() throws OperationException, OperationStillRunningException {
213188
ServiceClient<TestNexusServices.TestNexusService1> serviceClient =
214-
testWorkflowRule
215-
.getWorkflowClient()
216-
.newNexusServiceClient(
217-
TestNexusServices.TestNexusService1.class,
218-
testWorkflowRule.getNexusEndpoint().getSpec().getName());
189+
testWorkflowRule.newNexusServiceClient(TestNexusServices.TestNexusService1.class);
219190

220191
StartOperationResponse<String> startResult =
221192
serviceClient.startOperation(TestNexusServices.TestNexusService1::operation, "World");
@@ -241,11 +212,7 @@ public void startAsyncOperation() throws OperationException, OperationStillRunni
241212
@Test
242213
public void cancelAsyncOperation() throws OperationException {
243214
ServiceClient<TestNexusServices.TestNexusService1> serviceClient =
244-
testWorkflowRule
245-
.getWorkflowClient()
246-
.newNexusServiceClient(
247-
TestNexusServices.TestNexusService1.class,
248-
testWorkflowRule.getNexusEndpoint().getSpec().getName());
215+
testWorkflowRule.newNexusServiceClient(TestNexusServices.TestNexusService1.class);
249216

250217
StartOperationResponse<String> startResult =
251218
serviceClient.startOperation(TestNexusServices.TestNexusService1::operation, "World");
@@ -271,11 +238,7 @@ public void cancelAsyncOperation() throws OperationException {
271238
@Test
272239
public void cancelAsyncOperationAsync() {
273240
ServiceClient<TestNexusServices.TestNexusService1> serviceClient =
274-
testWorkflowRule
275-
.getWorkflowClient()
276-
.newNexusServiceClient(
277-
TestNexusServices.TestNexusService1.class,
278-
testWorkflowRule.getNexusEndpoint().getSpec().getName());
241+
testWorkflowRule.newNexusServiceClient(TestNexusServices.TestNexusService1.class);
279242

280243
StartOperationResponse<String> startResult =
281244
serviceClient
@@ -304,11 +267,7 @@ public void cancelAsyncOperationAsync() {
304267
@Test
305268
public void startAsyncOperationAsync() {
306269
ServiceClient<TestNexusServices.TestNexusService1> serviceClient =
307-
testWorkflowRule
308-
.getWorkflowClient()
309-
.newNexusServiceClient(
310-
TestNexusServices.TestNexusService1.class,
311-
testWorkflowRule.getNexusEndpoint().getSpec().getName());
270+
testWorkflowRule.newNexusServiceClient(TestNexusServices.TestNexusService1.class);
312271

313272
StartOperationResponse<String> startResult =
314273
serviceClient
@@ -342,11 +301,7 @@ public void startAsyncOperationAsync() {
342301
@Test
343302
public void startWorkflowOperationFail() throws OperationException {
344303
ServiceClient<TestNexusServices.TestNexusService1> serviceClient =
345-
testWorkflowRule
346-
.getWorkflowClient()
347-
.newNexusServiceClient(
348-
TestNexusServices.TestNexusService1.class,
349-
testWorkflowRule.getNexusEndpoint().getSpec().getName());
304+
testWorkflowRule.newNexusServiceClient(TestNexusServices.TestNexusService1.class);
350305

351306
StartOperationResponse<String> startResult =
352307
serviceClient.startOperation(TestNexusServices.TestNexusService1::operation, "fail");

temporal-testing/src/main/java/io/temporal/testing/internal/SDKTestWorkflowRule.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
import com.google.common.io.CharSink;
99
import com.google.common.io.Files;
1010
import com.uber.m3.tally.Scope;
11+
import io.nexusrpc.client.ServiceClient;
1112
import io.temporal.api.enums.v1.EventType;
1213
import io.temporal.api.enums.v1.IndexedValueType;
1314
import io.temporal.api.history.v1.History;
1415
import io.temporal.api.history.v1.HistoryEvent;
1516
import io.temporal.api.nexus.v1.Endpoint;
16-
import io.temporal.client.WorkflowClient;
17-
import io.temporal.client.WorkflowClientOptions;
18-
import io.temporal.client.WorkflowQueryException;
19-
import io.temporal.client.WorkflowStub;
17+
import io.temporal.client.*;
2018
import io.temporal.common.SearchAttributeKey;
2119
import io.temporal.common.WorkerDeploymentVersion;
2220
import io.temporal.common.WorkflowExecutionHistory;
@@ -367,6 +365,16 @@ public WorkflowClient getWorkflowClient() {
367365
return testWorkflowRule.getWorkflowClient();
368366
}
369367

368+
public <T> ServiceClient<T> newNexusServiceClient(Class<T> nexusServiceInterface) {
369+
return testWorkflowRule
370+
.getWorkflowClient()
371+
.newNexusServiceClient(
372+
nexusServiceInterface,
373+
TemporalNexusServiceClientOptions.newBuilder()
374+
.setEndpoint(getNexusEndpoint().getSpec().getName())
375+
.build());
376+
}
377+
370378
public WorkflowServiceStubs getWorkflowServiceStubs() {
371379
return testWorkflowRule.getWorkflowServiceStubs();
372380
}

0 commit comments

Comments
 (0)