use of com.dangdang.ddframe.job.statistics.type.task.TaskRunningStatistics in project elastic-job by dangdangdotcom.
the class StatisticRdbRepositoryTest method assertFindLatestTaskRunningStatistics.
@Test
public void assertFindLatestTaskRunningStatistics() {
repository.add(new TaskRunningStatistics(100, new Date()));
repository.add(new TaskRunningStatistics(200, new Date()));
Optional<TaskRunningStatistics> po = repository.findLatestTaskRunningStatistics();
assertThat(po.get().getRunningCount(), is(200));
}
use of com.dangdang.ddframe.job.statistics.type.task.TaskRunningStatistics in project elastic-job by dangdangdotcom.
the class StatisticRdbRepositoryTest method assertFindTaskRunningStatisticsWithDifferentFromDate.
@Test
public void assertFindTaskRunningStatisticsWithDifferentFromDate() {
Date now = new Date();
Date yesterday = getYesterday();
assertTrue(repository.add(new TaskRunningStatistics(100, yesterday)));
assertTrue(repository.add(new TaskRunningStatistics(100, now)));
assertThat(repository.findTaskRunningStatistics(yesterday).size(), is(2));
assertThat(repository.findTaskRunningStatistics(now).size(), is(1));
}
use of com.dangdang.ddframe.job.statistics.type.task.TaskRunningStatistics in project elastic-job by dangdangdotcom.
the class JobRunningStatisticJob method statisticTask.
private void statisticTask(final int runningCount) {
Optional<TaskRunningStatistics> latestOne = repository.findLatestTaskRunningStatistics();
if (latestOne.isPresent()) {
fillBlankIfNeeded(latestOne.get());
}
TaskRunningStatistics taskRunningStatistics = new TaskRunningStatistics(runningCount, StatisticTimeUtils.getCurrentStatisticTime(execInterval));
log.debug("Add taskRunningStatistics, runningCount is:{}", runningCount);
repository.add(taskRunningStatistics);
}
use of com.dangdang.ddframe.job.statistics.type.task.TaskRunningStatistics in project elastic-job by dangdangdotcom.
the class StatisticManagerTest method assertFindTaskRunningStatisticsWhenRdbIsConfigured.
@Test
public void assertFindTaskRunningStatisticsWhenRdbIsConfigured() throws NoSuchFieldException {
ReflectionUtils.setFieldValue(statisticManager, "rdbRepository", rdbRepository);
when(rdbRepository.findTaskRunningStatistics(any(Date.class))).thenReturn(Lists.newArrayList(new TaskRunningStatistics(10, new Date())));
assertThat(statisticManager.findTaskRunningStatisticsWeekly().size(), is(1));
verify(rdbRepository).findTaskRunningStatistics(any(Date.class));
}
use of com.dangdang.ddframe.job.statistics.type.task.TaskRunningStatistics in project elastic-job by dangdangdotcom.
the class StatisticRdbRepository method findLatestTaskRunningStatistics.
/**
* 获取最近一条运行中的任务统计数据.
*
* @return 运行中的任务统计数据对象
*/
public Optional<TaskRunningStatistics> findLatestTaskRunningStatistics() {
TaskRunningStatistics result = null;
String sql = String.format("SELECT id, running_count, statistics_time, creation_time FROM %s order by id DESC LIMIT 1", TABLE_TASK_RUNNING_STATISTICS);
try (Connection conn = dataSource.getConnection();
PreparedStatement preparedStatement = conn.prepareStatement(sql);
ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
result = new TaskRunningStatistics(resultSet.getLong(1), resultSet.getInt(2), new Date(resultSet.getTimestamp(3).getTime()), new Date(resultSet.getTimestamp(4).getTime()));
}
} catch (final SQLException ex) {
// TODO 记录失败直接输出日志,未来可考虑配置化
log.error("Fetch latest taskRunningStatistics from DB error:", ex);
}
return Optional.fromNullable(result);
}
Aggregations