Search in sources :

Example 26 with Date

use of java.util.Date in project elastic-job by dangdangdotcom.

the class JobEventRdbSearch method getJobExecutionEvents.

private List<JobExecutionEvent> getJobExecutionEvents(final Condition condition) {
    List<JobExecutionEvent> result = new LinkedList<>();
    try (Connection conn = dataSource.getConnection();
        PreparedStatement preparedStatement = createDataPreparedStatement(conn, TABLE_JOB_EXECUTION_LOG, FIELDS_JOB_EXECUTION_LOG, condition);
        ResultSet resultSet = preparedStatement.executeQuery()) {
        while (resultSet.next()) {
            JobExecutionEvent jobExecutionEvent = new JobExecutionEvent(resultSet.getString(1), resultSet.getString(2), resultSet.getString(3), resultSet.getString(4), resultSet.getString(5), JobExecutionEvent.ExecutionSource.valueOf(resultSet.getString(6)), Integer.valueOf(resultSet.getString(7)), new Date(resultSet.getTimestamp(8).getTime()), resultSet.getTimestamp(9) == null ? null : new Date(resultSet.getTimestamp(9).getTime()), resultSet.getBoolean(10), new JobExecutionEventThrowable(null, resultSet.getString(11)));
            result.add(jobExecutionEvent);
        }
    } catch (final SQLException ex) {
        // TODO 记录失败直接输出日志,未来可考虑配置化
        log.error("Fetch JobExecutionEvent from DB error:", ex);
    }
    return result;
}
Also used : JobExecutionEvent(com.dangdang.ddframe.job.event.type.JobExecutionEvent) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) JobExecutionEventThrowable(com.dangdang.ddframe.job.event.type.JobExecutionEventThrowable) LinkedList(java.util.LinkedList) Date(java.util.Date)

Example 27 with Date

use of java.util.Date 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));
}
Also used : TaskRunningStatistics(com.dangdang.ddframe.job.statistics.type.task.TaskRunningStatistics) Date(java.util.Date) Test(org.junit.Test)

Example 28 with Date

use of java.util.Date in project elastic-job by dangdangdotcom.

the class StatisticRdbRepositoryTest method assertFindTaskResultStatisticsWhenTableIsEmpty.

@Test
public void assertFindTaskResultStatisticsWhenTableIsEmpty() {
    assertThat(repository.findTaskResultStatistics(new Date(), StatisticInterval.MINUTE).size(), is(0));
    assertThat(repository.findTaskResultStatistics(new Date(), StatisticInterval.HOUR).size(), is(0));
    assertThat(repository.findTaskResultStatistics(new Date(), StatisticInterval.DAY).size(), is(0));
}
Also used : Date(java.util.Date) Test(org.junit.Test)

Example 29 with Date

use of java.util.Date 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 30 with Date

use of java.util.Date 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));
}
Also used : Date(java.util.Date) TaskRunningStatistics(com.dangdang.ddframe.job.statistics.type.task.TaskRunningStatistics) Test(org.junit.Test)

Aggregations

Date (java.util.Date)33499 Test (org.junit.Test)8112 SimpleDateFormat (java.text.SimpleDateFormat)4502 ArrayList (java.util.ArrayList)3177 Calendar (java.util.Calendar)2351 HashMap (java.util.HashMap)1985 IOException (java.io.IOException)1914 File (java.io.File)1649 ParseException (java.text.ParseException)1578 List (java.util.List)1106 DateFormat (java.text.DateFormat)1022 Map (java.util.Map)983 GregorianCalendar (java.util.GregorianCalendar)884 Test (org.junit.jupiter.api.Test)853 HashSet (java.util.HashSet)576 Test (org.testng.annotations.Test)527 Timestamp (java.sql.Timestamp)458 BigDecimal (java.math.BigDecimal)436 LocalDate (java.time.LocalDate)423 DateTime (org.joda.time.DateTime)391