Search in sources :

Example 1 with JobRegisterStatistics

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

the class StatisticManagerTest method assertFindJobRegisterStatisticsWhenRdbIsConfigured.

@Test
public void assertFindJobRegisterStatisticsWhenRdbIsConfigured() throws NoSuchFieldException {
    ReflectionUtils.setFieldValue(statisticManager, "rdbRepository", rdbRepository);
    when(rdbRepository.findJobRegisterStatistics(any(Date.class))).thenReturn(Lists.newArrayList(new JobRegisterStatistics(10, new Date())));
    assertThat(statisticManager.findJobRegisterStatisticsSinceOnline().size(), is(1));
    verify(rdbRepository).findJobRegisterStatistics(any(Date.class));
}
Also used : JobRegisterStatistics(com.dangdang.ddframe.job.statistics.type.job.JobRegisterStatistics) Date(java.util.Date) Test(org.junit.Test)

Example 2 with JobRegisterStatistics

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

the class RegisteredJobStatisticJobTest method assertExecute.

@Test
public void assertExecute() throws SchedulerException {
    Optional<JobRegisterStatistics> latestOne = Optional.of(new JobRegisterStatistics(0, StatisticTimeUtils.getStatisticTime(StatisticInterval.DAY, -3)));
    when(repository.findLatestJobRegisterStatistics()).thenReturn(latestOne);
    when(repository.add(any(JobRegisterStatistics.class))).thenReturn(true);
    when(configurationService.loadAll()).thenReturn(Lists.newArrayList(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job")));
    registeredJobStatisticJob.execute(null);
    verify(repository).findLatestJobRegisterStatistics();
    verify(repository, times(3)).add(any(JobRegisterStatistics.class));
    verify(configurationService).loadAll();
}
Also used : JobRegisterStatistics(com.dangdang.ddframe.job.statistics.type.job.JobRegisterStatistics) Test(org.junit.Test)

Example 3 with JobRegisterStatistics

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

the class StatisticRdbRepository method findLatestJobRegisterStatistics.

/**
     * 获取最近一条作业注册统计数据.
     * 
     * @return 作业注册统计数据对象
     */
public Optional<JobRegisterStatistics> findLatestJobRegisterStatistics() {
    JobRegisterStatistics result = null;
    String sql = String.format("SELECT id, registered_count, statistics_time, creation_time FROM %s order by id DESC LIMIT 1", TABLE_JOB_REGISTER_STATISTICS);
    try (Connection conn = dataSource.getConnection();
        PreparedStatement preparedStatement = conn.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery()) {
        while (resultSet.next()) {
            result = new JobRegisterStatistics(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 jobRegisterStatistics from DB error:", ex);
    }
    return Optional.fromNullable(result);
}
Also used : JobRegisterStatistics(com.dangdang.ddframe.job.statistics.type.job.JobRegisterStatistics) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Date(java.util.Date)

Example 4 with JobRegisterStatistics

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

the class StatisticRdbRepository method findJobRegisterStatistics.

/**
     * 获取作业注册统计数据集合.
     * 
     * @param from 统计开始时间
     * @return 作业注册统计数据集合
     */
public List<JobRegisterStatistics> findJobRegisterStatistics(final Date from) {
    List<JobRegisterStatistics> result = new LinkedList<>();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String sql = String.format("SELECT id, registered_count, statistics_time, creation_time FROM %s WHERE statistics_time >= '%s' order by id ASC", TABLE_JOB_REGISTER_STATISTICS, formatter.format(from));
    try (Connection conn = dataSource.getConnection();
        PreparedStatement preparedStatement = conn.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery()) {
        while (resultSet.next()) {
            JobRegisterStatistics jobRegisterStatistics = new JobRegisterStatistics(resultSet.getLong(1), resultSet.getInt(2), new Date(resultSet.getTimestamp(3).getTime()), new Date(resultSet.getTimestamp(4).getTime()));
            result.add(jobRegisterStatistics);
        }
    } catch (final SQLException ex) {
        // TODO 记录失败直接输出日志,未来可考虑配置化
        log.error("Fetch jobRegisterStatistics from DB error:", ex);
    }
    return result;
}
Also used : JobRegisterStatistics(com.dangdang.ddframe.job.statistics.type.job.JobRegisterStatistics) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SimpleDateFormat(java.text.SimpleDateFormat) LinkedList(java.util.LinkedList) Date(java.util.Date)

Example 5 with JobRegisterStatistics

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

the class StatisticRdbRepositoryTest method assertFindLatestJobRegisterStatistics.

@Test
public void assertFindLatestJobRegisterStatistics() {
    repository.add(new JobRegisterStatistics(100, new Date()));
    repository.add(new JobRegisterStatistics(200, new Date()));
    Optional<JobRegisterStatistics> po = repository.findLatestJobRegisterStatistics();
    assertThat(po.get().getRegisteredCount(), is(200));
}
Also used : JobRegisterStatistics(com.dangdang.ddframe.job.statistics.type.job.JobRegisterStatistics) Date(java.util.Date) Test(org.junit.Test)

Aggregations

JobRegisterStatistics (com.dangdang.ddframe.job.statistics.type.job.JobRegisterStatistics)7 Date (java.util.Date)5 Test (org.junit.Test)4 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 SimpleDateFormat (java.text.SimpleDateFormat)1 LinkedList (java.util.LinkedList)1