use of com.dangdang.ddframe.job.statistics.type.task.TaskResultStatistics in project elastic-job by dangdangdotcom.
the class CloudJobRestfulApiTest method assertGetTaskResultStatisticsWithPathParameter.
@Test
public void assertGetTaskResultStatisticsWithPathParameter() throws Exception {
String[] parameters = { "online", "lastWeek", "lastHour", "lastMinute" };
for (String each : parameters) {
String result = sentGetRequest("http://127.0.0.1:19000/job/statistics/tasks/results/" + each);
TaskResultStatistics taskResultStatistics = GsonFactory.getGson().fromJson(result, TaskResultStatistics.class);
assertThat(taskResultStatistics.getSuccessCount(), is(0));
assertThat(taskResultStatistics.getFailedCount(), is(0));
}
}
use of com.dangdang.ddframe.job.statistics.type.task.TaskResultStatistics in project elastic-job by dangdangdotcom.
the class StatisticManagerTest method assertFindTaskResultStatisticsDailyWhenRdbIsConfigured.
@Test
public void assertFindTaskResultStatisticsDailyWhenRdbIsConfigured() throws NoSuchFieldException {
ReflectionUtils.setFieldValue(statisticManager, "rdbRepository", rdbRepository);
when(rdbRepository.findTaskResultStatistics(any(Date.class), any(StatisticInterval.class))).thenReturn(Lists.newArrayList(new TaskResultStatistics(10, 5, StatisticInterval.MINUTE, new Date())));
assertThat(statisticManager.findTaskResultStatisticsDaily().size(), is(1));
verify(rdbRepository).findTaskResultStatistics(any(Date.class), any(StatisticInterval.class));
}
use of com.dangdang.ddframe.job.statistics.type.task.TaskResultStatistics in project elastic-job by dangdangdotcom.
the class StatisticManagerTest method assertFindLatestTaskResultStatisticsWhenRdbIsNotConfigured.
@Test
public void assertFindLatestTaskResultStatisticsWhenRdbIsNotConfigured() throws NoSuchFieldException {
ReflectionUtils.setFieldValue(statisticManager, "rdbRepository", null);
for (StatisticInterval each : StatisticInterval.values()) {
TaskResultStatistics actual = statisticManager.findLatestTaskResultStatistics(each);
assertThat(actual.getSuccessCount(), is(0));
assertThat(actual.getFailedCount(), is(0));
}
}
use of com.dangdang.ddframe.job.statistics.type.task.TaskResultStatistics in project elastic-job by dangdangdotcom.
the class TaskResultStatisticJobTest method assertExecute.
@Test
public void assertExecute() throws SchedulerException {
for (StatisticInterval each : StatisticInterval.values()) {
taskResultStatisticJob.setStatisticInterval(each);
Optional<TaskResultStatistics> latestOne = Optional.of(new TaskResultStatistics(0, 0, each, StatisticTimeUtils.getStatisticTime(each, -3)));
when(repository.findLatestTaskResultStatistics(each)).thenReturn(latestOne);
when(repository.add(any(TaskResultStatistics.class))).thenReturn(true);
taskResultStatisticJob.execute(null);
verify(repository).findLatestTaskResultStatistics(each);
}
verify(repository, times(StatisticInterval.values().length * 3)).add(any(TaskResultStatistics.class));
}
use of com.dangdang.ddframe.job.statistics.type.task.TaskResultStatistics in project elastic-job by dangdangdotcom.
the class TaskResultStatisticJob method execute.
@Override
public void execute(final JobExecutionContext context) throws JobExecutionException {
Optional<TaskResultStatistics> latestOne = repository.findLatestTaskResultStatistics(statisticInterval);
if (latestOne.isPresent()) {
fillBlankIfNeeded(latestOne.get());
}
TaskResultStatistics taskResultStatistics = new TaskResultStatistics(sharedData.getSuccessCount(), sharedData.getFailedCount(), statisticInterval, StatisticTimeUtils.getCurrentStatisticTime(statisticInterval));
log.debug("Add taskResultStatistics, statisticInterval is:{}, successCount is:{}, failedCount is:{}", statisticInterval, sharedData.getSuccessCount(), sharedData.getFailedCount());
repository.add(taskResultStatistics);
sharedData.reset();
}
Aggregations