Search in sources :

Example 6 with StatisticInterval

use of com.dangdang.ddframe.job.statistics.StatisticInterval in project elastic-job by dangdangdotcom.

the class StatisticRdbRepositoryTest method assertFindLatestTaskResultStatistics.

@Test
public void assertFindLatestTaskResultStatistics() {
    for (StatisticInterval each : StatisticInterval.values()) {
        repository.add(new TaskResultStatistics(100, 2, each, new Date()));
        repository.add(new TaskResultStatistics(200, 5, each, new Date()));
        Optional<TaskResultStatistics> po = repository.findLatestTaskResultStatistics(each);
        assertThat(po.get().getSuccessCount(), is(200));
        assertThat(po.get().getFailedCount(), is(5));
    }
}
Also used : TaskResultStatistics(com.dangdang.ddframe.job.statistics.type.task.TaskResultStatistics) Date(java.util.Date) StatisticInterval(com.dangdang.ddframe.job.statistics.StatisticInterval) Test(org.junit.Test)

Example 7 with StatisticInterval

use of com.dangdang.ddframe.job.statistics.StatisticInterval in project elastic-job by dangdangdotcom.

the class StatisticRdbRepositoryTest method assertGetSummedTaskResultStatistics.

@Test
public void assertGetSummedTaskResultStatistics() {
    for (StatisticInterval each : StatisticInterval.values()) {
        Date date = new Date();
        repository.add(new TaskResultStatistics(100, 2, each, date));
        repository.add(new TaskResultStatistics(200, 5, each, date));
        TaskResultStatistics po = repository.getSummedTaskResultStatistics(date, each);
        assertThat(po.getSuccessCount(), is(300));
        assertThat(po.getFailedCount(), is(7));
    }
}
Also used : TaskResultStatistics(com.dangdang.ddframe.job.statistics.type.task.TaskResultStatistics) Date(java.util.Date) StatisticInterval(com.dangdang.ddframe.job.statistics.StatisticInterval) Test(org.junit.Test)

Example 8 with StatisticInterval

use of com.dangdang.ddframe.job.statistics.StatisticInterval 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));
    }
}
Also used : TaskResultStatistics(com.dangdang.ddframe.job.statistics.type.task.TaskResultStatistics) StatisticInterval(com.dangdang.ddframe.job.statistics.StatisticInterval) Test(org.junit.Test)

Example 9 with StatisticInterval

use of com.dangdang.ddframe.job.statistics.StatisticInterval 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));
}
Also used : TaskResultStatistics(com.dangdang.ddframe.job.statistics.type.task.TaskResultStatistics) StatisticInterval(com.dangdang.ddframe.job.statistics.StatisticInterval) Test(org.junit.Test)

Aggregations

StatisticInterval (com.dangdang.ddframe.job.statistics.StatisticInterval)9 Test (org.junit.Test)9 TaskResultStatistics (com.dangdang.ddframe.job.statistics.type.task.TaskResultStatistics)8 Date (java.util.Date)5 Trigger (org.quartz.Trigger)1