Search in sources :

Example 1 with Worker

use of io.temporal.worker.Worker in project sdk-java by temporalio.

the class TestWorkflowRule method init.

private String init(Description description) {
    String testMethod = description.getMethodName();
    String taskQueue = "WorkflowTest-" + testMethod + "-" + UUID.randomUUID();
    Worker worker = testEnvironment.newWorker(taskQueue, workerOptions);
    worker.registerWorkflowImplementationTypes(workflowImplementationOptions, workflowTypes);
    worker.registerActivitiesImplementations(activityImplementations);
    return taskQueue;
}
Also used : Worker(io.temporal.worker.Worker)

Example 2 with Worker

use of io.temporal.worker.Worker in project sdk-java by temporalio.

the class WorkflowReplayer method replayWorkflowExecution.

/**
 * Replays workflow from a {@link WorkflowExecutionHistory}.
 *
 * @param history object that contains the workflow ids and the events.
 * @param testWorkflowEnvironment to be used to create a worker on a task queue.
 * @param workflowClass s workflow implementation class to replay
 * @param moreWorkflowClasses optional additional workflow implementation classes
 * @throws Exception if replay failed for any reason.
 */
public static void replayWorkflowExecution(WorkflowExecutionHistory history, TestWorkflowEnvironment testWorkflowEnvironment, Class<?> workflowClass, Class<?>... moreWorkflowClasses) throws Exception {
    Worker worker = testWorkflowEnvironment.newWorker(getQueueName((history)));
    worker.registerWorkflowImplementationTypes(ObjectArrays.concat(moreWorkflowClasses, workflowClass));
    replayWorkflowExecution(history, worker);
}
Also used : Worker(io.temporal.worker.Worker)

Example 3 with Worker

use of io.temporal.worker.Worker in project sdk-java by temporalio.

the class TestEnvironmentCloseTest method testCloseNotHanging.

@Test
public void testCloseNotHanging() {
    TestWorkflowEnvironment env = TestWorkflowEnvironment.newInstance();
    Worker worker = env.newWorker("WW");
    worker.registerWorkflowImplementationTypes(WW.class);
    worker.registerActivitiesImplementations(new AA());
    long start = System.currentTimeMillis();
    env.close();
    long elapsed = System.currentTimeMillis() - start;
    assertTrue(elapsed < 5000);
}
Also used : TestWorkflowEnvironment(io.temporal.testing.TestWorkflowEnvironment) Worker(io.temporal.worker.Worker) Test(org.junit.Test)

Example 4 with Worker

use of io.temporal.worker.Worker in project sdk-java by temporalio.

the class WorkflowTestingTest method testActivityThatExecutesWorkflow.

/**
 * Tests situation when an activity executes a workflow using a workflow client.
 */
@Test
public void testActivityThatExecutesWorkflow() {
    Worker worker = testEnvironment.newWorker(TASK_QUEUE);
    worker.registerWorkflowImplementationTypes(TestActivityThatExecutesWorkflowImpl.class, WorkflowExecutedFromActivity.class);
    worker.registerActivitiesImplementations(new ActivityThatExecutesWorkflow(testEnvironment.getWorkflowClient(), TASK_QUEUE));
    testEnvironment.start();
    WorkflowClient client = testEnvironment.getWorkflowClient();
    WorkflowOptions options = WorkflowOptions.newBuilder().setTaskQueue(TASK_QUEUE).build();
    NoArgsWorkflow workflow = client.newWorkflowStub(NoArgsWorkflow.class, options);
    workflow.execute();
}
Also used : Worker(io.temporal.worker.Worker) WorkflowClient(io.temporal.client.WorkflowClient) WorkflowOptions(io.temporal.client.WorkflowOptions) NoArgsWorkflow(io.temporal.workflow.shared.TestWorkflows.NoArgsWorkflow) Test(org.junit.Test)

Example 5 with Worker

use of io.temporal.worker.Worker in project sdk-java by temporalio.

the class WorkflowTestingTest method testTimer.

@Test
public void testTimer() {
    Worker worker = testEnvironment.newWorker(TASK_QUEUE);
    worker.registerWorkflowImplementationTypes(TimerWorkflow.class);
    testEnvironment.start();
    WorkflowClient client = testEnvironment.getWorkflowClient();
    WorkflowOptions options = WorkflowOptions.newBuilder().setTaskQueue(TASK_QUEUE).build();
    TestWorkflow1 workflow = client.newWorkflowStub(TestWorkflow1.class, options);
    long start = testEnvironment.currentTimeMillis();
    String result = workflow.execute("input1");
    assertEquals("TestWorkflow1-input1", result);
    assertTrue(testEnvironment.currentTimeMillis() - start >= Duration.ofHours(2).toMillis());
}
Also used : Worker(io.temporal.worker.Worker) WorkflowClient(io.temporal.client.WorkflowClient) WorkflowOptions(io.temporal.client.WorkflowOptions) TestWorkflow1(io.temporal.workflow.shared.TestWorkflows.TestWorkflow1) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

Worker (io.temporal.worker.Worker)81 WorkflowClient (io.temporal.client.WorkflowClient)67 WorkflowOptions (io.temporal.client.WorkflowOptions)45 WorkerFactory (io.temporal.worker.WorkerFactory)34 Test (org.junit.Test)34 WorkflowServiceStubs (io.temporal.serviceclient.WorkflowServiceStubs)32 WorkflowException (io.temporal.client.WorkflowException)11 WorkflowTestingTest (io.temporal.internal.testing.WorkflowTestingTest)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 TestWorkflows (io.temporal.workflow.shared.TestWorkflows)8 TestWorkflow1 (io.temporal.workflow.shared.TestWorkflows.TestWorkflow1)8 TimeoutFailure (io.temporal.failure.TimeoutFailure)7 TestWorkflowEnvironment (io.temporal.testing.TestWorkflowEnvironment)6 ActivityFailure (io.temporal.failure.ActivityFailure)4 NoArgsWorkflow (io.temporal.workflow.shared.TestWorkflows.NoArgsWorkflow)4 WorkerFactoryOptions (io.temporal.worker.WorkerFactoryOptions)3 TestWorkflowReturnString (io.temporal.workflow.shared.TestWorkflows.TestWorkflowReturnString)3 RootScopeBuilder (com.uber.m3.tally.RootScopeBuilder)2 ImmutableMap (com.uber.m3.util.ImmutableMap)2 WorkflowExecution (io.temporal.api.common.v1.WorkflowExecution)2