diff --git a/build.gradle b/build.gradle index eaf29032..0f03ee0a 100644 --- a/build.gradle +++ b/build.gradle @@ -28,14 +28,13 @@ subprojects { ext { otelVersion = '1.30.1' otelVersionAlpha = "${otelVersion}-alpha" - javaSDKVersion = '1.23.0-SNAPSHOT' + javaSDKVersion = '1.26.0' camelVersion = '3.22.1' jarVersion = '1.0.0' nexusVersion = '0.1.0-alpha1' } repositories { - mavenLocal() maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } diff --git a/core/src/main/java/io/temporal/samples/nexus/caller/EchoCallerWorkflowImpl.java b/core/src/main/java/io/temporal/samples/nexus/caller/EchoCallerWorkflowImpl.java index ea084ca1..7c5d5f78 100644 --- a/core/src/main/java/io/temporal/samples/nexus/caller/EchoCallerWorkflowImpl.java +++ b/core/src/main/java/io/temporal/samples/nexus/caller/EchoCallerWorkflowImpl.java @@ -20,10 +20,21 @@ package io.temporal.samples.nexus.caller; import io.temporal.samples.nexus.service.NexusService; +import io.temporal.workflow.NexusOperationOptions; +import io.temporal.workflow.NexusServiceOptions; import io.temporal.workflow.Workflow; +import java.time.Duration; public class EchoCallerWorkflowImpl implements EchoCallerWorkflow { - NexusService nexusService = Workflow.newNexusServiceStub(NexusService.class); + NexusService nexusService = + Workflow.newNexusServiceStub( + NexusService.class, + NexusServiceOptions.newBuilder() + .setOperationOptions( + NexusOperationOptions.newBuilder() + .setScheduleToCloseTimeout(Duration.ofSeconds(10)) + .build()) + .build()); @Override public String echo(String message) { diff --git a/core/src/test/java/io/temporal/samples/nexus/caller/CallerWorkflowTest.java b/core/src/test/java/io/temporal/samples/nexus/caller/CallerWorkflowTest.java index 9af08174..97dfd2ef 100644 --- a/core/src/test/java/io/temporal/samples/nexus/caller/CallerWorkflowTest.java +++ b/core/src/test/java/io/temporal/samples/nexus/caller/CallerWorkflowTest.java @@ -29,6 +29,8 @@ import org.junit.Rule; import org.junit.Test; +import java.util.Collections; + import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -44,6 +46,8 @@ public class CallerWorkflowTest { // of the TestWorkflowRule will automatically inherit the endpoint if none is set. .setNexusServiceImplementation(new NexusServiceImpl()) .setWorkflowTypes(HelloCallerWorkflowImpl.class) + // Disable automatic worker startup as we are going to register some workflows manually + // per test .setDoNotStart(true) .build(); @@ -51,6 +55,7 @@ public class CallerWorkflowTest { public void testHelloWorkflow() { testWorkflowRule .getWorker() + // Workflows started by a Nexus service can be mocked just like any other workflow .registerWorkflowImplementationFactory( HelloHandlerWorkflow.class, () -> { @@ -74,14 +79,19 @@ public void testHelloWorkflow() { @Test public void testEchoWorkflow() { + // If Workflows are registered later than the endpoint can be set manually + // either by setting the endpoint in the NexusServiceOptions in the Workflow implementation or by setting the + // NexusServiceOptions on the WorkflowImplementationOptions when registering the Workflow. testWorkflowRule .getWorker() .registerWorkflowImplementationTypes( WorkflowImplementationOptions.newBuilder() - .setDefaultNexusServiceOptions( - NexusServiceOptions.newBuilder() - .setEndpoint(testWorkflowRule.getNexusEndpoint().getSpec().getName()) - .build()) + .setNexusServiceOptions( + Collections.singletonMap( + "NexusService", + NexusServiceOptions.newBuilder() + .setEndpoint(testWorkflowRule.getNexusEndpoint().getSpec().getName()) + .build())) .build(), EchoCallerWorkflowImpl.class); testWorkflowRule.getTestEnvironment().start();