Package com.uber.cadence.internal.sync
Class TestWorkflowEnvironmentInternal
- java.lang.Object
-
- com.uber.cadence.internal.sync.TestWorkflowEnvironmentInternal
-
- All Implemented Interfaces:
TestWorkflowEnvironment
public final class TestWorkflowEnvironmentInternal extends java.lang.Object implements TestWorkflowEnvironment
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TestWorkflowEnvironmentInternal.WorkflowServiceWrapper
-
Constructor Summary
Constructors Constructor Description TestWorkflowEnvironmentInternal(TestWorkflowEnvironmentInternal.WorkflowServiceWrapper workflowServiceWrapper, TestEnvironmentOptions options)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
awaitTermination(long timeout, java.util.concurrent.TimeUnit unit)
Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.void
close()
long
currentTimeMillis()
Returns the current in-memory test Cadence service time in milliseconds.java.lang.String
getDiagnostics()
Returns the diagnostic data about the internal service state.java.lang.String
getDomain()
WorkerFactory
getWorkerFactory()
IWorkflowService
getWorkflowService()
Returns the in-memory test Cadence service that is owned by this.boolean
isShutdown()
boolean
isStarted()
WasTestWorkflowEnvironment.start()
called?boolean
isTerminated()
Are all tasks done afterTestWorkflowEnvironment.shutdownNow()
orTestWorkflowEnvironment.shutdown()
?Worker
newWorker(java.lang.String taskList)
Creates a new Worker instance that is connected to the in-memory test Cadence service.Worker
newWorker(java.lang.String taskList, java.util.function.Function<WorkerOptions.Builder,WorkerOptions.Builder> overrideOptions)
Creates a new Worker instance that is connected to the in-memory test Cadence service.WorkflowClient
newWorkflowClient()
Creates a WorkflowClient that is connected to the in-memory test Cadence service.WorkflowClient
newWorkflowClient(WorkflowClientOptions options)
Creates a WorkflowClient that is connected to the in-memory test Cadence service.void
registerDelayedCallback(java.time.Duration delay, java.lang.Runnable r)
Registers a callback to run after the specified delay according to the test Cadence service internal clock.void
shutdown()
Initiates an orderly shutdown in which polls are stopped and already received decision and activity tasks are executed.void
shutdownNow()
Initiates an orderly shutdown in which polls are stopped and already received decision and activity tasks are attempted to be stopped.void
sleep(java.time.Duration duration)
Wait until internal test Cadence service time passes the specified duration.void
start()
Start all workers created by this factory.
-
-
-
Constructor Detail
-
TestWorkflowEnvironmentInternal
public TestWorkflowEnvironmentInternal(TestWorkflowEnvironmentInternal.WorkflowServiceWrapper workflowServiceWrapper, TestEnvironmentOptions options)
-
-
Method Detail
-
newWorker
public Worker newWorker(java.lang.String taskList)
Description copied from interface:TestWorkflowEnvironment
Creates a new Worker instance that is connected to the in-memory test Cadence service.- Specified by:
newWorker
in interfaceTestWorkflowEnvironment
- Parameters:
taskList
- task list to poll.
-
newWorker
public Worker newWorker(java.lang.String taskList, java.util.function.Function<WorkerOptions.Builder,WorkerOptions.Builder> overrideOptions)
Description copied from interface:TestWorkflowEnvironment
Creates a new Worker instance that is connected to the in-memory test Cadence service.- Specified by:
newWorker
in interfaceTestWorkflowEnvironment
- Parameters:
taskList
- task list to poll.overrideOptions
- is used to override the default worker options.
-
newWorkflowClient
public WorkflowClient newWorkflowClient()
Description copied from interface:TestWorkflowEnvironment
Creates a WorkflowClient that is connected to the in-memory test Cadence service.- Specified by:
newWorkflowClient
in interfaceTestWorkflowEnvironment
-
newWorkflowClient
public WorkflowClient newWorkflowClient(WorkflowClientOptions options)
Description copied from interface:TestWorkflowEnvironment
Creates a WorkflowClient that is connected to the in-memory test Cadence service.- Specified by:
newWorkflowClient
in interfaceTestWorkflowEnvironment
- Parameters:
options
- options used to configure the client.
-
currentTimeMillis
public long currentTimeMillis()
Description copied from interface:TestWorkflowEnvironment
Returns the current in-memory test Cadence service time in milliseconds. This time might not be equal toSystem.currentTimeMillis()
due to time skipping.- Specified by:
currentTimeMillis
in interfaceTestWorkflowEnvironment
-
sleep
public void sleep(java.time.Duration duration)
Description copied from interface:TestWorkflowEnvironment
Wait until internal test Cadence service time passes the specified duration. This call also indicates that workflow time might jump forward (if none of the activities are running) up to the specified duration.- Specified by:
sleep
in interfaceTestWorkflowEnvironment
-
registerDelayedCallback
public void registerDelayedCallback(java.time.Duration delay, java.lang.Runnable r)
Description copied from interface:TestWorkflowEnvironment
Registers a callback to run after the specified delay according to the test Cadence service internal clock.- Specified by:
registerDelayedCallback
in interfaceTestWorkflowEnvironment
-
getWorkflowService
public IWorkflowService getWorkflowService()
Description copied from interface:TestWorkflowEnvironment
Returns the in-memory test Cadence service that is owned by this.- Specified by:
getWorkflowService
in interfaceTestWorkflowEnvironment
-
getDomain
public java.lang.String getDomain()
- Specified by:
getDomain
in interfaceTestWorkflowEnvironment
-
getDiagnostics
public java.lang.String getDiagnostics()
Description copied from interface:TestWorkflowEnvironment
Returns the diagnostic data about the internal service state. Currently prints histories of all workflow instances stored in the service. This is useful information to print in the case of a unit test failure. A convenient way to achieve this is to add the following Rule to a unit test:@Rule public TestWatcher watchman = new TestWatcher() { @Override protected void failed(Throwable e, Description description) { System.err.println(testEnvironment.getDiagnostics()); testEnvironment.close(); } };
- Specified by:
getDiagnostics
in interfaceTestWorkflowEnvironment
-
close
public void close()
Description copied from interface:TestWorkflowEnvironment
CallsTestWorkflowEnvironment.shutdownNow()
andTestWorkflowEnvironment.awaitTermination(long, TimeUnit)
.- Specified by:
close
in interfaceTestWorkflowEnvironment
-
start
public void start()
Description copied from interface:TestWorkflowEnvironment
Start all workers created by this factory.- Specified by:
start
in interfaceTestWorkflowEnvironment
-
isStarted
public boolean isStarted()
Description copied from interface:TestWorkflowEnvironment
WasTestWorkflowEnvironment.start()
called?- Specified by:
isStarted
in interfaceTestWorkflowEnvironment
-
isShutdown
public boolean isShutdown()
Description copied from interface:TestWorkflowEnvironment
- Specified by:
isShutdown
in interfaceTestWorkflowEnvironment
-
isTerminated
public boolean isTerminated()
Description copied from interface:TestWorkflowEnvironment
Are all tasks done afterTestWorkflowEnvironment.shutdownNow()
orTestWorkflowEnvironment.shutdown()
?- Specified by:
isTerminated
in interfaceTestWorkflowEnvironment
-
shutdown
public void shutdown()
Description copied from interface:TestWorkflowEnvironment
Initiates an orderly shutdown in which polls are stopped and already received decision and activity tasks are executed. After the shutdown calls toActivity.heartbeat(Object)
start throwingActivityWorkerShutdownException
. Invocation has no additional effect if already shut down. This method does not wait for previously received tasks to complete execution. UseTestWorkflowEnvironment.awaitTermination(long, TimeUnit)
to do that.- Specified by:
shutdown
in interfaceTestWorkflowEnvironment
-
shutdownNow
public void shutdownNow()
Description copied from interface:TestWorkflowEnvironment
Initiates an orderly shutdown in which polls are stopped and already received decision and activity tasks are attempted to be stopped. This implementation cancels tasks via Thread.interrupt(), so any task that fails to respond to interrupts may never terminate. Also after the shutdownNow calls toActivity.heartbeat(Object)
start throwingActivityWorkerShutdownException
. Invocation has no additional effect if already shut down. This method does not wait for previously received tasks to complete execution. UseTestWorkflowEnvironment.awaitTermination(long, TimeUnit)
to do that.- Specified by:
shutdownNow
in interfaceTestWorkflowEnvironment
-
awaitTermination
public void awaitTermination(long timeout, java.util.concurrent.TimeUnit unit)
Description copied from interface:TestWorkflowEnvironment
Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.- Specified by:
awaitTermination
in interfaceTestWorkflowEnvironment
-
getWorkerFactory
public WorkerFactory getWorkerFactory()
- Specified by:
getWorkerFactory
in interfaceTestWorkflowEnvironment
-
-