Search in sources :

Example 71 with InternalJob

use of org.ow2.proactive.scheduler.job.InternalJob 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 72 with InternalJob

use of org.ow2.proactive.scheduler.job.InternalJob 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 73 with InternalJob

use of org.ow2.proactive.scheduler.job.InternalJob 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 74 with InternalJob

use of org.ow2.proactive.scheduler.job.InternalJob in project scheduling by ow2-proactive.

the class TestTaskResultData method testMultipleJobs.

@Test
public void testMultipleJobs() throws Throwable {
    // two jobs have tasks with the same name
    TaskFlowJob jobDef1 = new TaskFlowJob();
    jobDef1.addTask(createDefaultTask("task1"));
    TaskFlowJob jobDef2 = new TaskFlowJob();
    jobDef2.addTask(createDefaultTask("task1"));
    InternalJob job1 = defaultSubmitJobAndLoadInternal(true, jobDef1);
    InternalJob job2 = defaultSubmitJobAndLoadInternal(true, jobDef2);
    dbManager.updateAfterTaskFinished(job1, job1.getTask("task1"), new TaskResultImpl(null, new TestResult(0, "job1Res"), null, 0));
    dbManager.updateAfterTaskFinished(job2, job2.getTask("task1"), new TaskResultImpl(null, new TestResult(0, "job2Res"), null, 0));
    TestResult result;
    result = (TestResult) dbManager.loadTaskResult(job1.getId(), "task1", 0).value();
    Assert.assertEquals("job1Res", result.getB());
    result = (TestResult) dbManager.loadTaskResult(job2.getId(), "task1", 0).value();
    Assert.assertEquals("job2Res", result.getB());
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) Test(org.junit.Test)

Example 75 with InternalJob

use of org.ow2.proactive.scheduler.job.InternalJob 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)

Aggregations

InternalJob (org.ow2.proactive.scheduler.job.InternalJob)166 Test (org.junit.Test)115 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)90 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)53 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)36 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)34 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)33 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)32 JobId (org.ow2.proactive.scheduler.common.job.JobId)28 ArrayList (java.util.ArrayList)27 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)26 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)19 RecoveredSchedulerState (org.ow2.proactive.scheduler.core.db.RecoveredSchedulerState)19 Matchers.containsString (org.hamcrest.Matchers.containsString)16 Matchers.anyString (org.mockito.Matchers.anyString)16 ExecuterInformation (org.ow2.proactive.scheduler.task.internal.ExecuterInformation)15 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)13 SchedulerStateRecoverHelper (org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper)12 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)12 HashMap (java.util.HashMap)10