Package io.temporal.testing
Class TestWorkflowEnvironmentInternal
- java.lang.Object
-
- io.temporal.testing.TestWorkflowEnvironmentInternal
-
- All Implemented Interfaces:
TestWorkflowEnvironment,java.io.Closeable,java.lang.AutoCloseable
public final class TestWorkflowEnvironmentInternal extends java.lang.Object implements TestWorkflowEnvironment
-
-
Constructor Summary
Constructors Constructor Description TestWorkflowEnvironmentInternal(TestEnvironmentOptions testEnvironmentOptions)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidawaitTermination(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.voidclose()longcurrentTimeMillis()This time might not be equal toSystem.currentTimeMillis()due to time skipping.java.lang.StringgetDiagnostics()Currently prints histories of all workflow instances stored in the service.java.lang.StringgetNamespace()io.temporal.worker.WorkerFactorygetWorkerFactory()io.temporal.client.WorkflowClientgetWorkflowClient()Creates a WorkflowClient that is connected to the in-memory test Temporal service.io.temporal.internal.common.WorkflowExecutionHistorygetWorkflowExecutionHistory(io.temporal.api.common.v1.WorkflowExecution execution)io.temporal.serviceclient.WorkflowServiceStubsgetWorkflowService()Deprecated.io.temporal.serviceclient.WorkflowServiceStubsgetWorkflowServiceStubs()booleanisShutdown()booleanisStarted()WasTestWorkflowEnvironment.start()called?booleanisTerminated()Are all tasks done afterTestWorkflowEnvironment.shutdownNow()orTestWorkflowEnvironment.shutdown()?io.temporal.worker.WorkernewWorker(java.lang.String taskQueue)Creates a new Worker instance that is connected to the in-memory test Temporal service.io.temporal.worker.WorkernewWorker(java.lang.String taskQueue, io.temporal.worker.WorkerOptions options)Creates a new Worker instance that is connected to the in-memory test Temporal service.voidregisterDelayedCallback(java.time.Duration delay, java.lang.Runnable r)Registers a callback to run after the specified delay according to the test Temporal service internal clock.booleanregisterSearchAttribute(java.lang.String name, io.temporal.api.enums.v1.IndexedValueType type)Register a Search Attribute with the server.voidshutdown()Initiates an orderly shutdown in which polls are stopped and already received workflow and activity tasks are executed.voidshutdownNow()Initiates an orderly shutdown in which polls are stopped and already received workflow and activity tasks are attempted to be stopped.voidshutdownTestService()Deprecated.voidsleep(java.time.Duration duration)Wait until internal test Temporal service time passes the specified duration.voidstart()Start all workers created by this factory.
-
-
-
Constructor Detail
-
TestWorkflowEnvironmentInternal
public TestWorkflowEnvironmentInternal(TestEnvironmentOptions testEnvironmentOptions)
-
-
Method Detail
-
newWorker
public io.temporal.worker.Worker newWorker(java.lang.String taskQueue)
Description copied from interface:TestWorkflowEnvironmentCreates a new Worker instance that is connected to the in-memory test Temporal service.- Specified by:
newWorkerin interfaceTestWorkflowEnvironment- Parameters:
taskQueue- task queue to poll.
-
newWorker
public io.temporal.worker.Worker newWorker(java.lang.String taskQueue, io.temporal.worker.WorkerOptions options)Description copied from interface:TestWorkflowEnvironmentCreates a new Worker instance that is connected to the in-memory test Temporal service.- Specified by:
newWorkerin interfaceTestWorkflowEnvironment- Parameters:
taskQueue- task queue to poll.
-
getWorkflowClient
public io.temporal.client.WorkflowClient getWorkflowClient()
Description copied from interface:TestWorkflowEnvironmentCreates a WorkflowClient that is connected to the in-memory test Temporal service.- Specified by:
getWorkflowClientin interfaceTestWorkflowEnvironment
-
currentTimeMillis
public long currentTimeMillis()
Description copied from interface:TestWorkflowEnvironmentThis time might not be equal toSystem.currentTimeMillis()due to time skipping.- Specified by:
currentTimeMillisin interfaceTestWorkflowEnvironment- Returns:
- the current in-memory test Temporal service time in milliseconds or
System.currentTimeMillis()if an external service without time skipping support is used
-
sleep
public void sleep(java.time.Duration duration)
Description copied from interface:TestWorkflowEnvironmentWait until internal test Temporal 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.This method falls back to
Thread.sleep(long)if an external service without time skipping support is used- Specified by:
sleepin interfaceTestWorkflowEnvironment
-
registerDelayedCallback
public void registerDelayedCallback(java.time.Duration delay, java.lang.Runnable r)Description copied from interface:TestWorkflowEnvironmentRegisters a callback to run after the specified delay according to the test Temporal service internal clock.- Specified by:
registerDelayedCallbackin interfaceTestWorkflowEnvironment
-
registerSearchAttribute
public boolean registerSearchAttribute(java.lang.String name, io.temporal.api.enums.v1.IndexedValueType type)Description copied from interface:TestWorkflowEnvironmentRegister a Search Attribute with the server.- Specified by:
registerSearchAttributein interfaceTestWorkflowEnvironment- Parameters:
name- Search Attribute nametype- Search Attribute type to be used for an elastic search index- Returns:
trueif the search attribute was registered, false if it was registered already- See Also:
- Add a Custom Search Attribute Using tctl
-
getWorkflowService
@Deprecated public io.temporal.serviceclient.WorkflowServiceStubs getWorkflowService()
Deprecated.- Specified by:
getWorkflowServicein interfaceTestWorkflowEnvironment- Returns:
- the in-memory test Temporal service that is owned by this.
-
getWorkflowServiceStubs
public io.temporal.serviceclient.WorkflowServiceStubs getWorkflowServiceStubs()
- Specified by:
getWorkflowServiceStubsin interfaceTestWorkflowEnvironment- Returns:
WorkflowServiceStubsconnected to the test server (in-memory or external)
-
getNamespace
public java.lang.String getNamespace()
- Specified by:
getNamespacein interfaceTestWorkflowEnvironment
-
getDiagnostics
public java.lang.String getDiagnostics()
Description copied from interface:TestWorkflowEnvironmentCurrently 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:
getDiagnosticsin interfaceTestWorkflowEnvironment- Returns:
- the diagnostic data about the internal service state.
-
getWorkflowExecutionHistory
public io.temporal.internal.common.WorkflowExecutionHistory getWorkflowExecutionHistory(io.temporal.api.common.v1.WorkflowExecution execution)
- Specified by:
getWorkflowExecutionHistoryin interfaceTestWorkflowEnvironment- Parameters:
execution- identifies the workflowId and runId (optionally) to reach the history for- Returns:
- history of the execution
-
close
public void close()
Description copied from interface:TestWorkflowEnvironmentCallsTestWorkflowEnvironment.shutdownNow()andTestWorkflowEnvironment.awaitTermination(long, TimeUnit).- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceTestWorkflowEnvironment
-
start
public void start()
Description copied from interface:TestWorkflowEnvironmentStart all workers created by this factory.- Specified by:
startin interfaceTestWorkflowEnvironment
-
isStarted
public boolean isStarted()
Description copied from interface:TestWorkflowEnvironmentWasTestWorkflowEnvironment.start()called?- Specified by:
isStartedin interfaceTestWorkflowEnvironment
-
isShutdown
public boolean isShutdown()
Description copied from interface:TestWorkflowEnvironment- Specified by:
isShutdownin interfaceTestWorkflowEnvironment
-
isTerminated
public boolean isTerminated()
Description copied from interface:TestWorkflowEnvironmentAre all tasks done afterTestWorkflowEnvironment.shutdownNow()orTestWorkflowEnvironment.shutdown()?- Specified by:
isTerminatedin interfaceTestWorkflowEnvironment
-
shutdownTestService
@Deprecated public void shutdownTestService()
Deprecated.Description copied from interface:TestWorkflowEnvironmentInitiates Test Service shutdown. This method is temporarily exposed to solve long poll thread shutdown forio.temporal.workflow.interceptorsTests.InterceptorExceptionTests#testExceptionOnStart(). See issue: https://github.com/temporalio/sdk-java/issues/608- Specified by:
shutdownTestServicein interfaceTestWorkflowEnvironment
-
shutdown
public void shutdown()
Description copied from interface:TestWorkflowEnvironmentInitiates an orderly shutdown in which polls are stopped and already received workflow and activity tasks are executed. After the shutdown calls toActivityExecutionContext.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:
shutdownin interfaceTestWorkflowEnvironment
-
shutdownNow
public void shutdownNow()
Description copied from interface:TestWorkflowEnvironmentInitiates an orderly shutdown in which polls are stopped and already received workflow 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 toActivityExecutionContext.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:
shutdownNowin interfaceTestWorkflowEnvironment
-
awaitTermination
public void awaitTermination(long timeout, java.util.concurrent.TimeUnit unit)Description copied from interface:TestWorkflowEnvironmentBlocks 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:
awaitTerminationin interfaceTestWorkflowEnvironment
-
getWorkerFactory
public io.temporal.worker.WorkerFactory getWorkerFactory()
- Specified by:
getWorkerFactoryin interfaceTestWorkflowEnvironment
-
-