Search in sources :

Example 1 with JobExecutionEvent

use of com.dangdang.ddframe.job.event.type.JobExecutionEvent in project elastic-job by dangdangdotcom.

the class JobEventRdbStorageTest method assertUpdateJobExecutionEventWhenSuccess.

@Test
public void assertUpdateJobExecutionEventWhenSuccess() throws SQLException {
    JobExecutionEvent startEvent = new JobExecutionEvent("fake_task_id", "test_job", ExecutionSource.NORMAL_TRIGGER, 0);
    assertTrue(storage.addJobExecutionEvent(startEvent));
    JobExecutionEvent successEvent = startEvent.executionSuccess();
    assertTrue(storage.addJobExecutionEvent(successEvent));
}
Also used : JobExecutionEvent(com.dangdang.ddframe.job.event.type.JobExecutionEvent) Test(org.junit.Test)

Example 2 with JobExecutionEvent

use of com.dangdang.ddframe.job.event.type.JobExecutionEvent in project elastic-job by dangdangdotcom.

the class JobEventRdbStorageTest method assertUpdateJobExecutionEventWhenSuccessAndConflict.

@Test
public void assertUpdateJobExecutionEventWhenSuccessAndConflict() throws SQLException {
    JobExecutionEvent startEvent = new JobExecutionEvent("fake_task_id", "test_job", ExecutionSource.NORMAL_TRIGGER, 0);
    JobExecutionEvent successEvent = startEvent.executionSuccess();
    assertTrue(storage.addJobExecutionEvent(successEvent));
    assertFalse(storage.addJobExecutionEvent(startEvent));
}
Also used : JobExecutionEvent(com.dangdang.ddframe.job.event.type.JobExecutionEvent) Test(org.junit.Test)

Example 3 with JobExecutionEvent

use of com.dangdang.ddframe.job.event.type.JobExecutionEvent in project elastic-job by dangdangdotcom.

the class JobEventRdbStorageTest method assertUpdateJobExecutionEventWhenFailureAndConflict.

@Test
public void assertUpdateJobExecutionEventWhenFailureAndConflict() throws SQLException {
    JobExecutionEvent startEvent = new JobExecutionEvent("fake_task_id", "test_job", ExecutionSource.NORMAL_TRIGGER, 0);
    JobExecutionEvent failureEvent = startEvent.executionFailure(new RuntimeException("failure"));
    assertTrue(storage.addJobExecutionEvent(failureEvent));
    assertThat(failureEvent.getFailureCause(), startsWith("java.lang.RuntimeException: failure"));
    assertFalse(storage.addJobExecutionEvent(startEvent));
}
Also used : JobExecutionEvent(com.dangdang.ddframe.job.event.type.JobExecutionEvent) Test(org.junit.Test)

Example 4 with JobExecutionEvent

use of com.dangdang.ddframe.job.event.type.JobExecutionEvent in project elastic-job by dangdangdotcom.

the class JobEventRdbStorageTest method assertUpdateJobExecutionEventWhenFailure.

@Test
public void assertUpdateJobExecutionEventWhenFailure() throws SQLException {
    JobExecutionEvent startEvent = new JobExecutionEvent("fake_task_id", "test_job", ExecutionSource.NORMAL_TRIGGER, 0);
    assertTrue(storage.addJobExecutionEvent(startEvent));
    JobExecutionEvent failureEvent = startEvent.executionFailure(new RuntimeException("failure"));
    assertTrue(storage.addJobExecutionEvent(failureEvent));
    assertThat(failureEvent.getFailureCause(), startsWith("java.lang.RuntimeException: failure"));
}
Also used : JobExecutionEvent(com.dangdang.ddframe.job.event.type.JobExecutionEvent) Test(org.junit.Test)

Example 5 with JobExecutionEvent

use of com.dangdang.ddframe.job.event.type.JobExecutionEvent 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)

Aggregations

JobExecutionEvent (com.dangdang.ddframe.job.event.type.JobExecutionEvent)24 Test (org.junit.Test)20 Condition (com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Condition)8 Date (java.util.Date)2 HashMap (java.util.HashMap)2 ShardingContext (com.dangdang.ddframe.job.api.ShardingContext)1 TestJobEventConfiguration (com.dangdang.ddframe.job.event.fixture.TestJobEventConfiguration)1 JobExecutionEventThrowable (com.dangdang.ddframe.job.event.type.JobExecutionEventThrowable)1 JobStatusTraceEvent (com.dangdang.ddframe.job.event.type.JobStatusTraceEvent)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 LinkedList (java.util.LinkedList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1