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