@Test public void testUpdateAgendaProgressException() { doThrow(new RuntimeException()).when(mockAgendaProgressClient).updateObject(any(), any()); Assert.assertFalse(consumer.updateAgendaProgress(AGENDA_PROGRESS_ID)); verify(mockAgendaProgressClient, times(1)).updateObject(any(), any()); }
protected boolean updateAgendaProgress(String agendaProgressId) { AgendaProgress agendaProgress = retrieveAgendaProgress(agendaProgressId); if(agendaProgress == null) return false; AgendaProgress updatedAgendaProgress = new AgendaProgress(); updatedAgendaProgress.setId(agendaProgressId); updatedAgendaProgress.setCustomerId(agendaProgress.getCustomerId()); updatedAgendaProgress.setProcessingState(ProcessingState.COMPLETE); updatedAgendaProgress.setProcessingStateMessage(CompleteStateMessage.FAILED.toString()); DiagnosticEvent diagnosticEvent = new DiagnosticEvent("AgendaProgress timed out."); DiagnosticEvent[] existingDiagnosticEvents = agendaProgress.getDiagnosticEvents(); if(existingDiagnosticEvents == null) updatedAgendaProgress.setDiagnosticEvents(new DiagnosticEvent[]{ diagnosticEvent }); else { LinkedList<DiagnosticEvent> existingEvents = new LinkedList<>(Arrays.asList(existingDiagnosticEvents)); existingEvents.add(diagnosticEvent); updatedAgendaProgress.setDiagnosticEvents(existingEvents.toArray(new DiagnosticEvent[0])); } try { logger.info("Reclaiming Agenda: {} Updating AgendaProgress: {}", agendaProgress.getAgendaId(), updatedAgendaProgress.getId()); if(!logReclaimOnly) agendaProgressClient.updateObject(updatedAgendaProgress, updatedAgendaProgress.getId()); } catch (Exception e) { logger.error(String.format("Failed to reclaim Agenda: %1$s", agendaProgress.getAgendaId()), e); return false; } return true; }
AgendaProgressTimeoutConsumer implements Consumer<String> { protected boolean updateAgendaProgress(String agendaProgressId) { AgendaProgress agendaProgress = retrieveAgendaProgress(agendaProgressId); if(agendaProgress == null) return false; AgendaProgress updatedAgendaProgress = new AgendaProgress(); updatedAgendaProgress.setId(agendaProgressId); updatedAgendaProgress.setCustomerId(agendaProgress.getCustomerId()); updatedAgendaProgress.setProcessingState(ProcessingState.COMPLETE); updatedAgendaProgress.setProcessingStateMessage(CompleteStateMessage.FAILED.toString()); DiagnosticEvent diagnosticEvent = new DiagnosticEvent("AgendaProgress timed out."); DiagnosticEvent[] existingDiagnosticEvents = agendaProgress.getDiagnosticEvents(); if(existingDiagnosticEvents == null) updatedAgendaProgress.setDiagnosticEvents(new DiagnosticEvent[]{ diagnosticEvent }); else { LinkedList<DiagnosticEvent> existingEvents = new LinkedList<>(Arrays.asList(existingDiagnosticEvents)); existingEvents.add(diagnosticEvent); updatedAgendaProgress.setDiagnosticEvents(existingEvents.toArray(new DiagnosticEvent[0])); } try { logger.info("Reclaiming Agenda: {} Updating AgendaProgress: {}", agendaProgress.getAgendaId(), updatedAgendaProgress.getId()); if(!logReclaimOnly) agendaProgressClient.updateObject(updatedAgendaProgress, updatedAgendaProgress.getId()); } catch (Exception e) { logger.error(String.format("Failed to reclaim Agenda: %1$s", agendaProgress.getAgendaId()), e); return false; } return true; } }
AgendaProgressTimeoutConsumer implements Consumer<String> { protected boolean updateAgendaProgress(String agendaProgressId) { AgendaProgress agendaProgress = retrieveAgendaProgress(agendaProgressId); if(agendaProgress == null) return false; AgendaProgress updatedAgendaProgress = new AgendaProgress(); updatedAgendaProgress.setId(agendaProgressId); updatedAgendaProgress.setCustomerId(agendaProgress.getCustomerId()); updatedAgendaProgress.setProcessingState(ProcessingState.COMPLETE); updatedAgendaProgress.setProcessingStateMessage(CompleteStateMessage.FAILED.toString()); DiagnosticEvent diagnosticEvent = new DiagnosticEvent("AgendaProgress timed out."); DiagnosticEvent[] existingDiagnosticEvents = agendaProgress.getDiagnosticEvents(); if(existingDiagnosticEvents == null) updatedAgendaProgress.setDiagnosticEvents(new DiagnosticEvent[]{ diagnosticEvent }); else { LinkedList<DiagnosticEvent> existingEvents = new LinkedList<>(Arrays.asList(existingDiagnosticEvents)); existingEvents.add(diagnosticEvent); updatedAgendaProgress.setDiagnosticEvents(existingEvents.toArray(new DiagnosticEvent[0])); } try { logger.info("Reclaiming Agenda: {} Updating AgendaProgress: {}", agendaProgress.getAgendaId(), updatedAgendaProgress.getId()); if(!logReclaimOnly) agendaProgressClient.updateObject(updatedAgendaProgress, updatedAgendaProgress.getId()); } catch (Exception e) { logger.error(String.format("Failed to reclaim Agenda: %1$s", agendaProgress.getAgendaId()), e); return false; } return true; } AgendaProgressTimeoutConsumer(HttpObjectClient<AgendaProgress> agendaProgressClient); }
AgendaProgressTimeoutConsumer implements Consumer<String> { protected boolean updateAgendaProgress(String agendaProgressId) { AgendaProgress agendaProgress = retrieveAgendaProgress(agendaProgressId); if(agendaProgress == null) return false; AgendaProgress updatedAgendaProgress = new AgendaProgress(); updatedAgendaProgress.setId(agendaProgressId); updatedAgendaProgress.setCustomerId(agendaProgress.getCustomerId()); updatedAgendaProgress.setProcessingState(ProcessingState.COMPLETE); updatedAgendaProgress.setProcessingStateMessage(CompleteStateMessage.FAILED.toString()); DiagnosticEvent diagnosticEvent = new DiagnosticEvent("AgendaProgress timed out."); DiagnosticEvent[] existingDiagnosticEvents = agendaProgress.getDiagnosticEvents(); if(existingDiagnosticEvents == null) updatedAgendaProgress.setDiagnosticEvents(new DiagnosticEvent[]{ diagnosticEvent }); else { LinkedList<DiagnosticEvent> existingEvents = new LinkedList<>(Arrays.asList(existingDiagnosticEvents)); existingEvents.add(diagnosticEvent); updatedAgendaProgress.setDiagnosticEvents(existingEvents.toArray(new DiagnosticEvent[0])); } try { logger.info("Reclaiming Agenda: {} Updating AgendaProgress: {}", agendaProgress.getAgendaId(), updatedAgendaProgress.getId()); if(!logReclaimOnly) agendaProgressClient.updateObject(updatedAgendaProgress, updatedAgendaProgress.getId()); } catch (Exception e) { logger.error(String.format("Failed to reclaim Agenda: %1$s", agendaProgress.getAgendaId()), e); return false; } return true; } AgendaProgressTimeoutConsumer(HttpObjectClient<AgendaProgress> agendaProgressClient); @Override ConsumerResult<String> consume(Collection<String> collection, Instant endProcessingInstant); boolean getLogReclaimOnly(); AgendaProgressTimeoutConsumer setLogReclaimOnly(boolean logReclaimOnly); }
AgendaProgressTimeoutConsumer implements Consumer<String> { protected boolean updateAgendaProgress(String agendaProgressId) { AgendaProgress agendaProgress = retrieveAgendaProgress(agendaProgressId); if(agendaProgress == null) return false; AgendaProgress updatedAgendaProgress = new AgendaProgress(); updatedAgendaProgress.setId(agendaProgressId); updatedAgendaProgress.setCustomerId(agendaProgress.getCustomerId()); updatedAgendaProgress.setProcessingState(ProcessingState.COMPLETE); updatedAgendaProgress.setProcessingStateMessage(CompleteStateMessage.FAILED.toString()); DiagnosticEvent diagnosticEvent = new DiagnosticEvent("AgendaProgress timed out."); DiagnosticEvent[] existingDiagnosticEvents = agendaProgress.getDiagnosticEvents(); if(existingDiagnosticEvents == null) updatedAgendaProgress.setDiagnosticEvents(new DiagnosticEvent[]{ diagnosticEvent }); else { LinkedList<DiagnosticEvent> existingEvents = new LinkedList<>(Arrays.asList(existingDiagnosticEvents)); existingEvents.add(diagnosticEvent); updatedAgendaProgress.setDiagnosticEvents(existingEvents.toArray(new DiagnosticEvent[0])); } try { logger.info("Reclaiming Agenda: {} Updating AgendaProgress: {}", agendaProgress.getAgendaId(), updatedAgendaProgress.getId()); if(!logReclaimOnly) agendaProgressClient.updateObject(updatedAgendaProgress, updatedAgendaProgress.getId()); } catch (Exception e) { logger.error(String.format("Failed to reclaim Agenda: %1$s", agendaProgress.getAgendaId()), e); return false; } return true; } AgendaProgressTimeoutConsumer(HttpObjectClient<AgendaProgress> agendaProgressClient); @Override ConsumerResult<String> consume(Collection<String> collection, Instant endProcessingInstant); boolean getLogReclaimOnly(); AgendaProgressTimeoutConsumer setLogReclaimOnly(boolean logReclaimOnly);  }