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;
}
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);
}
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);
}
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();
}
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());
}
Aggregations