From b5f667f580a107618fa8bc88e90b502333cf2b90 Mon Sep 17 00:00:00 2001 From: Maxim Fateev Date: Wed, 1 Apr 2020 16:32:37 -0700 Subject: [PATCH 1/3] Fixes due to proto changes --- build.gradle | 2 +- .../io/temporal/samples/hello/HelloSearchAttributes.java | 2 +- .../java/io/temporal/samples/hello/HelloPeriodicTest.java | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 98591374b..90ab4ee1b 100644 --- a/build.gradle +++ b/build.gradle @@ -36,7 +36,7 @@ repositories { } dependencies { - compile group: 'io.temporal', name: 'temporal-sdk', version: '0.10.0-SNAPSHOT' + compile group: 'io.temporal', name: 'temporal-sdk', version: '0.20.0-SNAPSHOT' 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/hello/HelloSearchAttributes.java b/src/main/java/io/temporal/samples/hello/HelloSearchAttributes.java index f138d9fc8..e49c8b078 100644 --- a/src/main/java/io/temporal/samples/hello/HelloSearchAttributes.java +++ b/src/main/java/io/temporal/samples/hello/HelloSearchAttributes.java @@ -117,7 +117,7 @@ public static void main(String[] args) { DescribeWorkflowExecutionRequest request = DescribeWorkflowExecutionRequest.newBuilder() - .setDomain(client.getOptions().getDomain()) + .setNamespace(client.getOptions().getNamespace()) .setExecution(execution) .build(); try { diff --git a/src/test/java/io/temporal/samples/hello/HelloPeriodicTest.java b/src/test/java/io/temporal/samples/hello/HelloPeriodicTest.java index a9cbfd876..7d9430863 100644 --- a/src/test/java/io/temporal/samples/hello/HelloPeriodicTest.java +++ b/src/test/java/io/temporal/samples/hello/HelloPeriodicTest.java @@ -29,7 +29,7 @@ import io.temporal.proto.common.WorkflowExecution; import io.temporal.proto.common.WorkflowExecutionFilter; import io.temporal.proto.common.WorkflowExecutionInfo; -import io.temporal.proto.enums.WorkflowExecutionCloseStatus; +import io.temporal.proto.enums.WorkflowExecutionStatus; import io.temporal.proto.workflowservice.ListClosedWorkflowExecutionsRequest; import io.temporal.proto.workflowservice.ListClosedWorkflowExecutionsResponse; import io.temporal.samples.hello.HelloPeriodic.GreetingActivities; @@ -98,7 +98,7 @@ public void testPeriodicActivityInvocation() { testEnv.sleep(Duration.ofMinutes(3)); ListClosedWorkflowExecutionsRequest request = ListClosedWorkflowExecutionsRequest.newBuilder() - .setDomain(testEnv.getDomain()) + .setNamespace(testEnv.getNamespace()) .setExecutionFilter( WorkflowExecutionFilter.newBuilder().setWorkflowId(PERIODIC_WORKFLOW_ID)) .build(); @@ -106,9 +106,7 @@ public void testPeriodicActivityInvocation() { testEnv.getWorkflowService().blockingStub().listClosedWorkflowExecutions(request); assertTrue(listResponse.getExecutionsCount() > 1); for (WorkflowExecutionInfo e : listResponse.getExecutionsList()) { - assertEquals( - WorkflowExecutionCloseStatus.WorkflowExecutionCloseStatusContinuedAsNew, - e.getCloseStatus()); + assertEquals(WorkflowExecutionStatus.WorkflowExecutionStatusContinuedAsNew, e.getStatus()); } } From 89da38c9191b158127430a93741bee3d2a8d4ff4 Mon Sep 17 00:00:00 2001 From: Maxim Fateev Date: Tue, 7 Apr 2020 23:02:06 -0700 Subject: [PATCH 2/3] Updated to the latest version of Java library --- build.gradle | 2 +- .../bookingsaga/TripBookingActivities.java | 3 ++ .../bookingsaga/TripBookingWorkflow.java | 2 ++ .../common/QueryWorkflowExecution.java | 2 +- .../FileProcessingWorkflow.java | 2 ++ .../fileprocessing/StoreActivities.java | 2 ++ .../temporal/samples/hello/HelloActivity.java | 12 +++++-- .../samples/hello/HelloActivityRetry.java | 4 +++ .../io/temporal/samples/hello/HelloAsync.java | 12 +++++-- .../hello/HelloAsyncActivityCompletion.java | 12 +++++-- .../samples/hello/HelloAsyncLambda.java | 4 +++ .../io/temporal/samples/hello/HelloChild.java | 3 ++ .../io/temporal/samples/hello/HelloCron.java | 6 +++- .../samples/hello/HelloException.java | 5 +++ .../temporal/samples/hello/HelloPeriodic.java | 6 +++- .../io/temporal/samples/hello/HelloQuery.java | 2 ++ .../io/temporal/samples/hello/HelloSaga.java | 32 +++++++++++++++---- .../samples/hello/HelloSearchAttributes.java | 22 +++++++++---- .../temporal/samples/hello/HelloSignal.java | 2 ++ .../fileprocessing/FileProcessingTest.java | 11 ++----- .../temporal/samples/hello/HelloCronTest.java | 2 +- .../samples/hello/HelloExceptionTest.java | 12 ++++--- .../samples/hello/HelloPeriodicTest.java | 10 +++--- 23 files changed, 126 insertions(+), 44 deletions(-) diff --git a/build.gradle b/build.gradle index 90ab4ee1b..35db779bb 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ googleJavaFormat { } group = 'com.uber' -version = '0.10.0-SNAPSHOT' +version = '0.21.1-SNAPSHOT' description = "Temporal Java SDK Samples" diff --git a/src/main/java/io/temporal/samples/bookingsaga/TripBookingActivities.java b/src/main/java/io/temporal/samples/bookingsaga/TripBookingActivities.java index 98e2c5454..40e2b7909 100644 --- a/src/main/java/io/temporal/samples/bookingsaga/TripBookingActivities.java +++ b/src/main/java/io/temporal/samples/bookingsaga/TripBookingActivities.java @@ -19,6 +19,9 @@ package io.temporal.samples.bookingsaga; +import io.temporal.activity.ActivityInterface; + +@ActivityInterface public interface TripBookingActivities { /** diff --git a/src/main/java/io/temporal/samples/bookingsaga/TripBookingWorkflow.java b/src/main/java/io/temporal/samples/bookingsaga/TripBookingWorkflow.java index 05f76b3d0..aade23baf 100644 --- a/src/main/java/io/temporal/samples/bookingsaga/TripBookingWorkflow.java +++ b/src/main/java/io/temporal/samples/bookingsaga/TripBookingWorkflow.java @@ -21,8 +21,10 @@ 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) diff --git a/src/main/java/io/temporal/samples/common/QueryWorkflowExecution.java b/src/main/java/io/temporal/samples/common/QueryWorkflowExecution.java index eea0b2358..efcb46e7f 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.common.WorkflowExecution; +import io.temporal.proto.execution.WorkflowExecution; import io.temporal.serviceclient.WorkflowServiceStubs; import java.util.Optional; diff --git a/src/main/java/io/temporal/samples/fileprocessing/FileProcessingWorkflow.java b/src/main/java/io/temporal/samples/fileprocessing/FileProcessingWorkflow.java index 0f9407f31..a97f5656a 100644 --- a/src/main/java/io/temporal/samples/fileprocessing/FileProcessingWorkflow.java +++ b/src/main/java/io/temporal/samples/fileprocessing/FileProcessingWorkflow.java @@ -19,10 +19,12 @@ package io.temporal.samples.fileprocessing; +import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; import java.net.URL; /** Contract for file processing workflow. */ +@WorkflowInterface public interface FileProcessingWorkflow { @WorkflowMethod( diff --git a/src/main/java/io/temporal/samples/fileprocessing/StoreActivities.java b/src/main/java/io/temporal/samples/fileprocessing/StoreActivities.java index 7b18a4185..80431d779 100644 --- a/src/main/java/io/temporal/samples/fileprocessing/StoreActivities.java +++ b/src/main/java/io/temporal/samples/fileprocessing/StoreActivities.java @@ -19,8 +19,10 @@ package io.temporal.samples.fileprocessing; +import io.temporal.activity.ActivityInterface; import java.net.URL; +@ActivityInterface public interface StoreActivities { final class TaskListFileNamePair { diff --git a/src/main/java/io/temporal/samples/hello/HelloActivity.java b/src/main/java/io/temporal/samples/hello/HelloActivity.java index 3e74725f3..b77b51d87 100644 --- a/src/main/java/io/temporal/samples/hello/HelloActivity.java +++ b/src/main/java/io/temporal/samples/hello/HelloActivity.java @@ -19,13 +19,17 @@ package io.temporal.samples.hello; +import io.temporal.activity.ActivityInterface; import io.temporal.activity.ActivityMethod; +import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowClient; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.time.Duration; /** * Hello World Temporal workflow that executes a single activity. Requires a local instance the @@ -36,6 +40,7 @@ public class HelloActivity { static final String TASK_LIST = "HelloActivity"; /** Workflow interface has to have at least one method annotated with @WorkflowMethod. */ + @WorkflowInterface public interface GreetingWorkflow { /** @return greeting string */ @WorkflowMethod(executionStartToCloseTimeoutSeconds = 10, taskList = TASK_LIST) @@ -43,8 +48,9 @@ public interface GreetingWorkflow { } /** Activity interface is just a POJI. */ + @ActivityInterface public interface GreetingActivities { - @ActivityMethod(scheduleToCloseTimeoutSeconds = 2) + @ActivityMethod String composeGreeting(String greeting, String name); } @@ -57,7 +63,9 @@ public static class GreetingWorkflowImpl implements GreetingWorkflow { * activity invocations. */ private final GreetingActivities activities = - Workflow.newActivityStub(GreetingActivities.class); + Workflow.newActivityStub( + GreetingActivities.class, + ActivityOptions.newBuilder().setScheduleToCloseTimeout(Duration.ofSeconds(2)).build()); @Override public String getGreeting(String name) { diff --git a/src/main/java/io/temporal/samples/hello/HelloActivityRetry.java b/src/main/java/io/temporal/samples/hello/HelloActivityRetry.java index 3691d841e..c83b8d8ef 100644 --- a/src/main/java/io/temporal/samples/hello/HelloActivityRetry.java +++ b/src/main/java/io/temporal/samples/hello/HelloActivityRetry.java @@ -19,6 +19,7 @@ package io.temporal.samples.hello; +import io.temporal.activity.ActivityInterface; import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; @@ -28,6 +29,7 @@ import io.temporal.worker.WorkerFactory; import io.temporal.workflow.Functions; import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; import java.time.Duration; @@ -39,12 +41,14 @@ public class HelloActivityRetry { static final String TASK_LIST = "HelloActivityRetry"; + @WorkflowInterface public interface GreetingWorkflow { /** @return greeting string */ @WorkflowMethod String getGreeting(String name); } + @ActivityInterface public interface GreetingActivities { String composeGreeting(String greeting, String name); } diff --git a/src/main/java/io/temporal/samples/hello/HelloAsync.java b/src/main/java/io/temporal/samples/hello/HelloAsync.java index e82cedae8..2bff5da4d 100644 --- a/src/main/java/io/temporal/samples/hello/HelloAsync.java +++ b/src/main/java/io/temporal/samples/hello/HelloAsync.java @@ -19,7 +19,8 @@ package io.temporal.samples.hello; -import io.temporal.activity.ActivityMethod; +import io.temporal.activity.ActivityInterface; +import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowClient; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; @@ -28,7 +29,9 @@ import io.temporal.workflow.Functions.Func; import io.temporal.workflow.Promise; import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.time.Duration; /** * Demonstrates asynchronous activity invocation. Requires a local instance of Temporal server to be @@ -38,13 +41,14 @@ public class HelloAsync { static final String TASK_LIST = "HelloAsync"; + @WorkflowInterface public interface GreetingWorkflow { @WorkflowMethod(executionStartToCloseTimeoutSeconds = 15, taskList = TASK_LIST) String getGreeting(String name); } + @ActivityInterface public interface GreetingActivities { - @ActivityMethod(scheduleToCloseTimeoutSeconds = 10) String composeGreeting(String greeting, String name); } @@ -60,7 +64,9 @@ public static class GreetingWorkflowImpl implements GreetingWorkflow { * activity invocations. */ private final GreetingActivities activities = - Workflow.newActivityStub(GreetingActivities.class); + Workflow.newActivityStub( + GreetingActivities.class, + ActivityOptions.newBuilder().setScheduleToCloseTimeout(Duration.ofSeconds(10)).build()); @Override public String getGreeting(String name) { diff --git a/src/main/java/io/temporal/samples/hello/HelloAsyncActivityCompletion.java b/src/main/java/io/temporal/samples/hello/HelloAsyncActivityCompletion.java index 3a20440d0..37437afb7 100644 --- a/src/main/java/io/temporal/samples/hello/HelloAsyncActivityCompletion.java +++ b/src/main/java/io/temporal/samples/hello/HelloAsyncActivityCompletion.java @@ -20,14 +20,17 @@ package io.temporal.samples.hello; import io.temporal.activity.Activity; -import io.temporal.activity.ActivityMethod; +import io.temporal.activity.ActivityInterface; +import io.temporal.activity.ActivityOptions; import io.temporal.client.ActivityCompletionClient; import io.temporal.client.WorkflowClient; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.time.Duration; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.ForkJoinPool; @@ -40,6 +43,7 @@ public class HelloAsyncActivityCompletion { static final String TASK_LIST = "HelloAsyncActivityCompletion"; + @WorkflowInterface public interface GreetingWorkflow { /** @return greeting string */ @WorkflowMethod(executionStartToCloseTimeoutSeconds = 15, taskList = TASK_LIST) @@ -47,8 +51,8 @@ public interface GreetingWorkflow { } /** Activity interface is just a POJI. * */ + @ActivityInterface public interface GreetingActivities { - @ActivityMethod(scheduleToCloseTimeoutSeconds = 10) String composeGreeting(String greeting, String name); } @@ -61,7 +65,9 @@ public static class GreetingWorkflowImpl implements GreetingWorkflow { * activity invocations. */ private final GreetingActivities activities = - Workflow.newActivityStub(GreetingActivities.class); + Workflow.newActivityStub( + GreetingActivities.class, + ActivityOptions.newBuilder().setScheduleToCloseTimeout(Duration.ofSeconds(10)).build()); @Override public String getGreeting(String name) { diff --git a/src/main/java/io/temporal/samples/hello/HelloAsyncLambda.java b/src/main/java/io/temporal/samples/hello/HelloAsyncLambda.java index 5c57046eb..fa5c561a6 100644 --- a/src/main/java/io/temporal/samples/hello/HelloAsyncLambda.java +++ b/src/main/java/io/temporal/samples/hello/HelloAsyncLambda.java @@ -19,6 +19,7 @@ package io.temporal.samples.hello; +import io.temporal.activity.ActivityInterface; import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; @@ -28,6 +29,7 @@ import io.temporal.workflow.Async; import io.temporal.workflow.Promise; import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; import java.time.Duration; @@ -39,6 +41,7 @@ public class HelloAsyncLambda { static final String TASK_LIST = "HelloAsyncLambda"; + @WorkflowInterface public interface GreetingWorkflow { /** @return greeting string */ @WorkflowMethod @@ -46,6 +49,7 @@ public interface GreetingWorkflow { } /** Activity interface is just a POJI. * */ + @ActivityInterface public interface GreetingActivities { String getGreeting(); diff --git a/src/main/java/io/temporal/samples/hello/HelloChild.java b/src/main/java/io/temporal/samples/hello/HelloChild.java index 75206424e..a7880cb3b 100644 --- a/src/main/java/io/temporal/samples/hello/HelloChild.java +++ b/src/main/java/io/temporal/samples/hello/HelloChild.java @@ -26,6 +26,7 @@ import io.temporal.workflow.Async; import io.temporal.workflow.Promise; import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; /** @@ -36,6 +37,7 @@ public class HelloChild { static final String TASK_LIST = "HelloChild"; /** The parent workflow interface. */ + @WorkflowInterface public interface GreetingWorkflow { /** @return greeting string */ @WorkflowMethod(executionStartToCloseTimeoutSeconds = 10, taskList = TASK_LIST) @@ -43,6 +45,7 @@ public interface GreetingWorkflow { } /** The child workflow interface. */ + @WorkflowInterface public interface GreetingChild { @WorkflowMethod String composeGreeting(String greeting, String name); diff --git a/src/main/java/io/temporal/samples/hello/HelloCron.java b/src/main/java/io/temporal/samples/hello/HelloCron.java index b075d2c7b..ff27f98e4 100644 --- a/src/main/java/io/temporal/samples/hello/HelloCron.java +++ b/src/main/java/io/temporal/samples/hello/HelloCron.java @@ -20,15 +20,17 @@ package io.temporal.samples.hello; import io.temporal.activity.Activity; +import io.temporal.activity.ActivityInterface; import io.temporal.activity.ActivityOptions; import io.temporal.client.DuplicateWorkflowException; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; -import io.temporal.proto.common.WorkflowExecution; +import io.temporal.proto.execution.WorkflowExecution; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; import java.time.Duration; @@ -43,6 +45,7 @@ public class HelloCron { static final String TASK_LIST = "HelloCron"; static final String CRON_WORKFLOW_ID = "HelloCron"; + @WorkflowInterface public interface GreetingWorkflow { /** * Use single fixed ID to ensure that there is at most one instance running. To run multiple @@ -59,6 +62,7 @@ public interface GreetingWorkflow { void greet(String name); } + @ActivityInterface public interface GreetingActivities { void greet(String greeting); } diff --git a/src/main/java/io/temporal/samples/hello/HelloException.java b/src/main/java/io/temporal/samples/hello/HelloException.java index 8e5a57244..93157e2bc 100644 --- a/src/main/java/io/temporal/samples/hello/HelloException.java +++ b/src/main/java/io/temporal/samples/hello/HelloException.java @@ -20,6 +20,7 @@ package io.temporal.samples.hello; import com.google.common.base.Throwables; +import io.temporal.activity.ActivityInterface; import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowException; @@ -28,6 +29,7 @@ import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; import java.io.IOException; import java.time.Duration; @@ -107,16 +109,19 @@ public class HelloException { static final String TASK_LIST = "HelloException"; + @WorkflowInterface public interface GreetingWorkflow { @WorkflowMethod String getGreeting(String name); } + @WorkflowInterface public interface GreetingChild { @WorkflowMethod String composeGreeting(String greeting, String name); } + @ActivityInterface public interface GreetingActivities { String composeGreeting(String greeting, String name); } diff --git a/src/main/java/io/temporal/samples/hello/HelloPeriodic.java b/src/main/java/io/temporal/samples/hello/HelloPeriodic.java index 429e8964f..a17a80f68 100644 --- a/src/main/java/io/temporal/samples/hello/HelloPeriodic.java +++ b/src/main/java/io/temporal/samples/hello/HelloPeriodic.java @@ -21,16 +21,18 @@ import com.google.common.base.Throwables; import io.temporal.activity.Activity; +import io.temporal.activity.ActivityInterface; import io.temporal.activity.ActivityOptions; import io.temporal.client.DuplicateWorkflowException; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowException; import io.temporal.client.WorkflowStub; -import io.temporal.proto.common.WorkflowExecution; +import io.temporal.proto.execution.WorkflowExecution; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; import java.time.Duration; import java.util.Optional; @@ -48,6 +50,7 @@ public class HelloPeriodic { static final String TASK_LIST = "HelloPeriodic"; static final String PERIODIC_WORKFLOW_ID = "HelloPeriodic"; + @WorkflowInterface public interface GreetingWorkflow { /** * Use single fixed ID to ensure that there is at most one instance running. To run multiple @@ -65,6 +68,7 @@ public interface GreetingWorkflow { void greetPeriodically(String name); } + @ActivityInterface public interface GreetingActivities { void greet(String greeting); } diff --git a/src/main/java/io/temporal/samples/hello/HelloQuery.java b/src/main/java/io/temporal/samples/hello/HelloQuery.java index 5271f48c5..cb93bf828 100644 --- a/src/main/java/io/temporal/samples/hello/HelloQuery.java +++ b/src/main/java/io/temporal/samples/hello/HelloQuery.java @@ -26,6 +26,7 @@ import io.temporal.worker.WorkerFactory; import io.temporal.workflow.QueryMethod; import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; import java.time.Duration; @@ -34,6 +35,7 @@ public class HelloQuery { static final String TASK_LIST = "HelloQuery"; + @WorkflowInterface public interface GreetingWorkflow { @WorkflowMethod diff --git a/src/main/java/io/temporal/samples/hello/HelloSaga.java b/src/main/java/io/temporal/samples/hello/HelloSaga.java index f8e141f11..8379998f2 100644 --- a/src/main/java/io/temporal/samples/hello/HelloSaga.java +++ b/src/main/java/io/temporal/samples/hello/HelloSaga.java @@ -19,26 +19,37 @@ package io.temporal.samples.hello; +import io.temporal.activity.ActivityInterface; 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; -import io.temporal.workflow.*; +import io.temporal.workflow.Async; +import io.temporal.workflow.Promise; +import io.temporal.workflow.Saga; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; +import io.temporal.workflow.WorkflowMethod; import java.time.Duration; /** Demonstrates implementing saga transaction and compensation logic using Temporal. */ public class HelloSaga { static final String TASK_LIST = "HelloSaga"; + @WorkflowInterface public interface ChildWorkflowOperation { @WorkflowMethod void execute(int amount); } public static class ChildWorkflowOperationImpl implements ChildWorkflowOperation { - ActivityOperation activity = Workflow.newActivityStub(ActivityOperation.class); + ActivityOperation activity = + Workflow.newActivityStub( + ActivityOperation.class, + ActivityOptions.newBuilder().setScheduleToCloseTimeout(Duration.ofSeconds(10)).build()); @Override public void execute(int amount) { @@ -46,13 +57,17 @@ public void execute(int amount) { } } + @WorkflowInterface public interface ChildWorkflowCompensation { @WorkflowMethod void compensate(int amount); } public static class ChildWorkflowCompensationImpl implements ChildWorkflowCompensation { - ActivityOperation activity = Workflow.newActivityStub(ActivityOperation.class); + ActivityOperation activity = + Workflow.newActivityStub( + ActivityOperation.class, + ActivityOptions.newBuilder().setScheduleToCloseTimeout(Duration.ofSeconds(10)).build()); @Override public void compensate(int amount) { @@ -60,11 +75,12 @@ public void compensate(int amount) { } } + @ActivityInterface public interface ActivityOperation { - @ActivityMethod(scheduleToCloseTimeoutSeconds = 2) + @ActivityMethod void execute(int amount); - @ActivityMethod(scheduleToCloseTimeoutSeconds = 2) + @ActivityMethod void compensate(int amount); } @@ -81,6 +97,7 @@ public void compensate(int amount) { } } + @WorkflowInterface public interface SagaWorkflow { /** * Main saga workflow. Here we execute activity operation twice (first from a child workflow, @@ -93,7 +110,10 @@ public interface SagaWorkflow { } public static class SagaWorkflowImpl implements SagaWorkflow { - ActivityOperation activity = Workflow.newActivityStub(ActivityOperation.class); + ActivityOperation activity = + Workflow.newActivityStub( + ActivityOperation.class, + ActivityOptions.newBuilder().setScheduleToCloseTimeout(Duration.ofSeconds(2)).build()); @Override public void execute() { diff --git a/src/main/java/io/temporal/samples/hello/HelloSearchAttributes.java b/src/main/java/io/temporal/samples/hello/HelloSearchAttributes.java index e49c8b078..dd29d09c7 100644 --- a/src/main/java/io/temporal/samples/hello/HelloSearchAttributes.java +++ b/src/main/java/io/temporal/samples/hello/HelloSearchAttributes.java @@ -20,20 +20,24 @@ 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; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.common.converter.DataConverter; -import io.temporal.common.converter.JsonDataConverter; +import io.temporal.common.converter.GsonJsonDataConverter; import io.temporal.proto.common.SearchAttributes; -import io.temporal.proto.common.WorkflowExecution; +import io.temporal.proto.execution.WorkflowExecution; import io.temporal.proto.workflowservice.DescribeWorkflowExecutionRequest; import io.temporal.proto.workflowservice.DescribeWorkflowExecutionResponse; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.time.Duration; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.HashMap; @@ -45,6 +49,7 @@ public class HelloSearchAttributes { static final String TASK_LIST = "HelloSearchAttributes"; /** Workflow interface has to have at least one method annotated with @WorkflowMethod. */ + @WorkflowInterface public interface GreetingWorkflow { /** @return greeting string */ @WorkflowMethod(executionStartToCloseTimeoutSeconds = 10, taskList = TASK_LIST) @@ -52,8 +57,9 @@ public interface GreetingWorkflow { } /** Activity interface is just a POJI. */ + @ActivityInterface public interface GreetingActivities { - @ActivityMethod(scheduleToCloseTimeoutSeconds = 2) + @ActivityMethod String composeGreeting(String greeting, String name); } @@ -65,8 +71,10 @@ public static class GreetingWorkflowImpl implements HelloActivity.GreetingWorkfl * invocations. Because activities are reentrant, only a single stub can be used for multiple * activity invocations. */ - private final HelloActivity.GreetingActivities activities = - Workflow.newActivityStub(HelloActivity.GreetingActivities.class); + private final GreetingActivities activities = + Workflow.newActivityStub( + GreetingActivities.class, + ActivityOptions.newBuilder().setScheduleToCloseTimeout(Duration.ofSeconds(2)).build()); @Override public String getGreeting(String name) { @@ -75,7 +83,7 @@ public String getGreeting(String name) { } } - static class GreetingActivitiesImpl implements HelloActivity.GreetingActivities { + static class GreetingActivitiesImpl implements GreetingActivities { @Override public String composeGreeting(String greeting, String name) { return greeting + " " + name + "!"; @@ -160,7 +168,7 @@ private static String generateDateTimeFieldValue() { // example for extract value from search attributes private static String getKeywordFromSearchAttribute(SearchAttributes searchAttributes) { ByteString field = searchAttributes.getIndexedFieldsOrThrow("CustomKeywordField"); - DataConverter dataConverter = JsonDataConverter.getInstance(); + DataConverter dataConverter = GsonJsonDataConverter.getInstance(); return dataConverter.fromData(field.toByteArray(), 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 b76b7ab9e..dc994bb47 100644 --- a/src/main/java/io/temporal/samples/hello/HelloSignal.java +++ b/src/main/java/io/temporal/samples/hello/HelloSignal.java @@ -26,6 +26,7 @@ import io.temporal.worker.WorkerFactory; import io.temporal.workflow.SignalMethod; import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; import java.time.Duration; import java.util.ArrayList; @@ -42,6 +43,7 @@ public class HelloSignal { static final String TASK_LIST = "HelloSignal"; /** Workflow interface must have a method annotated with @WorkflowMethod. */ + @WorkflowInterface public interface GreetingWorkflow { /** * @return list of greeting strings that were received through the waitForNameMethod. This diff --git a/src/test/java/io/temporal/samples/fileprocessing/FileProcessingTest.java b/src/test/java/io/temporal/samples/fileprocessing/FileProcessingTest.java index 2a922306f..20bc43c44 100644 --- a/src/test/java/io/temporal/samples/fileprocessing/FileProcessingTest.java +++ b/src/test/java/io/temporal/samples/fileprocessing/FileProcessingTest.java @@ -20,15 +20,10 @@ package io.temporal.samples.fileprocessing; import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import io.temporal.client.WorkflowClient; -import io.temporal.proto.enums.TimeoutType; +import io.temporal.proto.event.TimeoutType; import io.temporal.samples.fileprocessing.StoreActivities.TaskListFileNamePair; import io.temporal.testing.SimulatedTimeoutException; import io.temporal.testing.TestWorkflowEnvironment; @@ -142,7 +137,7 @@ public void testHostFailover() { StoreActivities activitiesHost1 = mock(StoreActivities.class); when(activitiesHost1.process(FILE_NAME_UNPROCESSED)) - .thenThrow(new SimulatedTimeoutException(TimeoutType.TimeoutTypeScheduleToStart)); + .thenThrow(new SimulatedTimeoutException(TimeoutType.ScheduleToStart)); workerHost1.registerActivitiesImplementations(activitiesHost1); StoreActivities activitiesHost2 = mock(StoreActivities.class); diff --git a/src/test/java/io/temporal/samples/hello/HelloCronTest.java b/src/test/java/io/temporal/samples/hello/HelloCronTest.java index b9e4e2ecd..ab3c2a110 100644 --- a/src/test/java/io/temporal/samples/hello/HelloCronTest.java +++ b/src/test/java/io/temporal/samples/hello/HelloCronTest.java @@ -26,7 +26,7 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; -import io.temporal.proto.common.WorkflowExecution; +import io.temporal.proto.execution.WorkflowExecution; import io.temporal.samples.hello.HelloCron.GreetingActivities; import io.temporal.samples.hello.HelloCron.GreetingWorkflow; import io.temporal.samples.hello.HelloCron.GreetingWorkflowImpl; diff --git a/src/test/java/io/temporal/samples/hello/HelloExceptionTest.java b/src/test/java/io/temporal/samples/hello/HelloExceptionTest.java index 58a21a578..55061cd47 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.enums.TimeoutType; +import io.temporal.proto.event.TimeoutType; import io.temporal.samples.hello.HelloException.GreetingActivities; import io.temporal.samples.hello.HelloException.GreetingChildImpl; import io.temporal.samples.hello.HelloException.GreetingWorkflow; @@ -45,6 +45,7 @@ import java.time.Duration; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestWatcher; @@ -114,7 +115,7 @@ public void testActivityTimeout() { // Mock an activity that times out. GreetingActivities activities = mock(GreetingActivities.class); when(activities.composeGreeting(anyString(), anyString())) - .thenThrow(new SimulatedTimeoutException(TimeoutType.TimeoutTypeScheduleToStart)); + .thenThrow(new SimulatedTimeoutException(TimeoutType.ScheduleToStart)); worker.registerActivitiesImplementations(activities); testEnv.start(); @@ -133,16 +134,17 @@ public void testActivityTimeout() { Throwable doubleCause = e.getCause().getCause(); assertTrue(doubleCause instanceof ActivityTimeoutException); ActivityTimeoutException timeoutException = (ActivityTimeoutException) doubleCause; - assertEquals(TimeoutType.TimeoutTypeScheduleToStart, timeoutException.getTimeoutType()); + assertEquals(TimeoutType.ScheduleToStart, timeoutException.getTimeoutType()); } } - @Test(timeout = 1000) + @Test(timeout = 100000) + @Ignore // TODO(maxim): Find workaround for mockito breaking reflection public void testChildWorkflowTimeout() { worker.registerWorkflowImplementationTypes(GreetingWorkflowImpl.class); // Mock a child that times out. worker.addWorkflowImplementationFactory( - GreetingChildImpl.class, + HelloException.GreetingChild.class, () -> { GreetingChildImpl child = mock(GreetingChildImpl.class); when(child.composeGreeting(anyString(), anyString())) diff --git a/src/test/java/io/temporal/samples/hello/HelloPeriodicTest.java b/src/test/java/io/temporal/samples/hello/HelloPeriodicTest.java index 7d9430863..163a28d7f 100644 --- a/src/test/java/io/temporal/samples/hello/HelloPeriodicTest.java +++ b/src/test/java/io/temporal/samples/hello/HelloPeriodicTest.java @@ -26,10 +26,10 @@ import static org.mockito.Mockito.*; import io.temporal.client.WorkflowClient; -import io.temporal.proto.common.WorkflowExecution; -import io.temporal.proto.common.WorkflowExecutionFilter; -import io.temporal.proto.common.WorkflowExecutionInfo; -import io.temporal.proto.enums.WorkflowExecutionStatus; +import io.temporal.proto.execution.WorkflowExecution; +import io.temporal.proto.execution.WorkflowExecutionInfo; +import io.temporal.proto.execution.WorkflowExecutionStatus; +import io.temporal.proto.filter.WorkflowExecutionFilter; import io.temporal.proto.workflowservice.ListClosedWorkflowExecutionsRequest; import io.temporal.proto.workflowservice.ListClosedWorkflowExecutionsResponse; import io.temporal.samples.hello.HelloPeriodic.GreetingActivities; @@ -106,7 +106,7 @@ public void testPeriodicActivityInvocation() { testEnv.getWorkflowService().blockingStub().listClosedWorkflowExecutions(request); assertTrue(listResponse.getExecutionsCount() > 1); for (WorkflowExecutionInfo e : listResponse.getExecutionsList()) { - assertEquals(WorkflowExecutionStatus.WorkflowExecutionStatusContinuedAsNew, e.getStatus()); + assertEquals(WorkflowExecutionStatus.ContinuedAsNew, e.getStatus()); } } From fcd859747b87ebda84e4aa2265af4d5e1dbf7a2b Mon Sep 17 00:00:00 2001 From: Maxim Fateev Date: Tue, 7 Apr 2020 23:03:48 -0700 Subject: [PATCH 3/3] reverted version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 35db779bb..4b5c78ed0 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ googleJavaFormat { } group = 'com.uber' -version = '0.21.1-SNAPSHOT' +version = '0.20.0-SNAPSHOT' description = "Temporal Java SDK Samples"