Search in sources :

Example 51 with InternalTask

use of org.ow2.proactive.scheduler.task.internal.InternalTask in project scheduling by ow2-proactive.

the class TestTaskResultData method testFlowAction.

@Test
public void testFlowAction() throws Exception {
    InternalJob job = saveSingleTask(createDefaultTask("task"));
    InternalTask task = (InternalTask) job.getTasks().get(0);
    TaskResultImpl result = new TaskResultImpl(null, new TestResult(10, "12345"), null, 0);
    FlowAction action = new FlowAction(FlowActionType.LOOP);
    action.setDupNumber(33);
    action.setTarget("t");
    action.setTargetContinuation("tc");
    action.setTargetElse("te");
    result.setAction(action);
    dbManager.updateAfterTaskFinished(job, task, result);
    TaskResultImpl restoredResult = (TaskResultImpl) dbManager.loadLastTaskResult(task.getId());
    FlowAction restoredAction = restoredResult.getAction();
    Assert.assertNotNull(restoredAction);
    Assert.assertEquals(FlowActionType.LOOP, restoredAction.getType());
    Assert.assertEquals(33, restoredAction.getDupNumber());
    Assert.assertEquals("t", restoredAction.getTarget());
    Assert.assertEquals("tc", restoredAction.getTargetContinuation());
    Assert.assertEquals("te", restoredAction.getTargetElse());
    restoredResult = (TaskResultImpl) dbManager.loadTaskResult(job.getId(), "task", 0);
    restoredAction = restoredResult.getAction();
    Assert.assertEquals(FlowActionType.LOOP, restoredAction.getType());
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) FlowAction(org.ow2.proactive.scheduler.common.task.flow.FlowAction) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) Test(org.junit.Test)

Example 52 with InternalTask

use of org.ow2.proactive.scheduler.task.internal.InternalTask in project scheduling by ow2-proactive.

the class TestTaskResultData method testExceptionResult.

@Test
public void testExceptionResult() throws Throwable {
    InternalJob job = saveSingleTask(createDefaultTask("task"));
    TaskResultImpl result = new TaskResultImpl(null, new TestException("message", "data"), null, 0);
    InternalTask task = (InternalTask) job.getTasks().get(0);
    dbManager.updateAfterTaskFinished(job, task, result);
    TaskResult restoredResult = dbManager.loadLastTaskResult(task.getId());
    TestException exception = (TestException) restoredResult.getException();
    Assert.assertNotNull(exception);
    Assert.assertEquals("message", exception.getMessage());
    Assert.assertEquals("data", exception.getData());
    try {
        restoredResult.value();
        Assert.fail("Exception is expected");
    } catch (TestException e) {
    }
    Assert.assertNull(restoredResult.getOutput());
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Test(org.junit.Test)

Example 53 with InternalTask

use of org.ow2.proactive.scheduler.task.internal.InternalTask in project scheduling by ow2-proactive.

the class TestTaskResultData method testMultipleResults.

@Test
public void testMultipleResults() throws Throwable {
    TaskFlowJob job = new TaskFlowJob();
    job.addTask(createDefaultTask("task1"));
    job.addTask(createDefaultTask("task2"));
    job.addTask(createDefaultTask("task3"));
    InternalJob internalJob = defaultSubmitJobAndLoadInternal(true, job);
    InternalTask task1 = internalJob.getTask("task1");
    InternalTask task2 = internalJob.getTask("task2");
    InternalTask task3 = internalJob.getTask("task3");
    dbManager.updateAfterTaskFinished(internalJob, task1, new TaskResultImpl(null, new TestResult(0, "1_1"), null, 0));
    dbManager.updateAfterTaskFinished(internalJob, task1, new TaskResultImpl(null, new TestResult(0, "1_2"), null, 0));
    dbManager.updateAfterTaskFinished(internalJob, task1, new TaskResultImpl(null, new TestResult(0, "1_3"), null, 0));
    dbManager.updateAfterTaskFinished(internalJob, task2, new TaskResultImpl(null, new TestResult(0, "2_1"), null, 0));
    dbManager.updateAfterTaskFinished(internalJob, task2, new TaskResultImpl(null, new TestResult(0, "2_2"), null, 0));
    dbManager.updateAfterTaskFinished(internalJob, task2, new TaskResultImpl(null, new TestResult(0, "2_3"), null, 0));
    dbManager.updateAfterTaskFinished(internalJob, task3, new TaskResultImpl(null, new TestResult(0, "3_1"), null, 0));
    dbManager.updateAfterTaskFinished(internalJob, task3, new TaskResultImpl(null, new TestResult(0, "3_2"), null, 0));
    dbManager.updateAfterTaskFinished(internalJob, task3, new TaskResultImpl(null, new TestResult(0, "3_3"), null, 0));
    TestResult result;
    result = (TestResult) dbManager.loadLastTaskResult(task1.getId()).value();
    Assert.assertEquals("1_3", result.getB());
    result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task1.getName(), 0).value();
    Assert.assertEquals("1_3", result.getB());
    result = (TestResult) dbManager.loadLastTaskResult(task2.getId()).value();
    Assert.assertEquals("2_3", result.getB());
    result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task2.getName(), 0).value();
    Assert.assertEquals("2_3", result.getB());
    result = (TestResult) dbManager.loadLastTaskResult(task3.getId()).value();
    Assert.assertEquals("3_3", result.getB());
    result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task3.getName(), 0).value();
    Assert.assertEquals("3_3", result.getB());
    result = (TestResult) dbManager.loadTaskResult(task2.getId(), 0).value();
    Assert.assertEquals("2_3", result.getB());
    result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task2.getName(), 0).value();
    Assert.assertEquals("2_3", result.getB());
    result = (TestResult) dbManager.loadTaskResult(task2.getId(), 1).value();
    Assert.assertEquals("2_2", result.getB());
    result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task2.getName(), 1).value();
    Assert.assertEquals("2_2", result.getB());
    result = (TestResult) dbManager.loadTaskResult(task2.getId(), 2).value();
    Assert.assertEquals("2_1", result.getB());
    result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task2.getName(), 2).value();
    Assert.assertEquals("2_1", result.getB());
    Assert.assertNull(dbManager.loadTaskResult(task2.getId(), 3));
    Assert.assertNull(dbManager.loadTaskResult(internalJob.getId(), task2.getName(), 3));
    List<TaskId> taskIds = Arrays.asList(task1.getId(), task2.getId(), task3.getId());
    System.out.println("Load results for 3 tasks");
    Map<TaskId, TaskResult> results = dbManager.loadTasksResults(internalJob.getId(), taskIds);
    Assert.assertEquals(3, results.size());
    result = (TestResult) results.get(task1.getId()).value();
    Assert.assertEquals("1_3", result.getB());
    result = (TestResult) results.get(task2.getId()).value();
    Assert.assertEquals("2_3", result.getB());
    result = (TestResult) results.get(task3.getId()).value();
    Assert.assertEquals("3_3", result.getB());
    taskIds = Arrays.asList(task2.getId(), task3.getId());
    System.out.println("Load results for 2 tasks");
    results = dbManager.loadTasksResults(internalJob.getId(), taskIds);
    Assert.assertEquals(2, results.size());
    result = (TestResult) results.get(task2.getId()).value();
    Assert.assertEquals("2_3", result.getB());
    result = (TestResult) results.get(task3.getId()).value();
    Assert.assertEquals("3_3", result.getB());
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Test(org.junit.Test)

Example 54 with InternalTask

use of org.ow2.proactive.scheduler.task.internal.InternalTask in project scheduling by ow2-proactive.

the class TestTaskResultData method testLog4jLogs.

@Test
public void testLog4jLogs() throws Exception {
    InternalJob job = saveSingleTask(createDefaultTask("task"));
    InternalTask task = (InternalTask) job.getTasks().get(0);
    LinkedList<LoggingEvent> events = new LinkedList<>();
    for (int i = 0; i < 3; i++) {
        events.add(new LoggingEvent("", Logger.getLogger(TestTaskResultData.class), Level.INFO, "info" + i, null));
        events.add(new LoggingEvent("", Logger.getLogger(TestTaskResultData.class), Level.ERROR, "error" + i, null));
    }
    TaskResultImpl result = new TaskResultImpl(null, "result", new Log4JTaskLogs(events, "0"), 0);
    dbManager.updateAfterTaskFinished(job, task, result);
    TaskResult restoredResult = dbManager.loadLastTaskResult(task.getId());
    TaskLogs logs = restoredResult.getOutput();
    Assert.assertNotNull(logs);
    String logsString = logs.getStdoutLogs(false);
    Assert.assertTrue(logsString.contains("info0"));
    Assert.assertTrue(logsString.contains("info1"));
    Assert.assertTrue(logsString.contains("info2"));
    logsString = logs.getStderrLogs(false);
    Assert.assertTrue(logsString.contains("error0"));
    Assert.assertTrue(logsString.contains("error1"));
    Assert.assertTrue(logsString.contains("error2"));
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) TaskLogs(org.ow2.proactive.scheduler.common.task.TaskLogs) Log4JTaskLogs(org.ow2.proactive.scheduler.common.task.Log4JTaskLogs) SimpleTaskLogs(org.ow2.proactive.scheduler.common.task.SimpleTaskLogs) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) Log4JTaskLogs(org.ow2.proactive.scheduler.common.task.Log4JTaskLogs) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 55 with InternalTask

use of org.ow2.proactive.scheduler.task.internal.InternalTask in project scheduling by ow2-proactive.

the class TestTaskRuntimeData method testStartJobExecution.

@Test
public void testStartJobExecution() throws Exception {
    TaskFlowJob job = new TaskFlowJob();
    job.addTask(createDefaultTask("task1"));
    job.addTask(createDefaultTask("task2"));
    job.addTask(createDefaultTask("task3"));
    InternalJob internalJob = defaultSubmitJobAndLoadInternal(true, job);
    Assert.assertEquals(TaskStatus.SUBMITTED, internalJob.getTask("task1").getStatus());
    Assert.assertEquals(TaskStatus.SUBMITTED, internalJob.getTask("task2").getStatus());
    Assert.assertEquals(TaskStatus.SUBMITTED, internalJob.getTask("task3").getStatus());
    internalJob.start();
    InternalTask task = startTask(internalJob, internalJob.getTask("task1"));
    System.out.println("Job started");
    dbManager.jobTaskStarted(internalJob, task, true);
    internalJob = loadInternalJob(true, internalJob.getId());
    Assert.assertEquals(TaskStatus.RUNNING, internalJob.getTask("task1").getStatus());
    Assert.assertEquals(TaskStatus.PENDING, internalJob.getTask("task2").getStatus());
    Assert.assertEquals(TaskStatus.PENDING, internalJob.getTask("task3").getStatus());
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) Test(org.junit.Test)

Aggregations

InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)142 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)74 Test (org.junit.Test)72 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)39 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)37 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)32 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)31 ArrayList (java.util.ArrayList)30 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)25 JobId (org.ow2.proactive.scheduler.common.job.JobId)22 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)18 ExecuterInformation (org.ow2.proactive.scheduler.task.internal.ExecuterInformation)16 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)13 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)12 HashMap (java.util.HashMap)10 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)10 ProActiveTest (org.ow2.tests.ProActiveTest)10 TaskInfo (org.ow2.proactive.scheduler.common.task.TaskInfo)9 HashSet (java.util.HashSet)8 SchedulerStateRecoverHelper (org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper)8