Search in sources :

Example 11 with TaskResultStatistics

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

Example 12 with TaskResultStatistics

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));
}
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 13 with TaskResultStatistics

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

Example 14 with TaskResultStatistics

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

Example 15 with TaskResultStatistics

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

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