Skip to content
Open
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 @@ -77,6 +77,8 @@ public final class POJOWorkflowImplementationFactory implements ReplayWorkflowFa
private Functions.Func1<EncodedValues, ? extends DynamicWorkflow>
dynamicWorkflowImplementationFactory;

@Nullable private WorkflowImplementationOptions dynamicWorkflowImplementationOptions;

private final Map<String, WorkflowImplementationOptions> implementationOptions =
Collections.synchronizedMap(new HashMap<>());

Expand Down Expand Up @@ -136,6 +138,7 @@ public <R> void addWorkflowImplementationFactory(
}
dynamicWorkflowImplementationFactory =
(Functions.Func1<EncodedValues, ? extends DynamicWorkflow>) factory;
dynamicWorkflowImplementationOptions = options;
return;
}
workflowInstanceFactories.put(clazz, factory);
Expand Down Expand Up @@ -213,6 +216,7 @@ private <T> void registerWorkflowImplementationType(
}
}
};
dynamicWorkflowImplementationOptions = options;
return;
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException(
Expand Down Expand Up @@ -285,8 +289,11 @@ private SyncWorkflowDefinition getWorkflowDefinition(
public ReplayWorkflow getWorkflow(
WorkflowType workflowType, WorkflowExecution workflowExecution) {
SyncWorkflowDefinition workflow = getWorkflowDefinition(workflowType, workflowExecution);
boolean isDynamicWorkflow = !workflowDefinitions.containsKey(workflowType.getName());
WorkflowImplementationOptions workflowImplementationOptions =
implementationOptions.get(workflowType.getName());
isDynamicWorkflow
? dynamicWorkflowImplementationOptions
: implementationOptions.get(workflowType.getName());
DataConverter dataConverterWithWorkflowContext =
dataConverter.withContext(
new WorkflowSerializationContext(namespace, workflowExecution.getWorkflowId()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.temporal.workflow;

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

import io.temporal.activity.Activity;
import io.temporal.activity.ActivityOptions;
Expand All @@ -14,6 +13,7 @@
import io.temporal.failure.ApplicationFailure;
import io.temporal.testing.TestWorkflowEnvironment;
import io.temporal.testing.internal.SDKTestWorkflowRule;
import io.temporal.worker.WorkflowImplementationOptions;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -74,6 +74,13 @@ public Object execute(EncodedValues args) {
}
}

public static class FailingDynamicWorkflowImpl implements DynamicWorkflow {
@Override
public Object execute(EncodedValues args) {
throw new NullPointerException("simulated");
}
}

@Test
public void testDynamicWorkflow() {
TestWorkflowEnvironment testEnvironment = testWorkflowRule.getTestEnvironment();
Expand Down Expand Up @@ -124,4 +131,41 @@ public void testDynamicWorkflowFailure() {
workflow.start("startArg0", true /* fail */);
workflow.getResult(String.class);
}

@Test(expected = WorkflowFailedException.class)
public void testDynamicWorkflowFailureTypes() {
TestWorkflowEnvironment testEnvironment = testWorkflowRule.getTestEnvironment();
testEnvironment
.getWorkerFactory()
.getWorker(testWorkflowRule.getTaskQueue())
.registerWorkflowImplementationTypes(
WorkflowImplementationOptions.newBuilder()
.setFailWorkflowExceptionTypes(NullPointerException.class)
.build(),
FailingDynamicWorkflowImpl.class);
testEnvironment.start();

WorkflowStub workflow = testWorkflowRule.newUntypedWorkflowStub("workflowFoo");
workflow.start();
workflow.getResult(String.class);
}

@Test(expected = WorkflowFailedException.class)
public void testDynamicWorkflowFactoryFailureTypes() {
TestWorkflowEnvironment testEnvironment = testWorkflowRule.getTestEnvironment();
testEnvironment
.getWorkerFactory()
.getWorker(testWorkflowRule.getTaskQueue())
.registerWorkflowImplementationFactory(
FailingDynamicWorkflowImpl.class,
FailingDynamicWorkflowImpl::new,
WorkflowImplementationOptions.newBuilder()
.setFailWorkflowExceptionTypes(NullPointerException.class)
.build());
testEnvironment.start();

WorkflowStub workflow = testWorkflowRule.newUntypedWorkflowStub("workflowFoo");
workflow.start();
workflow.getResult(String.class);
}
}
Loading