-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix proto decoding in a Nexus Operation (#2281)
Fix proto decoding in a Nexus Operation
- Loading branch information
1 parent
93e30d7
commit b8c4b7b
Showing
8 changed files
with
329 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
temporal-sdk/src/test/java/io/temporal/workflow/nexus/GenericListOperationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.workflow.nexus; | ||
|
||
import io.nexusrpc.Operation; | ||
import io.nexusrpc.Service; | ||
import io.nexusrpc.handler.OperationHandler; | ||
import io.nexusrpc.handler.OperationImpl; | ||
import io.nexusrpc.handler.ServiceImpl; | ||
import io.temporal.common.converter.EncodedValuesTest; | ||
import io.temporal.nexus.WorkflowClientOperationHandlers; | ||
import io.temporal.testing.internal.SDKTestWorkflowRule; | ||
import io.temporal.workflow.NexusServiceOptions; | ||
import io.temporal.workflow.Workflow; | ||
import io.temporal.workflow.shared.TestWorkflows; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import org.junit.Assert; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
|
||
// Test an operation that takes and returns a List type with a non-primitive element type | ||
public class GenericListOperationTest { | ||
@ClassRule | ||
public static SDKTestWorkflowRule testWorkflowRule = | ||
SDKTestWorkflowRule.newBuilder() | ||
.setWorkflowTypes(TestNexus.class) | ||
.setNexusServiceImplementation(new TestNexusServiceImpl()) | ||
.build(); | ||
|
||
@Test | ||
public void testOperation() { | ||
TestWorkflows.TestWorkflow1 workflowStub = | ||
testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); | ||
String result = workflowStub.execute(testWorkflowRule.getTaskQueue()); | ||
Assert.assertEquals("hello", result); | ||
} | ||
|
||
public static class TestNexus implements TestWorkflows.TestWorkflow1 { | ||
@Override | ||
public String execute(String input) { | ||
NexusServiceOptions serviceOptions = | ||
NexusServiceOptions.newBuilder() | ||
.setEndpoint(testWorkflowRule.getNexusEndpoint().getSpec().getName()) | ||
.build(); | ||
// Try to call with the typed stub | ||
TestNexusService serviceStub = | ||
Workflow.newNexusServiceStub(TestNexusService.class, serviceOptions); | ||
List<EncodedValuesTest.Pair> arg = | ||
Collections.singletonList(new EncodedValuesTest.Pair(1, "hello")); | ||
return serviceStub.operation(arg).get(0).getS(); | ||
} | ||
} | ||
|
||
@Service | ||
public interface TestNexusService { | ||
@Operation | ||
List<EncodedValuesTest.Pair> operation(List<EncodedValuesTest.Pair> input); | ||
} | ||
|
||
@ServiceImpl(service = TestNexusService.class) | ||
public static class TestNexusServiceImpl { | ||
@OperationImpl | ||
public OperationHandler<List<EncodedValuesTest.Pair>, List<EncodedValuesTest.Pair>> | ||
operation() { | ||
return WorkflowClientOperationHandlers.sync( | ||
(context, details, client, input) -> { | ||
return input; | ||
}); | ||
} | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
temporal-sdk/src/test/java/io/temporal/workflow/nexus/ProtoOperationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.workflow.nexus; | ||
|
||
import io.nexusrpc.Operation; | ||
import io.nexusrpc.Service; | ||
import io.nexusrpc.handler.OperationHandler; | ||
import io.nexusrpc.handler.OperationImpl; | ||
import io.nexusrpc.handler.ServiceImpl; | ||
import io.temporal.api.common.v1.WorkflowExecution; | ||
import io.temporal.api.workflowservice.v1.DescribeWorkflowExecutionRequest; | ||
import io.temporal.api.workflowservice.v1.DescribeWorkflowExecutionResponse; | ||
import io.temporal.nexus.WorkflowClientOperationHandlers; | ||
import io.temporal.testing.internal.SDKTestWorkflowRule; | ||
import io.temporal.workflow.*; | ||
import io.temporal.workflow.shared.TestWorkflows; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
// Test an operation that takes and returns a protobuf message | ||
public class ProtoOperationTest { | ||
@Rule | ||
public SDKTestWorkflowRule testWorkflowRule = | ||
SDKTestWorkflowRule.newBuilder() | ||
.setWorkflowTypes(TestNexus.class) | ||
.setNexusServiceImplementation(new TestNexusServiceImpl()) | ||
.build(); | ||
|
||
@Test | ||
public void testDescribeWorkflowOperation() { | ||
TestWorkflows.TestWorkflow1 workflowStub = | ||
testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); | ||
String result = workflowStub.execute(testWorkflowRule.getTaskQueue()); | ||
Assert.assertEquals(testWorkflowRule.getTaskQueue(), result); | ||
} | ||
|
||
public static class TestNexus implements TestWorkflows.TestWorkflow1 { | ||
@Override | ||
public String execute(String input) { | ||
TestNexusService serviceStub = Workflow.newNexusServiceStub(TestNexusService.class); | ||
|
||
WorkflowExecution exec = | ||
WorkflowExecution.newBuilder() | ||
.setWorkflowId(Workflow.getInfo().getWorkflowId()) | ||
.setRunId(Workflow.getInfo().getRunId()) | ||
.build(); | ||
return serviceStub | ||
.describeWorkflow( | ||
DescribeWorkflowExecutionRequest.newBuilder() | ||
.setNamespace(Workflow.getInfo().getNamespace()) | ||
.setExecution(exec) | ||
.build()) | ||
.getExecutionConfig() | ||
.getTaskQueue() | ||
.getName(); | ||
} | ||
} | ||
|
||
@Service | ||
public interface TestNexusService { | ||
@Operation | ||
DescribeWorkflowExecutionResponse describeWorkflow(DescribeWorkflowExecutionRequest input); | ||
} | ||
|
||
@ServiceImpl(service = TestNexusService.class) | ||
public class TestNexusServiceImpl { | ||
@OperationImpl | ||
public OperationHandler<DescribeWorkflowExecutionRequest, DescribeWorkflowExecutionResponse> | ||
describeWorkflow() { | ||
return WorkflowClientOperationHandlers.sync( | ||
(context, details, client, input) -> | ||
client.getWorkflowServiceStubs().blockingStub().describeWorkflowExecution(input)); | ||
} | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
temporal-sdk/src/test/java/io/temporal/workflow/nexus/VoidOperationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.workflow.nexus; | ||
|
||
import io.nexusrpc.Operation; | ||
import io.nexusrpc.Service; | ||
import io.nexusrpc.handler.OperationHandler; | ||
import io.nexusrpc.handler.OperationImpl; | ||
import io.nexusrpc.handler.ServiceImpl; | ||
import io.temporal.nexus.WorkflowClientOperationHandlers; | ||
import io.temporal.testing.internal.SDKTestWorkflowRule; | ||
import io.temporal.workflow.NexusServiceOptions; | ||
import io.temporal.workflow.NexusServiceStub; | ||
import io.temporal.workflow.Workflow; | ||
import io.temporal.workflow.shared.TestWorkflows; | ||
import org.junit.Assert; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
|
||
// Test an operation that takes and returns a void type | ||
public class VoidOperationTest { | ||
@ClassRule | ||
public static SDKTestWorkflowRule testWorkflowRule = | ||
SDKTestWorkflowRule.newBuilder() | ||
.setWorkflowTypes(TestNexus.class) | ||
.setNexusServiceImplementation(new TestNexusServiceImpl()) | ||
.build(); | ||
|
||
@Test | ||
public void testVoidOperation() { | ||
TestWorkflows.TestWorkflow1 workflowStub = | ||
testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class); | ||
String result = workflowStub.execute(testWorkflowRule.getTaskQueue()); | ||
Assert.assertEquals("success", result); | ||
} | ||
|
||
public static class TestNexus implements TestWorkflows.TestWorkflow1 { | ||
@Override | ||
public String execute(String input) { | ||
NexusServiceOptions serviceOptions = | ||
NexusServiceOptions.newBuilder() | ||
.setEndpoint(testWorkflowRule.getNexusEndpoint().getSpec().getName()) | ||
.build(); | ||
// Try to call with the typed stub | ||
TestNexusService serviceStub = | ||
Workflow.newNexusServiceStub(TestNexusService.class, serviceOptions); | ||
serviceStub.noop(); | ||
// Try to call with an untyped stub | ||
NexusServiceStub untypedServiceStub = | ||
Workflow.newUntypedNexusServiceStub("TestNexusService", serviceOptions); | ||
untypedServiceStub.execute("noop", Void.class, null); | ||
untypedServiceStub.execute("noop", Void.class, Void.class, null); | ||
return "success"; | ||
} | ||
} | ||
|
||
@Service | ||
public interface TestNexusService { | ||
@Operation | ||
void noop(); | ||
} | ||
|
||
@ServiceImpl(service = TestNexusService.class) | ||
public static class TestNexusServiceImpl { | ||
@OperationImpl | ||
public OperationHandler<Void, Void> noop() { | ||
return WorkflowClientOperationHandlers.sync((context, details, client, input) -> null); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters