Search in sources :

Example 1 with Task

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());
    }
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 2 with Task

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());
}
Also used : TaskClient(com.netflix.conductor.client.http.TaskClient) Task(com.netflix.conductor.common.metadata.tasks.Task) Worker(com.netflix.conductor.client.worker.Worker) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 3 with Task

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());
}
Also used : TaskClient(com.netflix.conductor.client.http.TaskClient) Task(com.netflix.conductor.common.metadata.tasks.Task) Worker(com.netflix.conductor.client.worker.Worker) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 4 with Task

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);
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 5 with Task

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());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Aggregations

Task (com.netflix.conductor.common.metadata.tasks.Task)357 Workflow (com.netflix.conductor.common.run.Workflow)249 Test (org.junit.Test)248 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)227 HashMap (java.util.HashMap)147 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)121 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)110 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)95 UserTask (com.netflix.conductor.tests.utils.UserTask)73 Map (java.util.Map)53 LinkedList (java.util.LinkedList)51 WorkflowSystemTask (com.netflix.conductor.core.execution.tasks.WorkflowSystemTask)45 List (java.util.List)45 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)41 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)39 TaskResult (com.netflix.conductor.common.metadata.tasks.TaskResult)38 Status (com.netflix.conductor.common.metadata.tasks.Task.Status)32 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)29 Collectors (java.util.stream.Collectors)29 TaskType (com.netflix.conductor.common.metadata.workflow.TaskType)28