use of com.dangdang.ddframe.job.context.TaskContext in project elastic-job by dangdangdotcom.
the class ProducerManagerTest method assertUpdateExisted.
@Test
public void assertUpdateExisted() {
when(configService.load("transient_test_job")).thenReturn(Optional.of(transientJobConfig));
List<TaskContext> taskContexts = Arrays.asList(TaskContext.from("transient_test_job@-@0@-@READY@-@SLAVE-S0@-@UUID"), TaskContext.from("transient_test_job@-@1@-@READY@-@SLAVE-S0@-@UUID"));
when(runningService.getRunningTasks("transient_test_job")).thenReturn(taskContexts);
producerManager.update(transientJobConfig);
verify(configService).update(transientJobConfig);
for (TaskContext each : taskContexts) {
verify(schedulerDriver).killTask(Protos.TaskID.newBuilder().setValue(each.getId()).build());
}
verify(runningService).remove("transient_test_job");
verify(readyService).remove(Lists.newArrayList("transient_test_job"));
}
use of com.dangdang.ddframe.job.context.TaskContext in project elastic-job by dangdangdotcom.
the class CloudJobRestfulApiTest method assertFindAllRunningTasks.
@Test
public void assertFindAllRunningTasks() throws Exception {
RunningService runningService = new RunningService(getRegCenter());
TaskContext actualTaskContext = TaskContext.from(TaskNode.builder().build().getTaskNodeValue());
when(getRegCenter().get("/config/job/" + actualTaskContext.getMetaInfo().getJobName())).thenReturn(CloudJsonConstants.getJobJson());
runningService.add(actualTaskContext);
assertThat(sentGetRequest("http://127.0.0.1:19000/job/tasks/running"), is(GsonFactory.getGson().toJson(Lists.newArrayList(actualTaskContext))));
}
use of com.dangdang.ddframe.job.context.TaskContext in project elastic-job by dangdangdotcom.
the class FacadeServiceTest method assertRemoveRunning.
@Test
public void assertRemoveRunning() {
String taskNodeValue = TaskNode.builder().build().getTaskNodeValue();
TaskContext taskContext = TaskContext.from(taskNodeValue);
facadeService.removeRunning(taskContext);
verify(runningService).remove(taskContext);
}
use of com.dangdang.ddframe.job.context.TaskContext in project elastic-job by dangdangdotcom.
the class JobRunningStatisticJobTest method assertExecute.
@Test
public void assertExecute() throws SchedulerException {
Optional<JobRunningStatistics> latestJobRunningStatistics = Optional.of(new JobRunningStatistics(0, StatisticTimeUtils.getStatisticTime(StatisticInterval.MINUTE, -3)));
Optional<TaskRunningStatistics> latestTaskRunningStatistics = Optional.of(new TaskRunningStatistics(0, StatisticTimeUtils.getStatisticTime(StatisticInterval.MINUTE, -3)));
when(repository.findLatestJobRunningStatistics()).thenReturn(latestJobRunningStatistics);
when(repository.findLatestTaskRunningStatistics()).thenReturn(latestTaskRunningStatistics);
when(repository.add(any(JobRunningStatistics.class))).thenReturn(true);
when(repository.add(any(TaskRunningStatistics.class))).thenReturn(true);
Map<String, Set<TaskContext>> jobMap = new HashMap<>(1);
Set<TaskContext> jobSet = new HashSet<>(1);
jobSet.add(TaskContext.from(TaskNode.builder().jobName("test_job").build().getTaskNodeValue()));
jobMap.put("test_job", jobSet);
when(runningService.getAllRunningTasks()).thenReturn(jobMap);
jobRunningStatisticJob.execute(null);
verify(repository).findLatestJobRunningStatistics();
verify(repository).findLatestTaskRunningStatistics();
verify(repository, times(3)).add(any(JobRunningStatistics.class));
verify(repository, times(3)).add(any(TaskRunningStatistics.class));
verify(runningService).getAllRunningTasks();
}
use of com.dangdang.ddframe.job.context.TaskContext in project elastic-job by dangdangdotcom.
the class FacadeService method removeLaunchTasksFromQueue.
/**
* 从队列中删除已运行的作业.
*
* @param taskContexts 任务上下文集合
*/
public void removeLaunchTasksFromQueue(final List<TaskContext> taskContexts) {
List<TaskContext> failoverTaskContexts = new ArrayList<>(taskContexts.size());
Collection<String> readyJobNames = new HashSet<>(taskContexts.size(), 1);
for (TaskContext each : taskContexts) {
switch(each.getType()) {
case FAILOVER:
failoverTaskContexts.add(each);
break;
case READY:
readyJobNames.add(each.getMetaInfo().getJobName());
break;
default:
break;
}
}
failoverService.remove(Lists.transform(failoverTaskContexts, new Function<TaskContext, TaskContext.MetaInfo>() {
@Override
public TaskContext.MetaInfo apply(final TaskContext input) {
return input.getMetaInfo();
}
}));
readyService.remove(readyJobNames);
}
Aggregations