### Question:
JobEventRdbStorage { boolean addJobExecutionEvent(final JobExecutionEvent jobExecutionEvent) { if (null == jobExecutionEvent.getCompleteTime()) { return insertJobExecutionEvent(jobExecutionEvent); } else { if (jobExecutionEvent.isSuccess()) { return updateJobExecutionEventWhenSuccess(jobExecutionEvent); } else { return updateJobExecutionEventFailure(jobExecutionEvent); } } } JobEventRdbStorage(final DataSource dataSource);   }### Answer:
@Test public void assertUpdateJobExecutionEventWhenSuccess() throws SQLException { JobExecutionEvent startEvent = new JobExecutionEvent("fake_task_id", "test_job", JobExecutionEvent.ExecutionSource.NORMAL_TRIGGER, 0); Assert.assertTrue(storage.addJobExecutionEvent(startEvent)); JobExecutionEvent successEvent = startEvent.executionSuccess(); Assert.assertTrue(storage.addJobExecutionEvent(successEvent)); }
@Test public void assertUpdateJobExecutionEventWhenFailure() throws SQLException { JobExecutionEvent startEvent = new JobExecutionEvent("fake_task_id", "test_job", JobExecutionEvent.ExecutionSource.NORMAL_TRIGGER, 0); Assert.assertTrue(storage.addJobExecutionEvent(startEvent)); JobExecutionEvent failureEvent = startEvent.executionFailure(new RuntimeException("failure")); Assert.assertTrue(storage.addJobExecutionEvent(failureEvent)); Assert.assertThat(failureEvent.getFailureCause(), CoreMatchers.startsWith("java.lang.RuntimeException: failure")); Assert.assertTrue(null != failureEvent.getCompleteTime()); }
@Test public void assertUpdateJobExecutionEventWhenSuccessAndConflict() throws SQLException { JobExecutionEvent startEvent = new JobExecutionEvent("fake_task_id", "test_job", JobExecutionEvent.ExecutionSource.NORMAL_TRIGGER, 0); JobExecutionEvent successEvent = startEvent.executionSuccess(); Assert.assertTrue(storage.addJobExecutionEvent(successEvent)); Assert.assertFalse(storage.addJobExecutionEvent(startEvent)); }
@Test public void assertUpdateJobExecutionEventWhenFailureAndConflict() throws SQLException { JobExecutionEvent startEvent = new JobExecutionEvent("fake_task_id", "test_job", JobExecutionEvent.ExecutionSource.NORMAL_TRIGGER, 0); JobExecutionEvent failureEvent = startEvent.executionFailure(new RuntimeException("failure")); Assert.assertTrue(storage.addJobExecutionEvent(failureEvent)); Assert.assertThat(failureEvent.getFailureCause(), CoreMatchers.startsWith("java.lang.RuntimeException: failure")); Assert.assertFalse(storage.addJobExecutionEvent(startEvent)); }
@Test public void assertUpdateJobExecutionEventWhenFailureAndMessageExceed() throws SQLException { JobExecutionEvent startEvent = new JobExecutionEvent("fake_task_id", "test_job", JobExecutionEvent.ExecutionSource.NORMAL_TRIGGER, 0); Assert.assertTrue(storage.addJobExecutionEvent(startEvent)); StringBuilder failureMsg = new StringBuilder(); for (int i = 0; i < 600; i++) { failureMsg.append(i); } JobExecutionEvent failEvent = startEvent.executionFailure(new RuntimeException("failure" + failureMsg.toString())); Assert.assertTrue(storage.addJobExecutionEvent(failEvent)); Assert.assertThat(failEvent.getFailureCause(), CoreMatchers.startsWith("java.lang.RuntimeException: failure")); }
@Test public void assertFindJobExecutionEvent() throws SQLException { storage.addJobExecutionEvent(new JobExecutionEvent("fake_task_id", "test_job", JobExecutionEvent.ExecutionSource.NORMAL_TRIGGER, 0)); }
@Test public void assertAddJobExecutionEvent() throws SQLException { Assert.assertTrue(storage.addJobExecutionEvent(new JobExecutionEvent("fake_task_id", "test_job", JobExecutionEvent.ExecutionSource.NORMAL_TRIGGER, 0))); }