Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 36 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Run 'gradle checkUpdates' to find out which dependencies have newer versions

plugins {
id 'net.minecrell.licenser' version '0.4.1'
id 'com.github.sherter.google-java-format' version '0.8'
id "net.ltgt.errorprone" version "0.6"
id 'com.github.sherter.google-java-format' version '0.9'
id "net.ltgt.errorprone" version "1.2.1"
id 'name.remal.check-updates' version '1.0.201'
}

apply plugin: 'java'
Expand All @@ -27,16 +30,16 @@ repositories {
}

dependencies {
implementation group: 'io.temporal', name: 'temporal-sdk', version: '0.26.0'
implementation group: 'commons-configuration', name: 'commons-configuration', version: '1.9'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
implementation group: 'io.temporal', name: 'temporal-sdk', version: '0.27.0'
implementation group: 'commons-configuration', name: 'commons-configuration', version: '1.10'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'

testImplementation group: 'junit', name: 'junit', version: '4.12'
testImplementation group: 'junit', name: 'junit', version: '4.13'
testImplementation group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
testImplementation group: 'org.powermock', name: 'powermock-api-mockito', version: '1.7.3'
testImplementation group: 'org.powermock', name: 'powermock-api-mockito', version: '1.7.4'

errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")
errorprone("com.google.errorprone:error_prone_core:2.3.1")
errorprone("com.google.errorprone:error_prone_core:2.4.0")
}

compileJava {
Expand All @@ -51,3 +54,28 @@ task execute(type: JavaExec) {
license {
header rootProject.file('license-header.txt')
}

task runHello {
doLast {
// Cron and Periodic are not in the list as they take long time to stop
["io.temporal.samples.hello.HelloActivity",
"io.temporal.samples.hello.HelloActivityRetry",
"io.temporal.samples.hello.HelloAsync",
"io.temporal.samples.hello.HelloAsyncActivityCompletion",
"io.temporal.samples.hello.HelloAsyncLambda",
"io.temporal.samples.hello.HelloChild",
"io.temporal.samples.hello.HelloException",
"io.temporal.samples.hello.HelloPolymorphicActivity",
"io.temporal.samples.hello.HelloQuery",
"io.temporal.samples.hello.HelloSaga",
"io.temporal.samples.hello.HelloSearchAttributes",
"io.temporal.samples.hello.HelloSignal"
].each { mainClass ->
println mainClass
javaexec {
classpath = sourceSets.main.runtimeClasspath
main = mainClass
}
}
}
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
3 changes: 3 additions & 0 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,50 @@
public interface TripBookingActivities {

/**
* Request a car rental reservation.
*
* @param name customer name
* @return reservationID
*/
String reserveCar(String name);

/**
* Request a flight reservation.
*
* @param name customer name
* @return reservationID
*/
String bookFlight(String name);

/**
* Request a hotel reservation.
*
* @param name customer name
* @return reservationID
*/
String bookHotel(String name);

/**
* Cancel a flight reservation.
*
* @param name customer name
* @param reservationID id returned by bookFlight
* @return cancellationConfirmationID
*/
String cancelFlight(String reservationID, String name);

/**
* Cancel a hotel reservation.
*
* @param name customer name
* @param reservationID id returned by bookHotel
* @return cancellationConfirmationID
*/
String cancelHotel(String reservationID, String name);

/**
* Cancel a car rental reservation.
*
* @param name customer name
* @param reservationID id returned by reserveCar
* @return cancellationConfirmationID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

package io.temporal.samples.common;

import io.temporal.api.common.v1.WorkflowExecution;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowStub;
import io.temporal.common.v1.WorkflowExecution;
import io.temporal.serviceclient.WorkflowServiceStubs;
import java.util.Optional;

Expand All @@ -33,7 +33,7 @@
*/
public class QueryWorkflowExecution {

public static void main(String[] args) throws Exception {
public static void main(String[] args) {
if (args.length < 2 || args.length > 3) {
System.err.println(
"Usage: java "
Expand Down
1 change: 0 additions & 1 deletion src/main/java/io/temporal/samples/hello/HelloActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class HelloActivity {
/** Workflow interface has to have at least one method annotated with @WorkflowMethod. */
@WorkflowInterface
public interface GreetingWorkflow {
/** @return greeting string */
@WorkflowMethod
String getGreeting(String name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class HelloActivityRetry {

@WorkflowInterface
public interface GreetingWorkflow {
/** @return greeting string */
@WorkflowMethod
String getGreeting(String name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public class HelloAsyncActivityCompletion {

@WorkflowInterface
public interface GreetingWorkflow {
/** @return greeting string */
@WorkflowMethod
String getGreeting(String name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class HelloAsyncLambda {

@WorkflowInterface
public interface GreetingWorkflow {
/** @return greeting string */
@WorkflowMethod
String getGreeting(String name);
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/io/temporal/samples/hello/HelloChild.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public class HelloChild {
/** The parent workflow interface. */
@WorkflowInterface
public interface GreetingWorkflow {
/** @return greeting string */
@WorkflowMethod
String getGreeting(String name);
}
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/io/temporal/samples/hello/HelloCron.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import io.temporal.activity.Activity;
import io.temporal.activity.ActivityInterface;
import io.temporal.activity.ActivityOptions;
import io.temporal.api.common.v1.WorkflowExecution;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowExecutionAlreadyStarted;
import io.temporal.client.WorkflowOptions;
import io.temporal.common.v1.WorkflowExecution;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.worker.Worker;
import io.temporal.worker.WorkerFactory;
Expand Down Expand Up @@ -67,12 +67,6 @@ public static class GreetingWorkflowImpl implements GreetingWorkflow {
GreetingActivities.class,
ActivityOptions.newBuilder().setScheduleToCloseTimeout(Duration.ofSeconds(10)).build());

/**
* Stub used to terminate this workflow run and create the next one with the same ID atomically.
*/
private final GreetingWorkflow continueAsNew =
Workflow.newContinueAsNewStub(GreetingWorkflow.class);

@Override
public void greet(String name) {
activities.greet("Hello " + name + "!");
Expand All @@ -87,7 +81,7 @@ public void greet(String greeting) {
}
}

public static void main(String[] args) throws InterruptedException {
public static void main(String[] args) {
// gRPC stubs wrapper that talks to the local docker instance of temporal service.
WorkflowServiceStubs service = WorkflowServiceStubs.newInstance();
// client that can be used to start and signal workflows
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/temporal/samples/hello/HelloPeriodic.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import io.temporal.activity.Activity;
import io.temporal.activity.ActivityInterface;
import io.temporal.activity.ActivityOptions;
import io.temporal.api.common.v1.WorkflowExecution;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowException;
import io.temporal.client.WorkflowExecutionAlreadyStarted;
import io.temporal.client.WorkflowOptions;
import io.temporal.client.WorkflowStub;
import io.temporal.common.v1.WorkflowExecution;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.worker.Worker;
import io.temporal.worker.WorkerFactory;
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/io/temporal/samples/hello/HelloSearchAttributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,24 @@
import io.temporal.activity.ActivityInterface;
import io.temporal.activity.ActivityMethod;
import io.temporal.activity.ActivityOptions;
import io.temporal.api.common.v1.Payload;
import io.temporal.api.common.v1.SearchAttributes;
import io.temporal.api.common.v1.WorkflowExecution;
import io.temporal.api.workflowservice.v1.DescribeWorkflowExecutionRequest;
import io.temporal.api.workflowservice.v1.DescribeWorkflowExecutionResponse;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowOptions;
import io.temporal.common.converter.DataConverter;
import io.temporal.common.v1.Payload;
import io.temporal.common.v1.SearchAttributes;
import io.temporal.common.v1.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 io.temporal.workflowservice.v1.DescribeWorkflowExecutionRequest;
import io.temporal.workflowservice.v1.DescribeWorkflowExecutionResponse;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.Date;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
Expand All @@ -53,7 +54,6 @@ public class HelloSearchAttributes {
/** Workflow interface has to have at least one method annotated with @WorkflowMethod. */
@WorkflowInterface
public interface GreetingWorkflow {
/** @return greeting string */
@WorkflowMethod
String getGreeting(String name);
}
Expand Down Expand Up @@ -161,7 +161,8 @@ private static Map<String, Object> generateSearchAttributes() {

// CustomDatetimeField takes times encoded in the RFC 3339 format.
private static String generateDateTimeFieldValue() {
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").format(new Date());
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX");
return ZonedDateTime.now(ZoneId.systemDefault()).format(formatter);
}

// example for extract value from search attributes
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/temporal/samples/hello/HelloSignal.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public class HelloSignal {
@WorkflowInterface
public interface GreetingWorkflow {
/**
* @return list of greeting strings that were received through the waitForNameMethod. This
* method will block until the number of greetings specified are received.
* list of greeting strings that were received through the waitForNameMethod. This method will
* block until the number of greetings specified are received.
*/
@WorkflowMethod
List<String> getGreetings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import static io.temporal.samples.updatabletimer.DynamicSleepWorkflowWorker.DYNAMIC_SLEEP_WORKFLOW_ID;
import static io.temporal.samples.updatabletimer.DynamicSleepWorkflowWorker.TASK_QUEUE;

import io.temporal.api.common.v1.WorkflowExecution;
import io.temporal.api.enums.v1.WorkflowIdReusePolicy;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowExecutionAlreadyStarted;
import io.temporal.client.WorkflowOptions;
import io.temporal.common.v1.WorkflowExecution;
import io.temporal.enums.v1.WorkflowIdReusePolicy;
import io.temporal.serviceclient.WorkflowServiceStubs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

import io.temporal.workflow.Workflow;
import java.time.Duration;
import java.util.Date;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import org.slf4j.Logger;

public final class UpdatableTimer {
Expand All @@ -32,7 +34,9 @@ public final class UpdatableTimer {
private boolean wakeUpTimeUpdated;

public void sleepUntil(long wakeUpTime) {
logger.info("sleepUntil: " + new Date(wakeUpTime));
Instant wakeUpInstant = Instant.ofEpochMilli(wakeUpTime);
LocalDateTime date = wakeUpInstant.atZone(ZoneId.systemDefault()).toLocalDateTime();
logger.info("sleepUntil: " + date);
this.wakeUpTime = wakeUpTime;
while (true) {
wakeUpTimeUpdated = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.*;

import io.temporal.api.enums.v1.TimeoutType;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowOptions;
import io.temporal.enums.v1.TimeoutType;
import io.temporal.failure.TimeoutFailure;
import io.temporal.samples.fileprocessing.StoreActivities.TaskQueueFileNamePair;
import io.temporal.testing.TestWorkflowEnvironment;
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/io/temporal/samples/hello/HelloChildTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.concurrent.atomic.AtomicReference;
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;
Expand Down Expand Up @@ -89,11 +90,12 @@ public void testChild() {
}

@Test
@Ignore // TODO: Find out how to deal with cglib based mocks
public void testMockedChild() {
worker.registerWorkflowImplementationTypes(GreetingWorkflowImpl.class);
// As new mock is created on each decision the only last one is useful to verify calls.
// As new mock is created on each workflow task the only last one is useful to verify calls.
AtomicReference<GreetingChild> lastChildMock = new AtomicReference<>();
// Factory is called to create a new workflow object on each decision.
// Factory is called to create a new workflow object on each workflow task.
worker.addWorkflowImplementationFactory(
GreetingChild.class,
() -> {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/temporal/samples/hello/HelloCronTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.*;

import io.temporal.api.common.v1.WorkflowExecution;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowOptions;
import io.temporal.common.v1.WorkflowExecution;
import io.temporal.samples.hello.HelloCron.GreetingActivities;
import io.temporal.samples.hello.HelloCron.GreetingWorkflow;
import io.temporal.samples.hello.HelloCron.GreetingWorkflowImpl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;

import io.temporal.api.enums.v1.TimeoutType;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowException;
import io.temporal.client.WorkflowOptions;
import io.temporal.enums.v1.TimeoutType;
import io.temporal.failure.ActivityFailure;
import io.temporal.failure.ApplicationFailure;
import io.temporal.failure.ChildWorkflowFailure;
Expand Down
Loading