Search in sources :

Example 1 with StatisticInterval

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

the class TaskResultStatisticJobTest method assertExecuteWhenRepositoryIsEmpty.

@Test
public void assertExecuteWhenRepositoryIsEmpty() throws SchedulerException {
    Optional<TaskResultStatistics> latestOne = Optional.absent();
    for (StatisticInterval each : StatisticInterval.values()) {
        taskResultStatisticJob.setStatisticInterval(each);
        when(repository.findLatestTaskResultStatistics(each)).thenReturn(latestOne);
        when(repository.add(any(TaskResultStatistics.class))).thenReturn(true);
        taskResultStatisticJob.execute(null);
        verify(repository).findLatestTaskResultStatistics(each);
    }
    verify(repository, times(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)

Example 2 with StatisticInterval

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

the class TaskResultStatisticJobTest method assertBuildTrigger.

@Test
public void assertBuildTrigger() throws SchedulerException {
    for (StatisticInterval each : StatisticInterval.values()) {
        taskResultStatisticJob.setStatisticInterval(each);
        Trigger trigger = taskResultStatisticJob.buildTrigger();
        assertThat(trigger.getKey().getName(), is(TaskResultStatisticJob.class.getSimpleName() + "Trigger" + "_" + each));
    }
}
Also used : Trigger(org.quartz.Trigger) StatisticInterval(com.dangdang.ddframe.job.statistics.StatisticInterval) Test(org.junit.Test)

Example 3 with StatisticInterval

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

the class StatisticRdbRepositoryTest method assertFindTaskResultStatisticsWithDifferentFromDate.

@Test
public void assertFindTaskResultStatisticsWithDifferentFromDate() {
    Date now = new Date();
    Date yesterday = getYesterday();
    for (StatisticInterval each : StatisticInterval.values()) {
        assertTrue(repository.add(new TaskResultStatistics(100, 0, each, yesterday)));
        assertTrue(repository.add(new TaskResultStatistics(100, 0, each, now)));
        assertThat(repository.findTaskResultStatistics(yesterday, each).size(), is(2));
        assertThat(repository.findTaskResultStatistics(now, each).size(), is(1));
    }
}
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 4 with StatisticInterval

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

the class StatisticManagerTest method assertFindLatestTaskResultStatisticsWhenRdbIsConfigured.

@Test
public void assertFindLatestTaskResultStatisticsWhenRdbIsConfigured() throws NoSuchFieldException {
    ReflectionUtils.setFieldValue(statisticManager, "rdbRepository", rdbRepository);
    for (StatisticInterval each : StatisticInterval.values()) {
        when(rdbRepository.findLatestTaskResultStatistics(each)).thenReturn(Optional.of(new TaskResultStatistics(10, 5, each, new Date())));
        TaskResultStatistics actual = statisticManager.findLatestTaskResultStatistics(each);
        assertThat(actual.getSuccessCount(), is(10));
        assertThat(actual.getFailedCount(), is(5));
    }
    verify(rdbRepository, times(StatisticInterval.values().length)).findLatestTaskResultStatistics(any(StatisticInterval.class));
}
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 5 with StatisticInterval

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

the class StatisticRdbRepositoryTest method assertGetSummedTaskResultStatisticsWhenTableIsEmpty.

@Test
public void assertGetSummedTaskResultStatisticsWhenTableIsEmpty() {
    for (StatisticInterval each : StatisticInterval.values()) {
        TaskResultStatistics po = repository.getSummedTaskResultStatistics(new Date(), each);
        assertThat(po.getSuccessCount(), is(0));
        assertThat(po.getFailedCount(), is(0));
    }
}
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)

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