diff --git a/build.gradle b/build.gradle index 9c26c30df..556a9d1ea 100644 --- a/build.gradle +++ b/build.gradle @@ -36,7 +36,7 @@ repositories { } dependencies { - compile group: 'io.temporal', name: 'temporal-sdk', version: '0.19.0' + compile group: 'io.temporal', name: 'temporal-sdk', version: '0.23.1' compile group: 'commons-configuration', name: 'commons-configuration', version: '1.9' compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3' diff --git a/src/main/java/io/temporal/samples/bookingsaga/TripBookingSaga.java b/src/main/java/io/temporal/samples/bookingsaga/TripBookingSaga.java index 5f8acb67b..cb42cf1ee 100644 --- a/src/main/java/io/temporal/samples/bookingsaga/TripBookingSaga.java +++ b/src/main/java/io/temporal/samples/bookingsaga/TripBookingSaga.java @@ -21,6 +21,7 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowException; +import io.temporal.client.WorkflowOptions; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; @@ -54,7 +55,8 @@ public static void main(String[] args) { System.out.println("Worker started for task list: " + TASK_LIST); // now we can start running instances of our saga - its state will be persisted - TripBookingWorkflow trip1 = client.newWorkflowStub(TripBookingWorkflow.class); + WorkflowOptions options = WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build(); + TripBookingWorkflow trip1 = client.newWorkflowStub(TripBookingWorkflow.class, options); try { trip1.bookTrip("trip1"); } catch (WorkflowException e) { @@ -62,7 +64,7 @@ public static void main(String[] args) { } try { - TripBookingWorkflow trip2 = client.newWorkflowStub(TripBookingWorkflow.class); + TripBookingWorkflow trip2 = client.newWorkflowStub(TripBookingWorkflow.class, options); trip2.bookTrip("trip2"); } catch (WorkflowException e) { // Expected diff --git a/src/main/java/io/temporal/samples/bookingsaga/TripBookingWorkflow.java b/src/main/java/io/temporal/samples/bookingsaga/TripBookingWorkflow.java index aade23baf..4431cd505 100644 --- a/src/main/java/io/temporal/samples/bookingsaga/TripBookingWorkflow.java +++ b/src/main/java/io/temporal/samples/bookingsaga/TripBookingWorkflow.java @@ -19,14 +19,11 @@ package io.temporal.samples.bookingsaga; -import static io.temporal.samples.bookingsaga.TripBookingSaga.TASK_LIST; - import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; @WorkflowInterface public interface TripBookingWorkflow { - - @WorkflowMethod(executionStartToCloseTimeoutSeconds = 3600, taskList = TASK_LIST) + @WorkflowMethod void bookTrip(String name); } diff --git a/src/main/java/io/temporal/samples/bookingsaga/TripBookingWorkflowImpl.java b/src/main/java/io/temporal/samples/bookingsaga/TripBookingWorkflowImpl.java index 1039c245f..f551b4a32 100644 --- a/src/main/java/io/temporal/samples/bookingsaga/TripBookingWorkflowImpl.java +++ b/src/main/java/io/temporal/samples/bookingsaga/TripBookingWorkflowImpl.java @@ -20,6 +20,7 @@ package io.temporal.samples.bookingsaga; import io.temporal.activity.ActivityOptions; +import io.temporal.common.RetryOptions; import io.temporal.workflow.ActivityException; import io.temporal.workflow.Saga; import io.temporal.workflow.Workflow; @@ -28,7 +29,11 @@ public class TripBookingWorkflowImpl implements TripBookingWorkflow { private final ActivityOptions options = - ActivityOptions.newBuilder().setScheduleToCloseTimeout(Duration.ofHours(1)).build(); + ActivityOptions.newBuilder() + .setScheduleToCloseTimeout(Duration.ofHours(1)) + // disable retries for example to run faster + .setRetryOptions(RetryOptions.newBuilder().setMaximumAttempts(1).build()) + .build(); private final TripBookingActivities activities = Workflow.newActivityStub(TripBookingActivities.class, options); diff --git a/src/main/java/io/temporal/samples/common/QueryWorkflowExecution.java b/src/main/java/io/temporal/samples/common/QueryWorkflowExecution.java index efcb46e7f..eea0b2358 100644 --- a/src/main/java/io/temporal/samples/common/QueryWorkflowExecution.java +++ b/src/main/java/io/temporal/samples/common/QueryWorkflowExecution.java @@ -21,7 +21,7 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowStub; -import io.temporal.proto.execution.WorkflowExecution; +import io.temporal.proto.common.WorkflowExecution; import io.temporal.serviceclient.WorkflowServiceStubs; import java.util.Optional; diff --git a/src/main/java/io/temporal/samples/fileprocessing/FileProcessingStarter.java b/src/main/java/io/temporal/samples/fileprocessing/FileProcessingStarter.java index 61b2f5c97..9bcc607c3 100644 --- a/src/main/java/io/temporal/samples/fileprocessing/FileProcessingStarter.java +++ b/src/main/java/io/temporal/samples/fileprocessing/FileProcessingStarter.java @@ -19,7 +19,10 @@ package io.temporal.samples.fileprocessing; +import static io.temporal.samples.fileprocessing.FileProcessingWorker.TASK_LIST; + import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowOptions; import io.temporal.serviceclient.WorkflowServiceStubs; import java.net.URL; @@ -31,7 +34,10 @@ public static void main(String[] args) throws Exception { WorkflowServiceStubs service = WorkflowServiceStubs.newInstance(); // client that can be used to start and signal workflows WorkflowClient client = WorkflowClient.newInstance(service); - FileProcessingWorkflow workflow = client.newWorkflowStub(FileProcessingWorkflow.class); + FileProcessingWorkflow workflow = + client.newWorkflowStub( + FileProcessingWorkflow.class, + WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build()); System.out.println("Executing FileProcessingWorkflow"); diff --git a/src/main/java/io/temporal/samples/fileprocessing/FileProcessingWorkflow.java b/src/main/java/io/temporal/samples/fileprocessing/FileProcessingWorkflow.java index a97f5656a..e684ac0c7 100644 --- a/src/main/java/io/temporal/samples/fileprocessing/FileProcessingWorkflow.java +++ b/src/main/java/io/temporal/samples/fileprocessing/FileProcessingWorkflow.java @@ -26,10 +26,6 @@ /** Contract for file processing workflow. */ @WorkflowInterface public interface FileProcessingWorkflow { - - @WorkflowMethod( - taskList = FileProcessingWorker.TASK_LIST, - executionStartToCloseTimeoutSeconds = 30 - ) + @WorkflowMethod void processFile(URL source, URL destination); } diff --git a/src/main/java/io/temporal/samples/fileprocessing/FileProcessingWorkflowImpl.java b/src/main/java/io/temporal/samples/fileprocessing/FileProcessingWorkflowImpl.java index 27fb6162b..95145d3dd 100644 --- a/src/main/java/io/temporal/samples/fileprocessing/FileProcessingWorkflowImpl.java +++ b/src/main/java/io/temporal/samples/fileprocessing/FileProcessingWorkflowImpl.java @@ -24,6 +24,7 @@ import io.temporal.workflow.Workflow; import java.net.URL; import java.time.Duration; +import java.util.Optional; /** * This implementation of FileProcessingWorkflow downloads the file, zips it, and uploads it to a @@ -51,12 +52,12 @@ public FileProcessingWorkflowImpl() { @Override public void processFile(URL source, URL destination) { RetryOptions retryOptions = - RetryOptions.newBuilder() - .setExpiration(Duration.ofSeconds(10)) - .setInitialInterval(Duration.ofSeconds(1)) - .build(); + RetryOptions.newBuilder().setInitialInterval(Duration.ofSeconds(1)).build(); // Retries the whole sequence on any failure, potentially on a different host. - Workflow.retry(retryOptions, () -> processFileImpl(source, destination)); + Workflow.retry( + retryOptions, + Optional.of(Duration.ofSeconds(10)), + () -> processFileImpl(source, destination)); } private void processFileImpl(URL source, URL destination) { diff --git a/src/main/java/io/temporal/samples/hello/HelloActivity.java b/src/main/java/io/temporal/samples/hello/HelloActivity.java index b77b51d87..64fff3d53 100644 --- a/src/main/java/io/temporal/samples/hello/HelloActivity.java +++ b/src/main/java/io/temporal/samples/hello/HelloActivity.java @@ -23,6 +23,7 @@ import io.temporal.activity.ActivityMethod; import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowOptions; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; @@ -43,7 +44,7 @@ public class HelloActivity { @WorkflowInterface public interface GreetingWorkflow { /** @return greeting string */ - @WorkflowMethod(executionStartToCloseTimeoutSeconds = 10, taskList = TASK_LIST) + @WorkflowMethod String getGreeting(String name); } @@ -100,7 +101,9 @@ public static void main(String[] args) { // Start a workflow execution. Usually this is done from another program. // Uses task list from the GreetingWorkflow @WorkflowMethod annotation. - GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class); + GreetingWorkflow workflow = + client.newWorkflowStub( + GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build()); // Execute a workflow waiting for it to complete. See {@link // io.temporal.samples.hello.HelloSignal} // for an example of starting workflow without waiting synchronously for its result. diff --git a/src/main/java/io/temporal/samples/hello/HelloActivityRetry.java b/src/main/java/io/temporal/samples/hello/HelloActivityRetry.java index c83b8d8ef..d49c7a731 100644 --- a/src/main/java/io/temporal/samples/hello/HelloActivityRetry.java +++ b/src/main/java/io/temporal/samples/hello/HelloActivityRetry.java @@ -72,7 +72,6 @@ public static class GreetingWorkflowImpl implements GreetingWorkflow { .setRetryOptions( RetryOptions.newBuilder() .setInitialInterval(Duration.ofSeconds(1)) - .setExpiration(Duration.ofMinutes(1)) .setDoNotRetry(IllegalArgumentException.class) .build()) .build()); @@ -122,11 +121,7 @@ public static void main(String[] args) { factory.start(); // Get a workflow stub using the same task list the worker uses. - WorkflowOptions workflowOptions = - WorkflowOptions.newBuilder() - .setTaskList(TASK_LIST) - .setExecutionStartToCloseTimeout(Duration.ofSeconds(30)) - .build(); + WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build(); GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions); // Execute a workflow waiting for it to complete. String greeting = workflow.getGreeting("World"); diff --git a/src/main/java/io/temporal/samples/hello/HelloAsync.java b/src/main/java/io/temporal/samples/hello/HelloAsync.java index 2bff5da4d..51e6d7bb7 100644 --- a/src/main/java/io/temporal/samples/hello/HelloAsync.java +++ b/src/main/java/io/temporal/samples/hello/HelloAsync.java @@ -22,6 +22,7 @@ import io.temporal.activity.ActivityInterface; import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowOptions; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; @@ -43,7 +44,7 @@ public class HelloAsync { @WorkflowInterface public interface GreetingWorkflow { - @WorkflowMethod(executionStartToCloseTimeoutSeconds = 15, taskList = TASK_LIST) + @WorkflowMethod String getGreeting(String name); } @@ -105,7 +106,9 @@ public static void main(String[] args) { // Start a workflow execution. Usually this is done from another program.\n' // Uses task list from the GreetingWorkflow @WorkflowMethod annotation. - GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class); + GreetingWorkflow workflow = + client.newWorkflowStub( + GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build()); // Execute a workflow waiting for it to complete. String greeting = workflow.getGreeting("World"); System.out.println(greeting); diff --git a/src/main/java/io/temporal/samples/hello/HelloAsyncActivityCompletion.java b/src/main/java/io/temporal/samples/hello/HelloAsyncActivityCompletion.java index 37437afb7..668adca41 100644 --- a/src/main/java/io/temporal/samples/hello/HelloAsyncActivityCompletion.java +++ b/src/main/java/io/temporal/samples/hello/HelloAsyncActivityCompletion.java @@ -24,6 +24,7 @@ import io.temporal.activity.ActivityOptions; import io.temporal.client.ActivityCompletionClient; import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowOptions; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; @@ -46,7 +47,7 @@ public class HelloAsyncActivityCompletion { @WorkflowInterface public interface GreetingWorkflow { /** @return greeting string */ - @WorkflowMethod(executionStartToCloseTimeoutSeconds = 15, taskList = TASK_LIST) + @WorkflowMethod String getGreeting(String name); } @@ -129,7 +130,9 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc // Start a workflow execution. Usually this is done from another program. // Uses task list from the GreetingWorkflow @WorkflowMethod annotation. - GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class); + GreetingWorkflow workflow = + client.newWorkflowStub( + GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build()); // Execute a workflow asynchronously returning a future that can be used to wait for the // workflow // completion. diff --git a/src/main/java/io/temporal/samples/hello/HelloAsyncLambda.java b/src/main/java/io/temporal/samples/hello/HelloAsyncLambda.java index fa5c561a6..7dd7a2579 100644 --- a/src/main/java/io/temporal/samples/hello/HelloAsyncLambda.java +++ b/src/main/java/io/temporal/samples/hello/HelloAsyncLambda.java @@ -123,11 +123,7 @@ public static void main(String[] args) { // Get a workflow stub using the same task list the worker uses. // As the required ExecutionStartToCloseTimeout is not specified through the @WorkflowMethod // annotation it has to be specified through the options. - WorkflowOptions workflowOptions = - WorkflowOptions.newBuilder() - .setTaskList(TASK_LIST) - .setExecutionStartToCloseTimeout(Duration.ofSeconds(30)) - .build(); + WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build(); GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions); // Execute a workflow waiting for it to complete. String greeting = workflow.getGreeting("World"); diff --git a/src/main/java/io/temporal/samples/hello/HelloChild.java b/src/main/java/io/temporal/samples/hello/HelloChild.java index a7880cb3b..3c03f07d7 100644 --- a/src/main/java/io/temporal/samples/hello/HelloChild.java +++ b/src/main/java/io/temporal/samples/hello/HelloChild.java @@ -20,6 +20,7 @@ package io.temporal.samples.hello; import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowOptions; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; @@ -40,7 +41,7 @@ public class HelloChild { @WorkflowInterface public interface GreetingWorkflow { /** @return greeting string */ - @WorkflowMethod(executionStartToCloseTimeoutSeconds = 10, taskList = TASK_LIST) + @WorkflowMethod String getGreeting(String name); } @@ -94,7 +95,9 @@ public static void main(String[] args) { // Start a workflow execution. Usually this is done from another program. // Uses task list from the GreetingWorkflow @WorkflowMethod annotation. - GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class); + GreetingWorkflow workflow = + client.newWorkflowStub( + GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build()); // Execute a workflow waiting for it to complete. String greeting = workflow.getGreeting("World"); System.out.println(greeting); diff --git a/src/main/java/io/temporal/samples/hello/HelloCron.java b/src/main/java/io/temporal/samples/hello/HelloCron.java index 13c49d2d8..5bbf4d4cb 100644 --- a/src/main/java/io/temporal/samples/hello/HelloCron.java +++ b/src/main/java/io/temporal/samples/hello/HelloCron.java @@ -25,7 +25,7 @@ import io.temporal.client.DuplicateWorkflowException; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; -import io.temporal.proto.execution.WorkflowExecution; +import io.temporal.proto.common.WorkflowExecution; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; @@ -47,18 +47,7 @@ public class HelloCron { @WorkflowInterface public interface GreetingWorkflow { - /** - * Use single fixed ID to ensure that there is at most one instance running. To run multiple - * instances set different IDs through WorkflowOptions passed to the - * WorkflowClient.newWorkflowStub call. - */ - @WorkflowMethod( - // At most one instance. - workflowId = CRON_WORKFLOW_ID, - // Adjust this value to the maximum time workflow is expected to run. - executionStartToCloseTimeoutSeconds = 300, - taskList = TASK_LIST - ) + @WorkflowMethod void greet(String name); } @@ -118,8 +107,14 @@ public static void main(String[] args) throws InterruptedException { // The cron format is parsed by "https://github.com/robfig/cron" library. // Besides the standard "* * * * *" format it supports @every and other extensions. // Note that unit testing framework doesn't support the extensions. + // Use single fixed ID to ensure that there is at most one instance running. To run multiple + // instances set different IDs. WorkflowOptions workflowOptions = - WorkflowOptions.newBuilder().setCronSchedule("* * * * *").build(); + WorkflowOptions.newBuilder() + .setWorkflowId(CRON_WORKFLOW_ID) + .setTaskList(TASK_LIST) + .setCronSchedule("* * * * *") + .build(); // WorkflowOptions.newBuilder().setCronSchedule("@every 2s").build(); GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions); try { diff --git a/src/main/java/io/temporal/samples/hello/HelloException.java b/src/main/java/io/temporal/samples/hello/HelloException.java index 93157e2bc..3dec3a868 100644 --- a/src/main/java/io/temporal/samples/hello/HelloException.java +++ b/src/main/java/io/temporal/samples/hello/HelloException.java @@ -177,11 +177,7 @@ public static void main(String[] args) { worker.registerActivitiesImplementations(new GreetingActivitiesImpl()); factory.start(); - WorkflowOptions workflowOptions = - WorkflowOptions.newBuilder() - .setTaskList(TASK_LIST) - .setExecutionStartToCloseTimeout(Duration.ofSeconds(30)) - .build(); + WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build(); GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions); try { workflow.getGreeting("World"); diff --git a/src/main/java/io/temporal/samples/hello/HelloPeriodic.java b/src/main/java/io/temporal/samples/hello/HelloPeriodic.java index a17a80f68..b19d8fba9 100644 --- a/src/main/java/io/temporal/samples/hello/HelloPeriodic.java +++ b/src/main/java/io/temporal/samples/hello/HelloPeriodic.java @@ -26,8 +26,9 @@ import io.temporal.client.DuplicateWorkflowException; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowException; +import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; -import io.temporal.proto.execution.WorkflowExecution; +import io.temporal.proto.common.WorkflowExecution; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; @@ -57,14 +58,7 @@ public interface GreetingWorkflow { * instances set different IDs through WorkflowOptions passed to the * WorkflowClient.newWorkflowStub call. */ - @WorkflowMethod( - // At most one instance. - workflowId = PERIODIC_WORKFLOW_ID, - // Adjust this value to the maximum time workflow is expected to run. - // It usually depends on the number of repetitions and interval between them. - executionStartToCloseTimeoutSeconds = 300, - taskList = TASK_LIST - ) + @WorkflowMethod void greetPeriodically(String name); } @@ -149,13 +143,20 @@ public static void main(String[] args) throws InterruptedException { if (execution != null) { WorkflowStub workflow = client.newUntypedWorkflowStub(execution, Optional.empty()); try { - workflow.getResult(Void.class); // + workflow.getResult(Void.class); } catch (WorkflowException e) { System.out.println("Previous instance failed:\n" + Throwables.getStackTraceAsString(e)); } } // New stub instance should be created for each new workflow start. - GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class); + GreetingWorkflow workflow = + client.newWorkflowStub( + GreetingWorkflow.class, + // At most one instance. + WorkflowOptions.newBuilder() + .setWorkflowId(PERIODIC_WORKFLOW_ID) + .setTaskList(TASK_LIST) + .build()); try { execution = WorkflowClient.start(workflow::greetPeriodically, "World"); System.out.println("Started " + execution); diff --git a/src/main/java/io/temporal/samples/hello/HelloQuery.java b/src/main/java/io/temporal/samples/hello/HelloQuery.java index cb93bf828..5d0763f85 100644 --- a/src/main/java/io/temporal/samples/hello/HelloQuery.java +++ b/src/main/java/io/temporal/samples/hello/HelloQuery.java @@ -80,11 +80,7 @@ public static void main(String[] args) throws InterruptedException { factory.start(); // Get a workflow stub using the same task list the worker uses. - WorkflowOptions workflowOptions = - WorkflowOptions.newBuilder() - .setTaskList(TASK_LIST) - .setExecutionStartToCloseTimeout(Duration.ofSeconds(30)) - .build(); + WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build(); GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions); // Start workflow asynchronously to not use another thread to query. WorkflowClient.start(workflow::createGreeting, "World"); diff --git a/src/main/java/io/temporal/samples/hello/HelloSaga.java b/src/main/java/io/temporal/samples/hello/HelloSaga.java index 8379998f2..51e2ee8c3 100644 --- a/src/main/java/io/temporal/samples/hello/HelloSaga.java +++ b/src/main/java/io/temporal/samples/hello/HelloSaga.java @@ -162,11 +162,7 @@ public static void main(String[] args) { factory.start(); // Get a workflow stub using the same task list the worker uses. - WorkflowOptions workflowOptions = - WorkflowOptions.newBuilder() - .setTaskList(TASK_LIST) - .setExecutionStartToCloseTimeout(Duration.ofSeconds(30)) - .build(); + WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build(); HelloSaga.SagaWorkflow workflow = client.newWorkflowStub(HelloSaga.SagaWorkflow.class, workflowOptions); workflow.execute(); diff --git a/src/main/java/io/temporal/samples/hello/HelloSearchAttributes.java b/src/main/java/io/temporal/samples/hello/HelloSearchAttributes.java index dd29d09c7..0767d9fd6 100644 --- a/src/main/java/io/temporal/samples/hello/HelloSearchAttributes.java +++ b/src/main/java/io/temporal/samples/hello/HelloSearchAttributes.java @@ -19,7 +19,6 @@ package io.temporal.samples.hello; -import com.google.protobuf.ByteString; import io.temporal.activity.ActivityInterface; import io.temporal.activity.ActivityMethod; import io.temporal.activity.ActivityOptions; @@ -27,8 +26,9 @@ import io.temporal.client.WorkflowOptions; import io.temporal.common.converter.DataConverter; import io.temporal.common.converter.GsonJsonDataConverter; +import io.temporal.proto.common.Payload; import io.temporal.proto.common.SearchAttributes; -import io.temporal.proto.execution.WorkflowExecution; +import io.temporal.proto.common.WorkflowExecution; import io.temporal.proto.workflowservice.DescribeWorkflowExecutionRequest; import io.temporal.proto.workflowservice.DescribeWorkflowExecutionResponse; import io.temporal.serviceclient.WorkflowServiceStubs; @@ -44,6 +44,9 @@ import java.util.Map; import java.util.UUID; +/** + * TODO(maxim): This sample is broken. https://github.com/temporalio/temporal-java-samples/issues/10 + */ public class HelloSearchAttributes { static final String TASK_LIST = "HelloSearchAttributes"; @@ -52,7 +55,7 @@ public class HelloSearchAttributes { @WorkflowInterface public interface GreetingWorkflow { /** @return greeting string */ - @WorkflowMethod(executionStartToCloseTimeoutSeconds = 10, taskList = TASK_LIST) + @WorkflowMethod String getGreeting(String name); } @@ -167,8 +170,8 @@ private static String generateDateTimeFieldValue() { // example for extract value from search attributes private static String getKeywordFromSearchAttribute(SearchAttributes searchAttributes) { - ByteString field = searchAttributes.getIndexedFieldsOrThrow("CustomKeywordField"); + Payload field = searchAttributes.getIndexedFieldsOrThrow("CustomKeywordField"); DataConverter dataConverter = GsonJsonDataConverter.getInstance(); - return dataConverter.fromData(field.toByteArray(), String.class, String.class); + return dataConverter.getPayloadConverter().fromData(field, String.class, String.class); } } diff --git a/src/main/java/io/temporal/samples/hello/HelloSignal.java b/src/main/java/io/temporal/samples/hello/HelloSignal.java index dc994bb47..91f282ce3 100644 --- a/src/main/java/io/temporal/samples/hello/HelloSignal.java +++ b/src/main/java/io/temporal/samples/hello/HelloSignal.java @@ -28,7 +28,6 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; -import java.time.Duration; import java.util.ArrayList; import java.util.List; import org.apache.commons.lang.RandomStringUtils; @@ -107,11 +106,7 @@ public static void main(String[] args) throws Exception { // Get a workflow stub using the same task list the worker uses. // The newly started workflow is going to have the workflowId generated above. WorkflowOptions workflowOptions = - WorkflowOptions.newBuilder() - .setTaskList(TASK_LIST) - .setExecutionStartToCloseTimeout(Duration.ofSeconds(30)) - .setWorkflowId(workflowId) - .build(); + WorkflowOptions.newBuilder().setTaskList(TASK_LIST).setWorkflowId(workflowId).build(); GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions); // Start workflow asynchronously to not use another thread to signal. WorkflowClient.start(workflow::getGreetings); diff --git a/src/test/java/io/temporal/samples/bookingsaga/TripBookingWorkflowTest.java b/src/test/java/io/temporal/samples/bookingsaga/TripBookingWorkflowTest.java index a1b63f245..5603ae432 100644 --- a/src/test/java/io/temporal/samples/bookingsaga/TripBookingWorkflowTest.java +++ b/src/test/java/io/temporal/samples/bookingsaga/TripBookingWorkflowTest.java @@ -19,15 +19,15 @@ package io.temporal.samples.bookingsaga; +import static io.temporal.samples.bookingsaga.TripBookingSaga.TASK_LIST; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowException; +import io.temporal.client.WorkflowOptions; import io.temporal.testing.TestWorkflowEnvironment; import io.temporal.worker.Worker; import org.junit.After; @@ -43,7 +43,7 @@ public class TripBookingWorkflowTest { @Before public void setUp() { testEnv = TestWorkflowEnvironment.newInstance(); - worker = testEnv.newWorker(TripBookingSaga.TASK_LIST); + worker = testEnv.newWorker(TASK_LIST); worker.registerWorkflowImplementationTypes(TripBookingWorkflowImpl.class); client = testEnv.getWorkflowClient(); @@ -63,7 +63,9 @@ public void testTripBookingFails() { worker.registerActivitiesImplementations(new TripBookingActivitiesImpl()); testEnv.start(); - TripBookingWorkflow workflow = client.newWorkflowStub(TripBookingWorkflow.class); + TripBookingWorkflow workflow = + client.newWorkflowStub( + TripBookingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build()); try { workflow.bookTrip("trip1"); fail("unreachable"); @@ -84,7 +86,9 @@ public void testSAGA() { testEnv.start(); - TripBookingWorkflow workflow = client.newWorkflowStub(TripBookingWorkflow.class); + TripBookingWorkflow workflow = + client.newWorkflowStub( + TripBookingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build()); try { workflow.bookTrip("trip1"); fail("unreachable"); diff --git a/src/test/java/io/temporal/samples/fileprocessing/FileProcessingTest.java b/src/test/java/io/temporal/samples/fileprocessing/FileProcessingTest.java index 20bc43c44..2106af206 100644 --- a/src/test/java/io/temporal/samples/fileprocessing/FileProcessingTest.java +++ b/src/test/java/io/temporal/samples/fileprocessing/FileProcessingTest.java @@ -19,11 +19,13 @@ package io.temporal.samples.fileprocessing; +import static io.temporal.samples.fileprocessing.FileProcessingWorker.TASK_LIST; import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.*; import io.temporal.client.WorkflowClient; -import io.temporal.proto.event.TimeoutType; +import io.temporal.client.WorkflowOptions; +import io.temporal.proto.common.TimeoutType; import io.temporal.samples.fileprocessing.StoreActivities.TaskListFileNamePair; import io.temporal.testing.SimulatedTimeoutException; import io.temporal.testing.TestWorkflowEnvironment; @@ -84,7 +86,7 @@ protected void failed(Throwable e, Description description) { @Before public void setUp() { testEnv = TestWorkflowEnvironment.newInstance(); - worker = testEnv.newWorker(FileProcessingWorker.TASK_LIST); + worker = testEnv.newWorker(TASK_LIST); worker.registerWorkflowImplementationTypes(FileProcessingWorkflowImpl.class); workerHost1 = testEnv.newWorker(HOST_NAME_1); workerHost2 = testEnv.newWorker(HOST_NAME_2); @@ -112,7 +114,10 @@ public void testHappyPath() { workerHost2.registerActivitiesImplementations(activitiesHost2); testEnv.start(); - FileProcessingWorkflow workflow = client.newWorkflowStub(FileProcessingWorkflow.class); + FileProcessingWorkflow workflow = + client.newWorkflowStub( + FileProcessingWorkflow.class, + WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build()); // Execute workflow waiting for completion. workflow.processFile(SOURCE, DESTINATION); @@ -147,13 +152,18 @@ public void testHostFailover() { testEnv.start(); - FileProcessingWorkflow workflow = client.newWorkflowStub(FileProcessingWorkflow.class); + FileProcessingWorkflow workflow = + client.newWorkflowStub( + FileProcessingWorkflow.class, + WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build()); workflow.processFile(SOURCE, DESTINATION); verify(activities, times(2)).download(SOURCE); - verify(activitiesHost1).process(FILE_NAME_UNPROCESSED); + // TODO(maxim): Change to 1, once retry of SimulatedTimeoutException is not happening. + // https://github.com/temporalio/temporal-java-sdk/issues/94 + verify(activitiesHost1, times(4)).process(FILE_NAME_UNPROCESSED); verify(activitiesHost2).process(FILE_NAME_UNPROCESSED); verify(activitiesHost2).upload(FILE_NAME_PROCESSED, DESTINATION); diff --git a/src/test/java/io/temporal/samples/hello/HelloActivityRetryTest.java b/src/test/java/io/temporal/samples/hello/HelloActivityRetryTest.java index 47b60f738..e1e6a8967 100644 --- a/src/test/java/io/temporal/samples/hello/HelloActivityRetryTest.java +++ b/src/test/java/io/temporal/samples/hello/HelloActivityRetryTest.java @@ -21,10 +21,7 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; @@ -34,7 +31,6 @@ import io.temporal.samples.hello.HelloActivityRetry.GreetingWorkflowImpl; import io.temporal.testing.TestWorkflowEnvironment; import io.temporal.worker.Worker; -import java.time.Duration; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -82,10 +78,7 @@ public void testActivityImpl() { testEnv.start(); WorkflowOptions workflowOptions = - WorkflowOptions.newBuilder() - .setTaskList(HelloActivityRetry.TASK_LIST) - .setExecutionStartToCloseTimeout(Duration.ofSeconds(30)) - .build(); + WorkflowOptions.newBuilder().setTaskList(HelloActivityRetry.TASK_LIST).build(); GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions); // Execute a workflow waiting for it to complete. @@ -107,10 +100,7 @@ public void testMockedActivity() { // Get a workflow stub using the same task list the worker uses. WorkflowOptions workflowOptions = - WorkflowOptions.newBuilder() - .setTaskList(HelloActivityRetry.TASK_LIST) - .setExecutionStartToCloseTimeout(Duration.ofSeconds(30)) - .build(); + WorkflowOptions.newBuilder().setTaskList(HelloActivityRetry.TASK_LIST).build(); GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions); // Execute a workflow waiting for it to complete. String greeting = workflow.getGreeting("World"); diff --git a/src/test/java/io/temporal/samples/hello/HelloActivityTest.java b/src/test/java/io/temporal/samples/hello/HelloActivityTest.java index a46ac474d..f931c3b80 100644 --- a/src/test/java/io/temporal/samples/hello/HelloActivityTest.java +++ b/src/test/java/io/temporal/samples/hello/HelloActivityTest.java @@ -19,11 +19,13 @@ package io.temporal.samples.hello; -import static org.junit.Assert.*; +import static io.temporal.samples.hello.HelloActivity.TASK_LIST; +import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowOptions; import io.temporal.samples.hello.HelloActivity.GreetingActivities; import io.temporal.samples.hello.HelloActivity.GreetingActivitiesImpl; import io.temporal.samples.hello.HelloActivity.GreetingWorkflow; @@ -44,7 +46,7 @@ public class HelloActivityTest { @Before public void setUp() { testEnv = TestWorkflowEnvironment.newInstance(); - worker = testEnv.newWorker(HelloActivity.TASK_LIST); + worker = testEnv.newWorker(TASK_LIST); worker.registerWorkflowImplementationTypes(GreetingWorkflowImpl.class); client = testEnv.getWorkflowClient(); @@ -61,7 +63,9 @@ public void testActivityImpl() { testEnv.start(); // Get a workflow stub using the same task list the worker uses. - GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class); + GreetingWorkflow workflow = + client.newWorkflowStub( + GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build()); // Execute a workflow waiting for it to complete. String greeting = workflow.getGreeting("World"); assertEquals("Hello World!", greeting); @@ -75,7 +79,9 @@ public void testMockedActivity() { testEnv.start(); // Get a workflow stub using the same task list the worker uses. - GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class); + GreetingWorkflow workflow = + client.newWorkflowStub( + GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build()); // Execute a workflow waiting for it to complete. String greeting = workflow.getGreeting("World"); assertEquals("Hello World!", greeting); diff --git a/src/test/java/io/temporal/samples/hello/HelloAsyncActivityCompletionTest.java b/src/test/java/io/temporal/samples/hello/HelloAsyncActivityCompletionTest.java index a72a21518..2ec026c1c 100644 --- a/src/test/java/io/temporal/samples/hello/HelloAsyncActivityCompletionTest.java +++ b/src/test/java/io/temporal/samples/hello/HelloAsyncActivityCompletionTest.java @@ -19,10 +19,12 @@ package io.temporal.samples.hello; +import static io.temporal.samples.hello.HelloAsyncActivityCompletion.TASK_LIST; import static org.junit.Assert.assertEquals; import io.temporal.client.ActivityCompletionClient; import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowOptions; import io.temporal.samples.hello.HelloAsyncActivityCompletion.GreetingActivitiesImpl; import io.temporal.samples.hello.HelloAsyncActivityCompletion.GreetingWorkflow; import io.temporal.samples.hello.HelloAsyncActivityCompletion.GreetingWorkflowImpl; @@ -63,7 +65,7 @@ protected void failed(Throwable e, Description description) { @Before public void setUp() { testEnv = TestWorkflowEnvironment.newInstance(); - worker = testEnv.newWorker(HelloAsyncActivityCompletion.TASK_LIST); + worker = testEnv.newWorker(TASK_LIST); worker.registerWorkflowImplementationTypes(GreetingWorkflowImpl.class); client = testEnv.getWorkflowClient(); @@ -80,7 +82,9 @@ public void testActivityImpl() throws ExecutionException, InterruptedException { worker.registerActivitiesImplementations(new GreetingActivitiesImpl(completionClient)); testEnv.start(); - GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class); + GreetingWorkflow workflow = + client.newWorkflowStub( + GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build()); // Execute a workflow asynchronously. CompletableFuture greeting = WorkflowClient.execute(workflow::getGreeting, "World"); // Wait for workflow completion. diff --git a/src/test/java/io/temporal/samples/hello/HelloAsyncLambdaTest.java b/src/test/java/io/temporal/samples/hello/HelloAsyncLambdaTest.java index 461744539..8e1063ca3 100644 --- a/src/test/java/io/temporal/samples/hello/HelloAsyncLambdaTest.java +++ b/src/test/java/io/temporal/samples/hello/HelloAsyncLambdaTest.java @@ -21,10 +21,7 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; @@ -34,7 +31,6 @@ import io.temporal.samples.hello.HelloAsyncLambda.GreetingWorkflowImpl; import io.temporal.testing.TestWorkflowEnvironment; import io.temporal.worker.Worker; -import java.time.Duration; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -86,10 +82,7 @@ public void testActivityImpl() { // Get a workflow stub using the same task list the worker uses. WorkflowOptions workflowOptions = - WorkflowOptions.newBuilder() - .setTaskList(HelloAsyncLambda.TASK_LIST) - .setExecutionStartToCloseTimeout(Duration.ofSeconds(30)) - .build(); + WorkflowOptions.newBuilder().setTaskList(HelloAsyncLambda.TASK_LIST).build(); GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions); // Execute a workflow waiting for it to complete. String greeting = workflow.getGreeting("World"); @@ -105,10 +98,7 @@ public void testMockedActivity() { testEnv.start(); WorkflowOptions workflowOptions = - WorkflowOptions.newBuilder() - .setTaskList(HelloAsyncLambda.TASK_LIST) - .setExecutionStartToCloseTimeout(Duration.ofSeconds(30)) - .build(); + WorkflowOptions.newBuilder().setTaskList(HelloAsyncLambda.TASK_LIST).build(); GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions); // Execute a workflow waiting for it to complete. String greeting = workflow.getGreeting("World"); diff --git a/src/test/java/io/temporal/samples/hello/HelloAsyncTest.java b/src/test/java/io/temporal/samples/hello/HelloAsyncTest.java index af8ea862c..ef1c5023d 100644 --- a/src/test/java/io/temporal/samples/hello/HelloAsyncTest.java +++ b/src/test/java/io/temporal/samples/hello/HelloAsyncTest.java @@ -19,11 +19,13 @@ package io.temporal.samples.hello; +import static io.temporal.samples.hello.HelloAsync.TASK_LIST; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowOptions; import io.temporal.samples.hello.HelloAsync.GreetingActivities; import io.temporal.samples.hello.HelloAsync.GreetingActivitiesImpl; import io.temporal.samples.hello.HelloAsync.GreetingWorkflow; @@ -63,7 +65,7 @@ protected void failed(Throwable e, Description description) { @Before public void setUp() { testEnv = TestWorkflowEnvironment.newInstance(); - worker = testEnv.newWorker(HelloAsync.TASK_LIST); + worker = testEnv.newWorker(TASK_LIST); worker.registerWorkflowImplementationTypes(GreetingWorkflowImpl.class); client = testEnv.getWorkflowClient(); @@ -79,7 +81,9 @@ public void testActivityImpl() { worker.registerActivitiesImplementations(new GreetingActivitiesImpl()); testEnv.start(); - GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class); + GreetingWorkflow workflow = + client.newWorkflowStub( + GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build()); // Execute a workflow waiting for it to complete. String greeting = workflow.getGreeting("World"); assertEquals("Hello World!\nBye World!", greeting); @@ -93,7 +97,9 @@ public void testMockedActivity() { worker.registerActivitiesImplementations(activities); testEnv.start(); - GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class); + GreetingWorkflow workflow = + client.newWorkflowStub( + GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build()); // Execute a workflow waiting for it to complete. String greeting = workflow.getGreeting("World"); assertEquals("Hello World!\nBye World!", greeting); diff --git a/src/test/java/io/temporal/samples/hello/HelloChildTest.java b/src/test/java/io/temporal/samples/hello/HelloChildTest.java index c1cc814a2..99ed02517 100644 --- a/src/test/java/io/temporal/samples/hello/HelloChildTest.java +++ b/src/test/java/io/temporal/samples/hello/HelloChildTest.java @@ -19,13 +19,13 @@ package io.temporal.samples.hello; +import static io.temporal.samples.hello.HelloChild.TASK_LIST; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowOptions; import io.temporal.samples.hello.HelloChild.GreetingChild; import io.temporal.samples.hello.HelloChild.GreetingChildImpl; import io.temporal.samples.hello.HelloChild.GreetingWorkflow; @@ -63,7 +63,7 @@ protected void failed(Throwable e, Description description) { @Before public void setUp() { testEnv = TestWorkflowEnvironment.newInstance(); - worker = testEnv.newWorker(HelloChild.TASK_LIST); + worker = testEnv.newWorker(TASK_LIST); client = testEnv.getWorkflowClient(); } @@ -80,7 +80,9 @@ public void testChild() { testEnv.start(); // Get a workflow stub using the same task list the worker uses. - GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class); + GreetingWorkflow workflow = + client.newWorkflowStub( + GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build()); // Execute a workflow waiting for it to complete. String greeting = workflow.getGreeting("World"); assertEquals("Hello World!", greeting); @@ -103,7 +105,9 @@ public void testMockedChild() { testEnv.start(); // Get a workflow stub using the same task list the worker uses. - GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class); + GreetingWorkflow workflow = + client.newWorkflowStub( + GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build()); // Execute a workflow waiting for it to complete. String greeting = workflow.getGreeting("World"); assertEquals("Hello World!", greeting); diff --git a/src/test/java/io/temporal/samples/hello/HelloCronTest.java b/src/test/java/io/temporal/samples/hello/HelloCronTest.java index ab3c2a110..34eabaa43 100644 --- a/src/test/java/io/temporal/samples/hello/HelloCronTest.java +++ b/src/test/java/io/temporal/samples/hello/HelloCronTest.java @@ -20,13 +20,14 @@ package io.temporal.samples.hello; import static io.temporal.samples.hello.HelloCron.CRON_WORKFLOW_ID; +import static io.temporal.samples.hello.HelloCron.TASK_LIST; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.*; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; -import io.temporal.proto.execution.WorkflowExecution; +import io.temporal.proto.common.WorkflowExecution; import io.temporal.samples.hello.HelloCron.GreetingActivities; import io.temporal.samples.hello.HelloCron.GreetingWorkflow; import io.temporal.samples.hello.HelloCron.GreetingWorkflowImpl; @@ -86,7 +87,11 @@ public void testMockedActivity() { // Unfortunately the supported cron format of the Java test service is not exactly the same as // the temporal service. For example @every is not supported by the unit testing framework. WorkflowOptions workflowOptions = - WorkflowOptions.newBuilder().setCronSchedule("0 * * * *").build(); + WorkflowOptions.newBuilder() + .setCronSchedule("0 * * * *") + .setTaskList(TASK_LIST) + .setWorkflowId(CRON_WORKFLOW_ID) + .build(); GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions); // Execute a workflow waiting for it to complete. diff --git a/src/test/java/io/temporal/samples/hello/HelloExceptionTest.java b/src/test/java/io/temporal/samples/hello/HelloExceptionTest.java index 55061cd47..4b2d9d8d3 100644 --- a/src/test/java/io/temporal/samples/hello/HelloExceptionTest.java +++ b/src/test/java/io/temporal/samples/hello/HelloExceptionTest.java @@ -29,7 +29,7 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowException; import io.temporal.client.WorkflowOptions; -import io.temporal.proto.event.TimeoutType; +import io.temporal.proto.common.TimeoutType; import io.temporal.samples.hello.HelloException.GreetingActivities; import io.temporal.samples.hello.HelloException.GreetingChildImpl; import io.temporal.samples.hello.HelloException.GreetingWorkflow; @@ -42,7 +42,6 @@ import io.temporal.workflow.ChildWorkflowFailureException; import io.temporal.workflow.ChildWorkflowTimedOutException; import java.io.IOException; -import java.time.Duration; import org.junit.After; import org.junit.Before; import org.junit.Ignore; @@ -90,11 +89,7 @@ public void testIOException() { worker.registerActivitiesImplementations(new HelloException.GreetingActivitiesImpl()); testEnv.start(); - WorkflowOptions workflowOptions = - WorkflowOptions.newBuilder() - .setTaskList(TASK_LIST) - .setExecutionStartToCloseTimeout(Duration.ofSeconds(30)) - .build(); + WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build(); GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions); try { workflow.getGreeting("World"); @@ -120,11 +115,7 @@ public void testActivityTimeout() { testEnv.start(); - WorkflowOptions workflowOptions = - WorkflowOptions.newBuilder() - .setTaskList(TASK_LIST) - .setExecutionStartToCloseTimeout(Duration.ofSeconds(30)) - .build(); + WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build(); GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions); try { workflow.getGreeting("World"); @@ -154,11 +145,7 @@ public void testChildWorkflowTimeout() { testEnv.start(); - WorkflowOptions workflowOptions = - WorkflowOptions.newBuilder() - .setTaskList(TASK_LIST) - .setExecutionStartToCloseTimeout(Duration.ofSeconds(30)) - .build(); + WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build(); GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions); try { workflow.getGreeting("World"); diff --git a/src/test/java/io/temporal/samples/hello/HelloPeriodicTest.java b/src/test/java/io/temporal/samples/hello/HelloPeriodicTest.java index 163a28d7f..1bf3f2524 100644 --- a/src/test/java/io/temporal/samples/hello/HelloPeriodicTest.java +++ b/src/test/java/io/temporal/samples/hello/HelloPeriodicTest.java @@ -20,13 +20,15 @@ package io.temporal.samples.hello; import static io.temporal.samples.hello.HelloPeriodic.PERIODIC_WORKFLOW_ID; +import static io.temporal.samples.hello.HelloPeriodic.TASK_LIST; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.*; import io.temporal.client.WorkflowClient; -import io.temporal.proto.execution.WorkflowExecution; +import io.temporal.client.WorkflowOptions; +import io.temporal.proto.common.WorkflowExecution; import io.temporal.proto.execution.WorkflowExecutionInfo; import io.temporal.proto.execution.WorkflowExecutionStatus; import io.temporal.proto.filter.WorkflowExecutionFilter; @@ -72,7 +74,7 @@ protected void failed(Throwable e, Description description) { @Before public void setUp() { testEnv = TestWorkflowEnvironment.newInstance(); - worker = testEnv.newWorker(HelloPeriodic.TASK_LIST); + worker = testEnv.newWorker(TASK_LIST); worker.registerWorkflowImplementationTypes(GreetingWorkflowImpl.class); client = testEnv.getWorkflowClient(); @@ -89,7 +91,13 @@ public void testPeriodicActivityInvocation() { testEnv.start(); // Get a workflow stub using the same task list the worker uses. - GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class); + GreetingWorkflow workflow = + client.newWorkflowStub( + GreetingWorkflow.class, + WorkflowOptions.newBuilder() + .setTaskList(TASK_LIST) + .setWorkflowId(PERIODIC_WORKFLOW_ID) + .build()); // Execute a workflow waiting for it to complete. WorkflowExecution execution = WorkflowClient.start(workflow::greetPeriodically, "World"); assertEquals(PERIODIC_WORKFLOW_ID, execution.getWorkflowId()); @@ -117,7 +125,13 @@ public void testMockedActivity() { testEnv.start(); // Get a workflow stub using the same task list the worker uses. - GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class); + GreetingWorkflow workflow = + client.newWorkflowStub( + GreetingWorkflow.class, + WorkflowOptions.newBuilder() + .setTaskList(TASK_LIST) + .setWorkflowId(PERIODIC_WORKFLOW_ID) + .build()); // Execute a workflow waiting for it to complete. WorkflowExecution execution = WorkflowClient.start(workflow::greetPeriodically, "World"); assertEquals(PERIODIC_WORKFLOW_ID, execution.getWorkflowId()); diff --git a/src/test/java/io/temporal/samples/hello/HelloQueryTest.java b/src/test/java/io/temporal/samples/hello/HelloQueryTest.java index 445a75718..4a08a42fe 100644 --- a/src/test/java/io/temporal/samples/hello/HelloQueryTest.java +++ b/src/test/java/io/temporal/samples/hello/HelloQueryTest.java @@ -78,10 +78,7 @@ public void tearDown() { public void testQuery() { // Get a workflow stub using the same task list the worker uses. WorkflowOptions workflowOptions = - WorkflowOptions.newBuilder() - .setTaskList(HelloQuery.TASK_LIST) - .setExecutionStartToCloseTimeout(Duration.ofSeconds(30)) - .build(); + WorkflowOptions.newBuilder().setTaskList(HelloQuery.TASK_LIST).build(); GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions); // Start workflow asynchronously to not use another thread to query. diff --git a/src/test/java/io/temporal/samples/hello/HelloSignalTest.java b/src/test/java/io/temporal/samples/hello/HelloSignalTest.java index 314adc9e5..93d70721c 100644 --- a/src/test/java/io/temporal/samples/hello/HelloSignalTest.java +++ b/src/test/java/io/temporal/samples/hello/HelloSignalTest.java @@ -79,7 +79,6 @@ public void testSignal() { WorkflowOptions.newBuilder() .setTaskList(HelloSignal.TASK_LIST) .setWorkflowIdReusePolicy(WorkflowIdReusePolicy.RejectDuplicate) - .setExecutionStartToCloseTimeout(Duration.ofDays(30)) .build(); GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions);