use of com.dangdang.ddframe.job.cloud.scheduler.fixture.TaskNode in project elastic-job by dangdangdotcom.
the class SchedulerEngineTest method assertKilledStatusUpdate.
@Test
public void assertKilledStatusUpdate() {
@SuppressWarnings("unchecked") Action2<String, String> taskUnAssigner = mock(Action2.class);
when(taskScheduler.getTaskUnAssigner()).thenReturn(taskUnAssigner);
TaskNode taskNode = TaskNode.builder().build();
when(facadeService.popMapping(taskNode.getTaskNodeValue())).thenReturn("localhost");
schedulerEngine.statusUpdate(null, Protos.TaskStatus.newBuilder().setTaskId(Protos.TaskID.newBuilder().setValue(taskNode.getTaskNodeValue())).setState(Protos.TaskState.TASK_KILLED).setSlaveId(Protos.SlaveID.newBuilder().setValue("slave-S0")).build());
verify(facadeService).removeRunning(TaskContext.from(taskNode.getTaskNodeValue()));
verify(facadeService).addDaemonJobToReadyQueue("test_job");
verify(taskUnAssigner).call(TaskContext.getIdForUnassignedSlave(taskNode.getTaskNodeValue()), "localhost");
}
use of com.dangdang.ddframe.job.cloud.scheduler.fixture.TaskNode in project elastic-job by dangdangdotcom.
the class SchedulerEngineTest method assertFinishedStatusUpdate.
@Test
public void assertFinishedStatusUpdate() {
@SuppressWarnings("unchecked") Action2<String, String> taskUnAssigner = mock(Action2.class);
when(taskScheduler.getTaskUnAssigner()).thenReturn(taskUnAssigner);
TaskNode taskNode = TaskNode.builder().build();
when(facadeService.popMapping(taskNode.getTaskNodeValue())).thenReturn("localhost");
schedulerEngine.statusUpdate(null, Protos.TaskStatus.newBuilder().setTaskId(Protos.TaskID.newBuilder().setValue(taskNode.getTaskNodeValue())).setState(Protos.TaskState.TASK_FINISHED).setSlaveId(Protos.SlaveID.newBuilder().setValue("slave-S0")).build());
verify(facadeService).removeRunning(TaskContext.from(taskNode.getTaskNodeValue()));
verify(taskUnAssigner).call(TaskContext.getIdForUnassignedSlave(taskNode.getTaskNodeValue()), "localhost");
verify(statisticManager).taskRunSuccessfully();
}
use of com.dangdang.ddframe.job.cloud.scheduler.fixture.TaskNode in project elastic-job by dangdangdotcom.
the class SchedulerEngineTest method assertErrorStatusUpdate.
@Test
public void assertErrorStatusUpdate() {
@SuppressWarnings("unchecked") Action2<String, String> taskUnAssigner = mock(Action2.class);
when(taskScheduler.getTaskUnAssigner()).thenReturn(taskUnAssigner);
TaskNode taskNode = TaskNode.builder().build();
when(facadeService.popMapping(taskNode.getTaskNodeValue())).thenReturn("localhost");
schedulerEngine.statusUpdate(null, Protos.TaskStatus.newBuilder().setTaskId(Protos.TaskID.newBuilder().setValue(taskNode.getTaskNodeValue())).setState(Protos.TaskState.TASK_ERROR).setSlaveId(Protos.SlaveID.newBuilder().setValue("slave-S0")).build());
verify(facadeService).recordFailoverTask(TaskContext.from(taskNode.getTaskNodeValue()));
verify(facadeService).removeRunning(TaskContext.from(taskNode.getTaskNodeValue()));
verify(taskUnAssigner).call(TaskContext.getIdForUnassignedSlave(taskNode.getTaskNodeValue()), "localhost");
verify(statisticManager).taskRunFailed();
}
use of com.dangdang.ddframe.job.cloud.scheduler.fixture.TaskNode in project elastic-job by dangdangdotcom.
the class FailoverServiceTest method assertAddWhenNotExistedAndTaskIsNotRunning.
@Test
public void assertAddWhenNotExistedAndTaskIsNotRunning() {
TaskNode taskNode = TaskNode.builder().type(ExecutionType.FAILOVER).build();
when(configService.load("test_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job")));
when(regCenter.isExisted("/state/failover/test_job/" + taskNode.getTaskNodePath())).thenReturn(false);
when(runningService.isTaskRunning(TaskContext.MetaInfo.from(taskNode.getTaskNodePath()))).thenReturn(false);
failoverService.add(TaskContext.from(taskNode.getTaskNodeValue()));
verify(regCenter).isExisted("/state/failover/test_job/" + taskNode.getTaskNodePath());
verify(runningService).isTaskRunning(TaskContext.MetaInfo.from(taskNode.getTaskNodePath()));
verify(regCenter).persist("/state/failover/test_job/" + taskNode.getTaskNodePath(), taskNode.getTaskNodeValue());
}
use of com.dangdang.ddframe.job.cloud.scheduler.fixture.TaskNode in project elastic-job by dangdangdotcom.
the class RunningServiceTest method assertStart.
@Test
public void assertStart() {
TaskNode taskNode1 = TaskNode.builder().jobName("test_job").shardingItem(0).slaveId("111").type(ExecutionType.READY).uuid(UUID.randomUUID().toString()).build();
TaskNode taskNode2 = TaskNode.builder().jobName("test_job").shardingItem(1).slaveId("222").type(ExecutionType.FAILOVER).uuid(UUID.randomUUID().toString()).build();
when(regCenter.getChildrenKeys(RunningNode.ROOT)).thenReturn(Collections.singletonList("test_job"));
when(regCenter.getChildrenKeys(RunningNode.getRunningJobNodePath("test_job"))).thenReturn(Arrays.asList(taskNode1.getTaskNodePath(), taskNode2.getTaskNodePath()));
when(regCenter.get(RunningNode.getRunningTaskNodePath(taskNode1.getTaskNodePath()))).thenReturn(taskNode1.getTaskNodeValue());
when(regCenter.get(RunningNode.getRunningTaskNodePath(taskNode2.getTaskNodePath()))).thenReturn(taskNode2.getTaskNodeValue());
runningService.start();
assertThat(runningService.getAllRunningDaemonTasks().size(), is(2));
}
Aggregations