use of com.netflix.conductor.common.metadata.tasks.Task in project conductor by Netflix.
the class TestWorkflowTask method testObjectMapper.
@SuppressWarnings("unchecked")
@Test
public void testObjectMapper() throws Exception {
try (InputStream stream = TestWorkflowTask.class.getResourceAsStream("/tasks.json")) {
List<Task> tasks = objectMapper.readValue(stream, List.class);
assertNotNull(tasks);
assertEquals(1, tasks.size());
}
}
use of com.netflix.conductor.common.metadata.tasks.Task in project conductor by Netflix.
the class WorkflowTaskCoordinatorTests method testReturnTaskWhenRejectedExecutionExceptionThrown.
@Test
public void testReturnTaskWhenRejectedExecutionExceptionThrown() {
Task testTask = new Task();
testTask.setStatus(Task.Status.IN_PROGRESS);
Worker worker = mock(Worker.class);
when(worker.getPollingInterval()).thenReturn(3000);
when(worker.getPollCount()).thenReturn(1);
when(worker.getTaskDefName()).thenReturn("test");
when(worker.preAck(any())).thenReturn(true);
when(worker.execute(any())).thenAnswer(invocation -> {
// Sleep for 2 seconds to trigger RejectedExecutionException
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
return new TaskResult(testTask);
});
TaskClient client = Mockito.mock(TaskClient.class);
WorkflowTaskCoordinator coordinator = new WorkflowTaskCoordinator.Builder().withWorkers(worker).withThreadCount(1).withWorkerQueueSize(1).withSleepWhenRetry(100000).withUpdateRetryCount(1).withTaskClient(client).withWorkerNamePrefix("test-worker-").build();
when(client.batchPollTasksInDomain(anyString(), isNull(), isNull(), anyInt(), anyInt())).thenReturn(ImmutableList.of(testTask, testTask, testTask));
when(client.ack(any(), any())).thenReturn(true);
CountDownLatch latch = new CountDownLatch(3);
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
TaskResult result = (TaskResult) args[0];
assertEquals(TaskResult.Status.IN_PROGRESS, result.getStatus());
latch.countDown();
return null;
}).when(client).updateTask(any());
coordinator.init();
Uninterruptibles.awaitUninterruptibly(latch);
// With worker queue set to 1, first two tasks can be submitted, and third one would get
// RejectedExceptionExcpetion, so worker.execute() should be called twice.
verify(worker, times(2)).execute(any());
// task must be updated with IN_PROGRESS status three times, two from worker.execute() and
// one from returnTask caused by RejectedExecutionException.
verify(client, times(3)).updateTask(any());
}
use of com.netflix.conductor.common.metadata.tasks.Task in project conductor by Netflix.
the class WorkflowTaskCoordinatorTests method testLargePayloadCanFailUpdateWithRetry.
@Test
public void testLargePayloadCanFailUpdateWithRetry() {
Task testTask = new Task();
testTask.setStatus(Task.Status.COMPLETED);
Worker worker = mock(Worker.class);
when(worker.getPollingInterval()).thenReturn(3000);
when(worker.getPollCount()).thenReturn(1);
when(worker.getTaskDefName()).thenReturn("test");
when(worker.preAck(any())).thenReturn(true);
when(worker.execute(any())).thenAnswer(invocation -> {
// Sleep for 2 seconds to trigger RejectedExecutionException
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
return new TaskResult(testTask);
});
TaskClient taskClient = Mockito.mock(TaskClient.class);
WorkflowTaskCoordinator coordinator = new WorkflowTaskCoordinator.Builder().withWorkers(worker).withThreadCount(1).withWorkerQueueSize(1).withSleepWhenRetry(100000).withUpdateRetryCount(3).withTaskClient(taskClient).withWorkerNamePrefix("test-worker-").build();
when(taskClient.batchPollTasksInDomain(anyString(), isNull(), isNull(), anyInt(), anyInt())).thenReturn(ImmutableList.of(testTask));
when(taskClient.ack(any(), any())).thenReturn(true);
doThrow(ConductorClientException.class).when(taskClient).evaluateAndUploadLargePayload(any(TaskResult.class), any());
CountDownLatch latch = new CountDownLatch(1);
doAnswer(invocation -> {
latch.countDown();
return null;
}).when(worker).onErrorUpdate(any());
coordinator.init();
Uninterruptibles.awaitUninterruptibly(latch);
// When evaluateAndUploadLargePayload fails indefinitely, task update shouldn't be called.
verify(taskClient, times(0)).updateTask(any());
}
use of com.netflix.conductor.common.metadata.tasks.Task in project conductor by Netflix.
the class TaskTest method testDeepCopyTask.
@Test
public void testDeepCopyTask() {
final Task task = new Task();
// In order to avoid forgetting putting inside the copy method the newly added fields check the number of declared fields.
final int expectedTaskFieldsNumber = 40;
final int declaredFieldsNumber = task.getClass().getDeclaredFields().length;
assertEquals(expectedTaskFieldsNumber, declaredFieldsNumber);
task.setCallbackAfterSeconds(111L);
task.setCallbackFromWorker(false);
task.setCorrelationId("correlation_id");
task.setInputData(new HashMap<>());
task.setOutputData(new HashMap<>());
task.setReferenceTaskName("ref_task_name");
task.setStartDelayInSeconds(1);
task.setTaskDefName("task_def_name");
task.setTaskType("dummy_task_type");
task.setWorkflowInstanceId("workflowInstanceId");
task.setWorkflowType("workflowType");
task.setResponseTimeoutSeconds(11L);
task.setStatus(Status.COMPLETED);
task.setRetryCount(0);
task.setPollCount(0);
task.setTaskId("taskId");
task.setWorkflowTask(new WorkflowTask());
task.setDomain("domain");
task.setInputMessage(Any.getDefaultInstance());
task.setOutputMessage(Any.getDefaultInstance());
task.setRateLimitPerFrequency(11);
task.setRateLimitFrequencyInSeconds(11);
task.setExternalInputPayloadStoragePath("externalInputPayloadStoragePath");
task.setExternalOutputPayloadStoragePath("externalOutputPayloadStoragePath");
task.setWorkflowPriority(0);
task.setIteration(1);
task.setExecutionNameSpace("name_space");
task.setIsolationGroupId("groupId");
task.setStartTime(12L);
task.setEndTime(20L);
task.setScheduledTime(7L);
task.setRetried(false);
task.setReasonForIncompletion("");
task.setWorkerId("");
task.setSubWorkflowId("");
final Task copy = task.deepCopy();
assertEquals(task, copy);
}
use of com.netflix.conductor.common.metadata.tasks.Task in project conductor by Netflix.
the class TaskTest method testTaskDefinitionIfAvailable.
@Test
public void testTaskDefinitionIfAvailable() {
Task task = new Task();
task.setStatus(Status.FAILED);
assertEquals(Status.FAILED, task.getStatus());
assertNull(task.getWorkflowTask());
assertFalse(task.getTaskDefinition().isPresent());
WorkflowTask workflowTask = new WorkflowTask();
TaskDef taskDefinition = new TaskDef();
workflowTask.setTaskDefinition(taskDefinition);
task.setWorkflowTask(workflowTask);
assertTrue(task.getTaskDefinition().isPresent());
assertEquals(taskDefinition, task.getTaskDefinition().get());
}
Aggregations