Skip to content

Commit 6eb66fa

Browse files
Fix CI failure
1 parent cdfbd22 commit 6eb66fa

2 files changed

Lines changed: 6 additions & 108 deletions

File tree

temporal-sdk/src/main/java/io/temporal/nexus/TemporalOperationHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ protected void cancelWorkflowRun(
136136
}
137137

138138
/**
139-
* Called when a cancel request is received for an activity-execution token (type=4). Override to
139+
* Called when a cancel request is received for an activity-execution token (type=2). Override to
140140
* customize cancel behavior.
141141
*
142142
* <p>Default behavior: requests cancellation of the underlying standalone activity execution.

temporal-sdk/src/test/java/io/temporal/workflow/nexus/AsyncActivityOperationTest.java

Lines changed: 5 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22

33
import static org.junit.Assume.assumeTrue;
44

5-
import io.nexusrpc.handler.HandlerException;
65
import io.nexusrpc.handler.OperationHandler;
76
import io.nexusrpc.handler.OperationImpl;
87
import io.nexusrpc.handler.ServiceImpl;
98
import io.temporal.activity.ActivityInterface;
109
import io.temporal.activity.ActivityMethod;
1110
import io.temporal.client.StartActivityOptions;
12-
import io.temporal.client.WorkflowFailedException;
13-
import io.temporal.failure.ApplicationFailure;
14-
import io.temporal.failure.NexusOperationFailure;
1511
import io.temporal.internal.nexus.OperationToken;
1612
import io.temporal.internal.nexus.OperationTokenType;
1713
import io.temporal.internal.nexus.OperationTokenUtil;
@@ -25,61 +21,29 @@
2521
import org.junit.Rule;
2622
import org.junit.Test;
2723

28-
public class AsyncActivityOperationTest extends BaseNexusTest {
24+
public class AsyncActivityOperationTest {
2925

3026
@Rule
3127
public SDKTestWorkflowRule testWorkflowRule =
3228
SDKTestWorkflowRule.newBuilder()
33-
.setWorkflowTypes(TestNexus.class, DoubleStartNexus.class)
29+
.setWorkflowTypes(TestNexus.class)
3430
.setActivityImplementations(new TestActivityImpl())
35-
.setNexusServiceImplementation(
36-
new TestNexusServiceImpl(), new DoubleStartNexusServiceImpl())
31+
.setNexusServiceImplementation(new TestNexusServiceImpl())
3732
.build();
3833

39-
@Override
40-
protected SDKTestWorkflowRule getTestWorkflowRule() {
41-
return testWorkflowRule;
42-
}
43-
4434
@Test
4535
public void testActivityOperationEndToEnd() {
4636
// The in-process test-server does not implement the StartActivityExecution RPC; the
4737
// standalone-activity Nexus path requires a real server. Unit-only token assertions stay
4838
// active in OperationTokenTest.
4939
assumeTrue(SDKTestWorkflowRule.useExternalService);
50-
// Combined (a) caller workflow receives "hello " + input
51-
// (b) opToken loads as ACTIVITY_EXECUTION with aid="act-" + requestId
40+
// The caller workflow receives the activity result and an ACTIVITY_EXECUTION operation token.
5241
TestWorkflows.TestWorkflow1 workflowStub =
5342
testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class);
5443
String result = workflowStub.execute("world");
5544
Assert.assertEquals("hello world", result);
5645
}
5746

58-
@Test
59-
public void testDoubleStartActivityThrows() {
60-
// The first start RPC requires StartActivityExecution which is not implemented by the
61-
// in-process test server; gate this on a real server so the guard at the second call can be
62-
// observed.
63-
assumeTrue(SDKTestWorkflowRule.useExternalService);
64-
// (c) Calling startActivity twice in one handler invocation throws
65-
// HandlerException(BAD_REQUEST).
66-
TestDoubleStartWorkflow workflowStub =
67-
testWorkflowRule.newWorkflowStubTimeoutOptions(TestDoubleStartWorkflow.class);
68-
WorkflowFailedException e =
69-
Assert.assertThrows(WorkflowFailedException.class, () -> workflowStub.execute("anything"));
70-
Assert.assertTrue(e.getCause() instanceof NexusOperationFailure);
71-
NexusOperationFailure nexusFailure = (NexusOperationFailure) e.getCause();
72-
Assert.assertTrue(nexusFailure.getCause() instanceof HandlerException);
73-
HandlerException handlerException = (HandlerException) nexusFailure.getCause();
74-
Assert.assertTrue(handlerException.getCause() instanceof ApplicationFailure);
75-
ApplicationFailure appFailure = (ApplicationFailure) handlerException.getCause();
76-
Assert.assertEquals("java.lang.IllegalStateException", appFailure.getType());
77-
Assert.assertTrue(
78-
appFailure
79-
.getOriginalMessage()
80-
.startsWith("Only one async operation can be started per operation handler"));
81-
}
82-
8347
@ActivityInterface
8448
public interface TestActivity {
8549
@ActivityMethod
@@ -101,14 +65,10 @@ public String execute(String input) {
10165
.setScheduleToCloseTimeout(Duration.ofSeconds(20))
10266
.build();
10367
NexusServiceOptions serviceOptions =
104-
NexusServiceOptions.newBuilder()
105-
.setEndpoint(getEndpointName())
106-
.setOperationOptions(options)
107-
.build();
68+
NexusServiceOptions.newBuilder().setOperationOptions(options).build();
10869
TestNexusServices.TestNexusService1 serviceStub =
10970
Workflow.newNexusServiceStub(TestNexusServices.TestNexusService1.class, serviceOptions);
11071

111-
// Drive a handle so we can inspect the operation token for assertion (b).
11272
NexusOperationHandle<String> handle =
11373
Workflow.startNexusOperation(serviceStub::operation, input);
11474
NexusOperationExecution exec = handle.getExecution().get();
@@ -140,66 +100,4 @@ public OperationHandler<String, String> operation() {
140100
.build()));
141101
}
142102
}
143-
144-
// ---------- Double-start test scaffolding ----------
145-
146-
public static class DoubleStartNexus implements TestDoubleStartWorkflow {
147-
@Override
148-
public String execute(String input) {
149-
NexusOperationOptions options =
150-
NexusOperationOptions.newBuilder()
151-
.setScheduleToCloseTimeout(Duration.ofSeconds(10))
152-
.build();
153-
NexusServiceOptions serviceOptions =
154-
NexusServiceOptions.newBuilder()
155-
.setEndpoint(getEndpointName())
156-
.setOperationOptions(options)
157-
.build();
158-
DoubleStartNexusService stub =
159-
Workflow.newNexusServiceStub(DoubleStartNexusService.class, serviceOptions);
160-
return stub.operation(input);
161-
}
162-
}
163-
164-
@WorkflowInterface
165-
public interface TestDoubleStartWorkflow {
166-
@WorkflowMethod
167-
String execute(String input);
168-
}
169-
170-
@io.nexusrpc.Service
171-
public interface DoubleStartNexusService {
172-
@io.nexusrpc.Operation
173-
String operation(String input);
174-
}
175-
176-
@ServiceImpl(service = DoubleStartNexusService.class)
177-
public class DoubleStartNexusServiceImpl {
178-
@OperationImpl
179-
public OperationHandler<String, String> operation() {
180-
return TemporalOperationHandler.create(
181-
(context, client, input) -> {
182-
// First start should succeed.
183-
client.startActivity(
184-
TestActivity.class,
185-
TestActivity::process,
186-
input,
187-
StartActivityOptions.newBuilder()
188-
.setId("act-first-" + context.getRequestId())
189-
.setTaskQueue(testWorkflowRule.getTaskQueue())
190-
.setStartToCloseTimeout(Duration.ofSeconds(10))
191-
.build());
192-
// Second start must throw HandlerException(BAD_REQUEST).
193-
return client.startActivity(
194-
TestActivity.class,
195-
TestActivity::process,
196-
input,
197-
StartActivityOptions.newBuilder()
198-
.setId("act-second-" + context.getRequestId())
199-
.setTaskQueue(testWorkflowRule.getTaskQueue())
200-
.setStartToCloseTimeout(Duration.ofSeconds(10))
201-
.build());
202-
});
203-
}
204-
}
205103
}

0 commit comments

Comments
 (0)