Skip to content

Commit 49bd366

Browse files
Add support for operation timeout header (#2427)
1 parent d0cf3f3 commit 49bd366

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3+
*
4+
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5+
*
6+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this material except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
package io.temporal.workflow.nexus;
22+
23+
import io.nexusrpc.Operation;
24+
import io.nexusrpc.Service;
25+
import io.nexusrpc.handler.OperationHandler;
26+
import io.nexusrpc.handler.OperationImpl;
27+
import io.nexusrpc.handler.ServiceImpl;
28+
import io.temporal.testing.internal.SDKTestWorkflowRule;
29+
import io.temporal.workflow.*;
30+
import java.util.Map;
31+
import org.junit.Assert;
32+
import org.junit.Rule;
33+
import org.junit.Test;
34+
35+
// Test the start operation handler receives the correct headers
36+
public class HeaderTest {
37+
@Rule
38+
public SDKTestWorkflowRule testWorkflowRule =
39+
SDKTestWorkflowRule.newBuilder()
40+
.setWorkflowTypes(TestNexus.class)
41+
.setNexusServiceImplementation(new TestNexusServiceImpl())
42+
.build();
43+
44+
@Test
45+
public void testOperationHeaders() {
46+
TestWorkflow workflowStub = testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflow.class);
47+
Map<String, String> headers = workflowStub.execute(testWorkflowRule.getTaskQueue());
48+
Assert.assertTrue(headers.containsKey("operation-timeout"));
49+
Assert.assertTrue(headers.containsKey("request-timeout"));
50+
}
51+
52+
@WorkflowInterface
53+
public interface TestWorkflow {
54+
@WorkflowMethod
55+
Map<String, String> execute(String arg);
56+
}
57+
58+
public static class TestNexus implements TestWorkflow {
59+
@Override
60+
public Map<String, String> execute(String input) {
61+
// Try to call with the typed stub
62+
TestNexusService serviceStub = Workflow.newNexusServiceStub(TestNexusService.class);
63+
return serviceStub.operation();
64+
}
65+
}
66+
67+
@Service
68+
public interface TestNexusService {
69+
@Operation
70+
Map<String, String> operation();
71+
}
72+
73+
@ServiceImpl(service = TestNexusService.class)
74+
public static class TestNexusServiceImpl {
75+
@OperationImpl
76+
public OperationHandler<Void, Map<String, String>> operation() {
77+
return OperationHandler.sync((context, details, input) -> context.getHeaders());
78+
}
79+
}
80+
}

temporal-test-server/src/main/java/io/temporal/internal/testservice/StateMachines.java

+3
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,9 @@ private static void scheduleNexusOperation(
711711
io.temporal.api.nexus.v1.Request.newBuilder()
712712
.setScheduledTime(ctx.currentTime())
713713
.putAllHeader(attr.getNexusHeaderMap())
714+
.putHeader(
715+
io.nexusrpc.Header.OPERATION_TIMEOUT.toLowerCase(),
716+
attr.getScheduleToCloseTimeout().toString())
714717
.setStartOperation(
715718
StartOperationRequest.newBuilder()
716719
.setService(attr.getService())

temporal-test-server/src/main/java/io/temporal/internal/testservice/TestWorkflowService.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,9 @@ public void pollNexusTaskQueue(
801801
String taskTimeout =
802802
String.valueOf(Timestamps.between(store.currentTime(), task.getDeadline()).getSeconds());
803803
Request.Builder req =
804-
task.getTask().getRequestBuilder().putHeader(Header.REQUEST_TIMEOUT, taskTimeout + "s");
804+
task.getTask()
805+
.getRequestBuilder()
806+
.putHeader(Header.REQUEST_TIMEOUT.toLowerCase(), taskTimeout + "s");
805807
PollNexusTaskQueueResponse.Builder resp = task.getTask().setRequest(req);
806808

807809
responseObserver.onNext(resp.build());

0 commit comments

Comments
 (0)