Search in sources :

Example 6 with TaskResultStatistics

use of com.dangdang.ddframe.job.statistics.type.task.TaskResultStatistics in project elastic-job by dangdangdotcom.

the class StatisticManagerTest method assertTaskResultStatisticsWhenRdbIsConfigured.

@Test
public void assertTaskResultStatisticsWhenRdbIsConfigured() throws NoSuchFieldException {
    ReflectionUtils.setFieldValue(statisticManager, "rdbRepository", rdbRepository);
    when(rdbRepository.getSummedTaskResultStatistics(any(Date.class), any(StatisticInterval.class))).thenReturn(new TaskResultStatistics(10, 10, StatisticInterval.DAY, new Date()));
    assertThat(statisticManager.getTaskResultStatisticsWeekly().getSuccessCount(), is(10));
    assertThat(statisticManager.getTaskResultStatisticsWeekly().getFailedCount(), is(10));
    assertThat(statisticManager.getTaskResultStatisticsSinceOnline().getSuccessCount(), is(10));
    assertThat(statisticManager.getTaskResultStatisticsSinceOnline().getFailedCount(), is(10));
    verify(rdbRepository, times(4)).getSummedTaskResultStatistics(any(Date.class), 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 7 with TaskResultStatistics

use of com.dangdang.ddframe.job.statistics.type.task.TaskResultStatistics 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 8 with TaskResultStatistics

use of com.dangdang.ddframe.job.statistics.type.task.TaskResultStatistics 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)

Example 9 with TaskResultStatistics

use of com.dangdang.ddframe.job.statistics.type.task.TaskResultStatistics 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 10 with TaskResultStatistics

use of com.dangdang.ddframe.job.statistics.type.task.TaskResultStatistics 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)

Aggregations

TaskResultStatistics (com.dangdang.ddframe.job.statistics.type.task.TaskResultStatistics)16 Test (org.junit.Test)12 StatisticInterval (com.dangdang.ddframe.job.statistics.StatisticInterval)10 Date (java.util.Date)10 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 SimpleDateFormat (java.text.SimpleDateFormat)2 LinkedList (java.util.LinkedList)1