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"));
}
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"));
}
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();
}
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"));
}
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();
}
Aggregations