Class SDKTestWorkflowRule

  • All Implemented Interfaces:
    org.junit.rules.TestRule

    public class SDKTestWorkflowRule
    extends java.lang.Object
    implements org.junit.rules.TestRule
    Intended to be used only in the Java SDK test code. This Rule duplicates TestWorkflowRule and provides additional convenience methods for SDK development
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <R> void addWorkflowImplementationFactory​(java.lang.Class<R> factoryImpl, io.temporal.workflow.Functions.Func<R> factoryFunc)  
      org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base, org.junit.runner.Description description)  
      void assertHistoryEvent​(java.lang.String workflowId, io.temporal.api.enums.v1.EventType eventType)
      Asserts that an event of the given EventType is found in the history.
      void assertHistoryEvent​(java.lang.String workflowId, java.lang.String runId, io.temporal.api.enums.v1.EventType eventType)  
      static void assertNoHistoryEvent​(io.temporal.api.history.v1.History history, io.temporal.api.enums.v1.EventType eventType)
      Asserts that an event of the given EventType is not found in the history.
      void assertNoHistoryEvent​(java.lang.String workflowId, io.temporal.api.enums.v1.EventType eventType)
      Asserts that an event of the given EventType is not found in the history.
      void assertNoHistoryEvent​(java.lang.String workflowId, java.lang.String runId, io.temporal.api.enums.v1.EventType eventType)
      Asserts that an event of the given EventType is not found in the history.
      java.lang.String getDeploymentName()  
      io.temporal.common.WorkflowExecutionHistory getExecutionHistory​(java.lang.String workflowId)  
      io.temporal.common.WorkflowExecutionHistory getExecutionHistory​(java.lang.String workflowId, java.lang.String runId)  
      io.temporal.api.history.v1.HistoryEvent getHistoryEvent​(java.lang.String workflowId, io.temporal.api.enums.v1.EventType eventType)
      Returns the first event of the given EventType found in the history.
      java.util.List<io.temporal.api.history.v1.HistoryEvent> getHistoryEvents​(java.lang.String workflowId, io.temporal.api.enums.v1.EventType eventType)
      Returns list of all events of the given EventType found in the history.
      <T extends io.temporal.common.interceptors.WorkerInterceptor>
      T
      getInterceptor​(java.lang.Class<T> type)  
      io.temporal.api.nexus.v1.Endpoint getNexusEndpoint()  
      java.lang.String getTaskQueue()  
      TestWorkflowEnvironment getTestEnvironment()  
      io.temporal.worker.Worker getWorker()  
      io.temporal.worker.WorkerFactoryOptions getWorkerFactoryOptions()  
      io.temporal.client.WorkflowClient getWorkflowClient()  
      io.temporal.serviceclient.WorkflowServiceStubs getWorkflowServiceStubs()  
      void invalidateWorkflowCache()
      Causes eviction of all workflows in the worker cache
      boolean isUseExternalService()  
      static SDKTestWorkflowRule.Builder newBuilder()  
      io.temporal.client.WorkflowStub newUntypedWorkflowStub​(java.lang.String workflow)  
      io.temporal.client.WorkflowStub newUntypedWorkflowStubTimeoutOptions​(java.lang.String workflow)  
      io.temporal.worker.Worker newWorker​(io.temporal.workflow.Functions.Proc1<io.temporal.worker.WorkerOptions.Builder> optionsModifier)
      Start a new worker, re-using existing options and modifying them with the provided modifier
      io.temporal.worker.Worker newWorkerWithBuildID​(java.lang.String buildId)
      Start a new worker, changing only the build ID
      <T> T newWorkflowStub​(java.lang.Class<T> workflow)  
      <T> T newWorkflowStub200sTimeoutOptions​(java.lang.Class<T> workflow)  
      <T> T newWorkflowStubTimeoutOptions​(java.lang.Class<T> workflow)  
      <T> T newWorkflowStubTimeoutOptions​(java.lang.Class<T> workflow, java.lang.String workflowIdPrefix)  
      void regenerateHistoryForReplay​(java.lang.String workflowId, java.lang.String fileName)  
      void registerDelayedCallback​(java.time.Duration delay, java.lang.Runnable r)  
      protected void shutdown()  
      void sleep​(java.time.Duration d)  
      static void waitForOKQuery​(java.lang.Object anyStub)
      Used to ensure that workflow first workflow task is executed.
      void waitForTheEndOfWFT​(java.lang.String workflowId)
      Waits till the end of the workflow task if there is a workflow task in progress
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • REGENERATE_JSON_FILES

        public static final boolean REGENERATE_JSON_FILES
        See Also:
        Constant Field Values
      • useExternalService

        public static final boolean useExternalService
      • USE_VIRTUAL_THREADS

        public static final boolean USE_VIRTUAL_THREADS
    • Method Detail

      • apply

        public org.junit.runners.model.Statement apply​(@Nonnull
                                                       org.junit.runners.model.Statement base,
                                                       org.junit.runner.Description description)
        Specified by:
        apply in interface org.junit.rules.TestRule
      • getInterceptor

        public <T extends io.temporal.common.interceptors.WorkerInterceptor> T getInterceptor​(java.lang.Class<T> type)
      • getTaskQueue

        public java.lang.String getTaskQueue()
      • getDeploymentName

        public java.lang.String getDeploymentName()
      • getNexusEndpoint

        public io.temporal.api.nexus.v1.Endpoint getNexusEndpoint()
      • getWorker

        public io.temporal.worker.Worker getWorker()
      • newWorker

        public io.temporal.worker.Worker newWorker​(io.temporal.workflow.Functions.Proc1<io.temporal.worker.WorkerOptions.Builder> optionsModifier)
        Start a new worker, re-using existing options and modifying them with the provided modifier
      • newWorkerWithBuildID

        public io.temporal.worker.Worker newWorkerWithBuildID​(java.lang.String buildId)
        Start a new worker, changing only the build ID
      • getWorkerFactoryOptions

        public io.temporal.worker.WorkerFactoryOptions getWorkerFactoryOptions()
      • getExecutionHistory

        public io.temporal.common.WorkflowExecutionHistory getExecutionHistory​(java.lang.String workflowId)
      • getExecutionHistory

        public io.temporal.common.WorkflowExecutionHistory getExecutionHistory​(java.lang.String workflowId,
                                                                               java.lang.String runId)
      • getHistoryEvents

        public java.util.List<io.temporal.api.history.v1.HistoryEvent> getHistoryEvents​(java.lang.String workflowId,
                                                                                        io.temporal.api.enums.v1.EventType eventType)
        Returns list of all events of the given EventType found in the history.
      • getHistoryEvent

        public io.temporal.api.history.v1.HistoryEvent getHistoryEvent​(java.lang.String workflowId,
                                                                       io.temporal.api.enums.v1.EventType eventType)
        Returns the first event of the given EventType found in the history.
      • assertHistoryEvent

        public void assertHistoryEvent​(java.lang.String workflowId,
                                       io.temporal.api.enums.v1.EventType eventType)
        Asserts that an event of the given EventType is found in the history.
      • assertHistoryEvent

        public void assertHistoryEvent​(java.lang.String workflowId,
                                       java.lang.String runId,
                                       io.temporal.api.enums.v1.EventType eventType)
      • assertNoHistoryEvent

        public void assertNoHistoryEvent​(java.lang.String workflowId,
                                         io.temporal.api.enums.v1.EventType eventType)
        Asserts that an event of the given EventType is not found in the history.
      • assertNoHistoryEvent

        public void assertNoHistoryEvent​(java.lang.String workflowId,
                                         java.lang.String runId,
                                         io.temporal.api.enums.v1.EventType eventType)
        Asserts that an event of the given EventType is not found in the history.
      • assertNoHistoryEvent

        public static void assertNoHistoryEvent​(io.temporal.api.history.v1.History history,
                                                io.temporal.api.enums.v1.EventType eventType)
        Asserts that an event of the given EventType is not found in the history.
      • waitForTheEndOfWFT

        public void waitForTheEndOfWFT​(java.lang.String workflowId)
        Waits till the end of the workflow task if there is a workflow task in progress
      • getWorkflowClient

        public io.temporal.client.WorkflowClient getWorkflowClient()
      • getWorkflowServiceStubs

        public io.temporal.serviceclient.WorkflowServiceStubs getWorkflowServiceStubs()
      • isUseExternalService

        public boolean isUseExternalService()
      • newWorkflowStub

        public <T> T newWorkflowStub​(java.lang.Class<T> workflow)
      • newWorkflowStubTimeoutOptions

        public <T> T newWorkflowStubTimeoutOptions​(java.lang.Class<T> workflow)
      • newWorkflowStubTimeoutOptions

        public <T> T newWorkflowStubTimeoutOptions​(java.lang.Class<T> workflow,
                                                   java.lang.String workflowIdPrefix)
      • newWorkflowStub200sTimeoutOptions

        public <T> T newWorkflowStub200sTimeoutOptions​(java.lang.Class<T> workflow)
      • newUntypedWorkflowStub

        public io.temporal.client.WorkflowStub newUntypedWorkflowStub​(java.lang.String workflow)
      • newUntypedWorkflowStubTimeoutOptions

        public io.temporal.client.WorkflowStub newUntypedWorkflowStubTimeoutOptions​(java.lang.String workflow)
      • waitForOKQuery

        public static void waitForOKQuery​(java.lang.Object anyStub)
        Used to ensure that workflow first workflow task is executed.
      • addWorkflowImplementationFactory

        public <R> void addWorkflowImplementationFactory​(java.lang.Class<R> factoryImpl,
                                                         io.temporal.workflow.Functions.Func<R> factoryFunc)
      • regenerateHistoryForReplay

        public void regenerateHistoryForReplay​(java.lang.String workflowId,
                                               java.lang.String fileName)
      • registerDelayedCallback

        public void registerDelayedCallback​(java.time.Duration delay,
                                            java.lang.Runnable r)
      • shutdown

        protected void shutdown()
                         throws java.lang.Throwable
        Throws:
        java.lang.Throwable
      • sleep

        public void sleep​(java.time.Duration d)
      • invalidateWorkflowCache

        public void invalidateWorkflowCache()
        Causes eviction of all workflows in the worker cache