JobTransactionLogger { static String doFormat(JobManagerReconcilerEvent event) { if (event instanceof JobChangeReconcilerEvent.JobBeforeChangeReconcilerEvent) { return logJobBeforeChangeReconcilerEvent((JobChangeReconcilerEvent.JobBeforeChangeReconcilerEvent) event); } if (event instanceof JobChangeReconcilerEvent.JobAfterChangeReconcilerEvent) { return logJobAfterChangeReconcilerEvent((JobChangeReconcilerEvent.JobAfterChangeReconcilerEvent) event); } if (event instanceof JobChangeReconcilerEvent.JobChangeErrorReconcilerEvent) { return logJobChangeErrorReconcilerEvent((JobChangeReconcilerEvent.JobChangeErrorReconcilerEvent) event); } if (event instanceof JobModelReconcilerEvent.JobNewModelReconcilerEvent) { return logJobNewModelReconcilerEvent((JobModelReconcilerEvent.JobNewModelReconcilerEvent) event); } if (event instanceof JobModelReconcilerEvent.JobModelUpdateReconcilerEvent) { return logJobModelUpdateReconcilerEvent((JobModelReconcilerEvent.JobModelUpdateReconcilerEvent) event); } if (event instanceof JobModelReconcilerEvent.JobModelUpdateErrorReconcilerEvent) { return logJobModelUpdateErrorReconcilerEvent((JobModelReconcilerEvent.JobModelUpdateErrorReconcilerEvent) event); } return "Unknown event type: " + event.getClass(); }    }
@Test public void testLogFormatting() throws Exception { Job previousJob = createJob(); Job currentJob = previousJob.toBuilder().withStatus(JobStatus.newBuilder().withState(JobState.Finished).build()).build(); ModelActionHolder modelActionHolder = ModelActionHolder.reference( TitusModelAction.newModelUpdate("testModelAction") .job(previousJob) .trigger(Trigger.API) .summary("Job model update") .jobUpdate(jobHolder -> jobHolder.setEntity(currentJob)) ); TitusChangeAction changeAction = TitusChangeAction.newAction("testChangeAction") .job(previousJob) .trigger(Trigger.API) .summary("Job update") .applyModelUpdate(self -> modelActionHolder); JobManagerReconcilerEvent jobReconcilerEvent = new JobModelUpdateReconcilerEvent( previousJob, changeAction, modelActionHolder, EntityHolder.newRoot(currentJob.getId(), currentJob), Optional.of(EntityHolder.newRoot(previousJob.getId(), previousJob)), "1", CallMetadata.newBuilder().withCallerId("LoggerTest").withCallReason("Testing logger transaction").build() ); String logLine = JobTransactionLogger.doFormat(jobReconcilerEvent); assertThat(logLine).isNotEmpty(); logger.info("Job event: {}", logLine); }