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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public static Builder newBuilder(WorkflowClientOptions options) {
return new Builder(options);
}

public WorkflowClientOptions.Builder toBuilder() {
return new WorkflowClientOptions.Builder(this);
}

public static WorkflowClientOptions getDefaultInstance() {
return DEFAULT_INSTANCE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,16 @@
import static org.junit.Assert.assertFalse;

import io.temporal.workflow.shared.SDKTestWorkflowRule;
import io.temporal.workflow.shared.TestActivities;
import io.temporal.workflow.shared.TestWorkflows;
import java.time.Duration;
import org.junit.Rule;
import org.junit.Test;

public class AwaitTest {

private final TestActivities.TestActivitiesImpl activitiesImpl =
new TestActivities.TestActivitiesImpl(null);

@Rule
public SDKTestWorkflowRule testWorkflowRule =
SDKTestWorkflowRule.newBuilder()
.setWorkflowTypes(TestAwait.class)
.setActivityImplementations(activitiesImpl)
.build();
SDKTestWorkflowRule.newBuilder().setWorkflowTypes(TestAwait.class).build();

@Test
public void testAwait() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (C) 2020 Temporal Technologies, Inc. All Rights Reserved.
*
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Modifications copyright (C) 2017 Uber Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. A copy of the License is
* located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package io.temporal.workflow;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import io.temporal.activity.ActivityOptions;
import io.temporal.api.common.v1.WorkflowExecution;
import io.temporal.api.enums.v1.EventType;
import io.temporal.api.history.v1.History;
import io.temporal.api.history.v1.HistoryEvent;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowClientOptions;
import io.temporal.client.WorkflowStub;
import io.temporal.workflow.shared.*;
import org.junit.Rule;
import org.junit.Test;

public class BinaryChecksumSetWhenTaskCompletedTest {

@Rule
public SDKTestWorkflowRule testWorkflowRule =
SDKTestWorkflowRule.newBuilder()
.setWorkflowClientOptions(
WorkflowClientOptions.newBuilder()
.setBinaryChecksum(SDKTestWorkflowRule.BINARY_CHECKSUM)
.build())
.setWorkflowTypes(SimpleTestWorkflow.class)
.build();

@Test
public void testBinaryChecksumSetWhenTaskCompleted() {
TestWorkflows.TestWorkflow1 client =
testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class);
WorkflowExecution execution =
WorkflowClient.start(client::execute, testWorkflowRule.getTaskQueue());
WorkflowStub stub = WorkflowStub.fromTyped(client);
SDKTestWorkflowRule.waitForOKQuery(stub);
History history = testWorkflowRule.getWorkflowExecutionHistory(execution);

boolean foundCompletedTask = false;
for (HistoryEvent event : history.getEventsList()) {
if (event.getEventType() == EventType.EVENT_TYPE_WORKFLOW_TASK_COMPLETED) {
assertEquals(
SDKTestWorkflowRule.BINARY_CHECKSUM,
event.getWorkflowTaskCompletedEventAttributes().getBinaryChecksum());
foundCompletedTask = true;
}
}
assertTrue(foundCompletedTask);
}

public static class SimpleTestWorkflow implements TestWorkflows.TestWorkflow1 {

@Override
public String execute(String taskQueue) {
TestActivities testActivities =
Workflow.newActivityStub(
TestActivities.class,
ActivityOptions.newBuilder(TestOptions.newActivityOptionsForTaskQueue(taskQueue))
.build());
testActivities.activity();
return "done";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2020 Temporal Technologies, Inc. All Rights Reserved.
*
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Modifications copyright (C) 2017 Uber Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. A copy of the License is
* located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package io.temporal.workflow;

import io.temporal.testing.TracingWorkerInterceptor;
import io.temporal.workflow.shared.SDKTestWorkflowRule;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

public class ContinueAsNewNoArgsTest {

@Rule
public SDKTestWorkflowRule testWorkflowRule =
SDKTestWorkflowRule.newBuilder()
.setWorkflowTypes(TestContinueAsNewNoArgsImpl.class)
.setWorkerInterceptors(
new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace()))
.build();

@Test
public void testContinueAsNewNoArgs() {

NoArgsWorkflow client = testWorkflowRule.newWorkflowStubTimeoutOptions(NoArgsWorkflow.class);
String result = client.execute();
Assert.assertEquals("done", result);
testWorkflowRule
.getInterceptor(TracingWorkerInterceptor.class)
.setExpected(
"interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP,
"newThread workflow-method",
"continueAsNew",
"interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP,
"newThread workflow-method");
}

@WorkflowInterface
public interface NoArgsWorkflow {
@WorkflowMethod
String execute();
}

public static class TestContinueAsNewNoArgsImpl implements NoArgsWorkflow {

@Override
public String execute() {
NoArgsWorkflow next = Workflow.newContinueAsNewStub(NoArgsWorkflow.class);
WorkflowInfo info = Workflow.getInfo();
if (!info.getContinuedExecutionRunId().isPresent()) {
next.execute();
throw new RuntimeException("unreachable");
} else {
return "done";
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright (C) 2020 Temporal Technologies, Inc. All Rights Reserved.
*
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Modifications copyright (C) 2017 Uber Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. A copy of the License is
* located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package io.temporal.workflow;

import static org.junit.Assert.assertEquals;

import io.temporal.testing.TracingWorkerInterceptor;
import io.temporal.workflow.shared.SDKTestWorkflowRule;
import java.util.HashMap;
import java.util.Map;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

public class ContinueAsNewTest {

@Rule
public SDKTestWorkflowRule testWorkflowRule =
SDKTestWorkflowRule.newBuilder()
.setWorkflowTypes(TestContinueAsNewImpl.class)
.setWorkerInterceptors(
new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace()))
.build();

@Test
public void testContinueAsNew() {
TestContinueAsNew client =
testWorkflowRule.newWorkflowStubTimeoutOptions(TestContinueAsNew.class);
int result = client.execute(4, testWorkflowRule.getTaskQueue());
Assert.assertEquals(111, result);
testWorkflowRule
.getInterceptor(TracingWorkerInterceptor.class)
.setExpected(
"interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP,
"newThread workflow-method",
"continueAsNew",
"interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP,
"newThread workflow-method",
"continueAsNew",
"interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP,
"newThread workflow-method",
"continueAsNew",
"interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP,
"newThread workflow-method",
"continueAsNew",
"interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP,
"newThread workflow-method");
}

@WorkflowInterface
public interface TestContinueAsNew {

@WorkflowMethod
int execute(int count, String continueAsNewTaskQueue);
}

public static class TestContinueAsNewImpl implements TestContinueAsNew {

@Override
public int execute(int count, String continueAsNewTaskQueue) {
String taskQueue = Workflow.getInfo().getTaskQueue();
if (count == 0) {
assertEquals(continueAsNewTaskQueue, taskQueue);
return 111;
}
Map<String, Object> memo = new HashMap<>();
memo.put("myKey", "MyValue");
Map<String, Object> searchAttributes = new HashMap<>();
searchAttributes.put("CustomKeywordField", "foo1");
ContinueAsNewOptions options =
ContinueAsNewOptions.newBuilder()
.setTaskQueue(continueAsNewTaskQueue)
.setMemo(memo)
.setSearchAttributes(searchAttributes)
.build();
TestContinueAsNew next = Workflow.newContinueAsNewStub(TestContinueAsNew.class, options);
next.execute(count - 1, continueAsNewTaskQueue);
throw new RuntimeException("unreachable");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright (C) 2020 Temporal Technologies, Inc. All Rights Reserved.
*
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Modifications copyright (C) 2017 Uber Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. A copy of the License is
* located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package io.temporal.workflow;

import static org.junit.Assert.*;

import io.temporal.client.WorkflowFailedException;
import io.temporal.client.WorkflowStub;
import io.temporal.failure.ActivityFailure;
import io.temporal.failure.CanceledFailure;
import io.temporal.workflow.shared.SDKTestWorkflowRule;
import io.temporal.workflow.shared.TestActivities;
import io.temporal.workflow.shared.TestOptions;
import io.temporal.workflow.shared.TestWorkflows;
import java.time.Duration;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

public class DetachedScopeTest {

private final TestActivities.TestActivitiesImpl activitiesImpl =
new TestActivities.TestActivitiesImpl();

@Rule
public SDKTestWorkflowRule testWorkflowRule =
SDKTestWorkflowRule.newBuilder()
.setWorkflowTypes(TestDetachedCancellationScope.class)
.setActivityImplementations(activitiesImpl)
.build();

@Test
public void testDetachedScope() {
WorkflowStub client = testWorkflowRule.newUntypedWorkflowStubTimeoutOptions("TestWorkflow1");
client.start(testWorkflowRule.getTaskQueue());
testWorkflowRule.sleep(Duration.ofMillis(500)); // To let activityWithDelay start.
client.cancel();
try {
client.getResult(String.class);
Assert.fail("unreachable");
} catch (WorkflowFailedException e) {
Assert.assertTrue(e.getCause() instanceof CanceledFailure);
}
activitiesImpl.assertInvocations("activityWithDelay", "activity1", "activity2", "activity3");
}

public static class TestDetachedCancellationScope implements TestWorkflows.TestWorkflow1 {

@Override
public String execute(String taskQueue) {
TestActivities testActivities =
Workflow.newActivityStub(
TestActivities.class, TestOptions.newActivityOptionsForTaskQueue(taskQueue));
try {
testActivities.activityWithDelay(100000, true);
fail("unreachable");
} catch (ActivityFailure e) {
assertTrue(e.getCause() instanceof CanceledFailure);
Workflow.newDetachedCancellationScope(() -> assertEquals(1, testActivities.activity1(1)))
.run();
}
try {
Workflow.sleep(Duration.ofHours(1));
fail("unreachable");
} catch (CanceledFailure e) {
Workflow.newDetachedCancellationScope(
() -> assertEquals("a12", testActivities.activity2("a1", 2)))
.run();
}
try {
Workflow.newTimer(Duration.ofHours(1)).get();
fail("unreachable");
} catch (CanceledFailure e) {
Workflow.newDetachedCancellationScope(
() -> assertEquals("a123", testActivities.activity3("a1", 2, 3)))
.run();
}
return "result";
}
}
}
Loading