Search in sources :

Example 11 with SchedulerDBManager

use of org.ow2.proactive.scheduler.core.db.SchedulerDBManager in project scheduling by ow2-proactive.

the class TaskResultCreatorTest method testThatJobVariablesAreUsedIfTaskHasNoParents.

@Test
public void testThatJobVariablesAreUsedIfTaskHasNoParents() throws UnknownTaskException {
    TaskResultCreator taskResultCreator = new TaskResultCreator();
    SchedulerDBManager mockedschedulerDbManager = mock(SchedulerDBManager.class);
    when(mockedschedulerDbManager.loadTasksResults(any(JobId.class), any(List.class))).thenThrow(new DatabaseManagerException());
    InternalJob mockedInternalJob = this.getMockedInternalJobTaskFlowType(this.getMockedJobDescriptorWithPausedTaskWithoutParent());
    Map<String, JobVariable> fakeVariableMap = new HashMap<>();
    fakeVariableMap.put("TestVar", new JobVariable("TestVar", "h234"));
    when(mockedInternalJob.getVariables()).thenReturn(fakeVariableMap);
    Map<String, String> fakeReplacementVariableMap = new HashMap<>();
    fakeReplacementVariableMap.put("TestVar", "h234");
    when(mockedInternalJob.getVariablesAsReplacementMap()).thenReturn(fakeReplacementVariableMap);
    TaskResult taskResult = taskResultCreator.getTaskResult(mockedschedulerDbManager, mockedInternalJob, this.getMockedInternalTask());
    verify(mockedInternalJob, atLeastOnce()).getVariablesAsReplacementMap();
    assertThat(new String(taskResult.getPropagatedVariables().get("TestVar")), is("h234"));
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) HashMap(java.util.HashMap) SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) List(java.util.List) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) JobId(org.ow2.proactive.scheduler.common.job.JobId) DatabaseManagerException(org.ow2.proactive.db.DatabaseManagerException) Test(org.junit.Test)

Example 12 with SchedulerDBManager

use of org.ow2.proactive.scheduler.core.db.SchedulerDBManager in project scheduling by ow2-proactive.

the class TaskResultCreatorTest method testThatTaskVariablesAreUsedIfTaskisInDB.

@Test
public void testThatTaskVariablesAreUsedIfTaskisInDB() throws UnknownTaskException {
    TaskResultCreator taskResultCreator = new TaskResultCreator();
    TaskResultImpl mockedTaskResultImpl = mock(TaskResultImpl.class);
    Map<String, byte[]> fakeVariableMap = new HashMap<>();
    fakeVariableMap.put("TestVar", new String("h234").getBytes());
    when(mockedTaskResultImpl.getPropagatedVariables()).thenReturn(fakeVariableMap);
    SchedulerDBManager mockedschedulerDbManager = mock(SchedulerDBManager.class);
    when(mockedschedulerDbManager.loadLastTaskResult(any(TaskId.class))).thenReturn(mockedTaskResultImpl);
    InternalJob mockedInternalJob = this.getMockedInternalJobTaskFlowType(this.getMockedJobDescriptorWithPausedTaskWithoutParent());
    TaskResult taskResult = taskResultCreator.getTaskResult(mockedschedulerDbManager, mockedInternalJob, this.getMockedInternalTask());
    verify(mockedTaskResultImpl, atLeastOnce()).getPropagatedVariables();
    assertThat(new String(taskResult.getPropagatedVariables().get("TestVar")), is("h234"));
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) HashMap(java.util.HashMap) SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Test(org.junit.Test)

Example 13 with SchedulerDBManager

use of org.ow2.proactive.scheduler.core.db.SchedulerDBManager in project scheduling by ow2-proactive.

the class TaskResultCreatorTest method testThatGetPropagatedVariablesAreExtractedFromParents.

@Test
public void testThatGetPropagatedVariablesAreExtractedFromParents() throws UnknownTaskException {
    TaskResultCreator taskResultCreator = new TaskResultCreator();
    TaskResultImpl mockedTaskResultImpl = mock(TaskResultImpl.class);
    Map<TaskId, TaskResult> loadTaskResultsValue = new HashMap<>();
    loadTaskResultsValue.put(this.createTaskID(), mockedTaskResultImpl);
    when(mockedTaskResultImpl.getPropagatedVariables()).thenReturn(new HashMap<String, byte[]>());
    SchedulerDBManager mockedschedulerDbManager = mock(SchedulerDBManager.class);
    when(mockedschedulerDbManager.loadTasksResults(any(JobId.class), any(List.class))).thenReturn(loadTaskResultsValue);
    taskResultCreator.getTaskResult(mockedschedulerDbManager, this.getMockedInternalJobTaskFlowType(this.getMockedJobDescriptorWithPausedTask()), this.getMockedInternalTask());
    verify(mockedTaskResultImpl, atLeastOnce()).getPropagatedVariables();
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) HashMap(java.util.HashMap) SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) List(java.util.List) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 14 with SchedulerDBManager

use of org.ow2.proactive.scheduler.core.db.SchedulerDBManager in project scheduling by ow2-proactive.

the class TaskResultCreatorTest method testThatPropagatedVariablesAreExtractedFromParents.

@Test
public void testThatPropagatedVariablesAreExtractedFromParents() throws UnknownTaskException {
    Map<String, byte[]> fakeVariableMap = new HashMap<>();
    fakeVariableMap.put("ParentVar", "5623g".getBytes());
    TaskResultCreator taskResultCreator = new TaskResultCreator();
    TaskResultImpl mockedParentTaskResultImpl = mock(TaskResultImpl.class);
    Map<TaskId, TaskResult> loadParentTaskResultsValue = new HashMap<>();
    loadParentTaskResultsValue.put(this.createTaskID(), mockedParentTaskResultImpl);
    when(mockedParentTaskResultImpl.getPropagatedVariables()).thenReturn(fakeVariableMap);
    SchedulerDBManager mockedschedulerDbManager = mock(SchedulerDBManager.class);
    when(mockedschedulerDbManager.loadTasksResults(any(JobId.class), any(List.class))).thenReturn(loadParentTaskResultsValue);
    TaskResult taskResult = taskResultCreator.getTaskResult(mockedschedulerDbManager, this.getMockedInternalJobTaskFlowType(this.getMockedJobDescriptorWithPausedTask()), this.getMockedInternalTask());
    when(taskResult.getPropagatedVariables()).thenCallRealMethod();
    assertThat(new String(taskResult.getPropagatedVariables().get("ParentVar")), is("5623g"));
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) HashMap(java.util.HashMap) SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) List(java.util.List) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 15 with SchedulerDBManager

use of org.ow2.proactive.scheduler.core.db.SchedulerDBManager in project scheduling by ow2-proactive.

the class TaskResultCreatorTest method testRunningTasksAreCheckedForATaskId.

@Test
public void testRunningTasksAreCheckedForATaskId() throws UnknownTaskException {
    TaskResultCreator taskResultCreator = new TaskResultCreator();
    TaskResultImpl mockedTaskResultImpl = mock(TaskResultImpl.class);
    Map<TaskId, TaskResult> loadTaskResultsValue = new HashMap<>();
    loadTaskResultsValue.put(this.createTaskID(), mockedTaskResultImpl);
    SchedulerDBManager mockedschedulerDbManager = mock(SchedulerDBManager.class);
    when(mockedschedulerDbManager.loadTasksResults(any(JobId.class), any(List.class))).thenReturn(loadTaskResultsValue);
    JobDescriptorImpl mockedJobDescriptorHasRunningTask = this.getMockedJobDescriptorWithRunningTask();
    taskResultCreator.getTaskResult(mockedschedulerDbManager, this.getMockedInternalJob(mockedJobDescriptorHasRunningTask), this.getMockedInternalTask());
    verify(mockedJobDescriptorHasRunningTask, atLeastOnce()).getRunningTasks();
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) HashMap(java.util.HashMap) SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) List(java.util.List) JobDescriptorImpl(org.ow2.proactive.scheduler.descriptor.JobDescriptorImpl) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Aggregations

SchedulerDBManager (org.ow2.proactive.scheduler.core.db.SchedulerDBManager)18 Test (org.junit.Test)14 HashMap (java.util.HashMap)9 JobId (org.ow2.proactive.scheduler.common.job.JobId)9 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)9 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)8 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)8 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)8 List (java.util.List)7 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)3 ProActiveTest (org.ow2.tests.ProActiveTest)3 File (java.io.File)2 Map (java.util.Map)2 Configuration (org.hibernate.cfg.Configuration)2 Before (org.junit.Before)2 SchedulerStateRecoverHelper (org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper)2 JobDescriptorImpl (org.ow2.proactive.scheduler.descriptor.JobDescriptorImpl)2 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)2 ImmutableList (com.google.common.collect.ImmutableList)1 KeyException (java.security.KeyException)1