@Test public void housekeepingPathRepositoryThrowsException() { Optional<BeekeeperEvent> event = Optional.of(newHousekeepingEvent(path, UNREFERENCED)); when(beekeeperEventReader.read()).thenReturn(event); doThrow(new BeekeeperException("exception")).when(pathSchedulerService).scheduleForHousekeeping(path); try { scheduler.scheduleBeekeeperEvent(); fail("Should have thrown exception"); } catch (Exception e) { verify(pathSchedulerService).scheduleForHousekeeping(path); verify(beekeeperEventReader, times(0)).delete(any()); verifyNoInteractions(tableSchedulerService); assertThat(e).isInstanceOf(BeekeeperException.class); assertThat(e.getMessage()).isEqualTo( format("Unable to schedule %s deletion for entity, this message will go back on the queue", path.getLifecycleType())); } }
@Transactional public void scheduleBeekeeperEvent() { Optional<BeekeeperEvent> housekeepingEntitiesToBeScheduled = beekeeperEventReader.read(); if (housekeepingEntitiesToBeScheduled.isEmpty()) { return; } BeekeeperEvent beekeeperEvent = housekeepingEntitiesToBeScheduled.get(); List<HousekeepingEntity> housekeepingEntities = beekeeperEvent.getHousekeepingEntities(); for (HousekeepingEntity entity : housekeepingEntities) { try { LifecycleEventType eventType = LifecycleEventType.valueOf(entity.getLifecycleType()); SchedulerService scheduler = schedulerServiceMap.get(eventType); scheduler.scheduleForHousekeeping(entity); } catch (Exception e) { throw new BeekeeperException(format( "Unable to schedule %s deletion for entity, this message will go back on the queue", entity.getLifecycleType()), e); } } beekeeperEventReader.delete(beekeeperEvent); }
SchedulerApiary { @Transactional public void scheduleBeekeeperEvent() { Optional<BeekeeperEvent> housekeepingEntitiesToBeScheduled = beekeeperEventReader.read(); if (housekeepingEntitiesToBeScheduled.isEmpty()) { return; } BeekeeperEvent beekeeperEvent = housekeepingEntitiesToBeScheduled.get(); List<HousekeepingEntity> housekeepingEntities = beekeeperEvent.getHousekeepingEntities(); for (HousekeepingEntity entity : housekeepingEntities) { try { LifecycleEventType eventType = LifecycleEventType.valueOf(entity.getLifecycleType()); SchedulerService scheduler = schedulerServiceMap.get(eventType); scheduler.scheduleForHousekeeping(entity); } catch (Exception e) { throw new BeekeeperException(format( "Unable to schedule %s deletion for entity, this message will go back on the queue", entity.getLifecycleType()), e); } } beekeeperEventReader.delete(beekeeperEvent); } }
SchedulerApiary { @Transactional public void scheduleBeekeeperEvent() { Optional<BeekeeperEvent> housekeepingEntitiesToBeScheduled = beekeeperEventReader.read(); if (housekeepingEntitiesToBeScheduled.isEmpty()) { return; } BeekeeperEvent beekeeperEvent = housekeepingEntitiesToBeScheduled.get(); List<HousekeepingEntity> housekeepingEntities = beekeeperEvent.getHousekeepingEntities(); for (HousekeepingEntity entity : housekeepingEntities) { try { LifecycleEventType eventType = LifecycleEventType.valueOf(entity.getLifecycleType()); SchedulerService scheduler = schedulerServiceMap.get(eventType); scheduler.scheduleForHousekeeping(entity); } catch (Exception e) { throw new BeekeeperException(format( "Unable to schedule %s deletion for entity, this message will go back on the queue", entity.getLifecycleType()), e); } } beekeeperEventReader.delete(beekeeperEvent); } @Autowired  SchedulerApiary(
      BeekeeperEventReader beekeeperEventReader,
      EnumMap<LifecycleEventType, SchedulerService> schedulerServiceMap
  ); }
SchedulerApiary { @Transactional public void scheduleBeekeeperEvent() { Optional<BeekeeperEvent> housekeepingEntitiesToBeScheduled = beekeeperEventReader.read(); if (housekeepingEntitiesToBeScheduled.isEmpty()) { return; } BeekeeperEvent beekeeperEvent = housekeepingEntitiesToBeScheduled.get(); List<HousekeepingEntity> housekeepingEntities = beekeeperEvent.getHousekeepingEntities(); for (HousekeepingEntity entity : housekeepingEntities) { try { LifecycleEventType eventType = LifecycleEventType.valueOf(entity.getLifecycleType()); SchedulerService scheduler = schedulerServiceMap.get(eventType); scheduler.scheduleForHousekeeping(entity); } catch (Exception e) { throw new BeekeeperException(format( "Unable to schedule %s deletion for entity, this message will go back on the queue", entity.getLifecycleType()), e); } } beekeeperEventReader.delete(beekeeperEvent); } @Autowired  SchedulerApiary(
      BeekeeperEventReader beekeeperEventReader,
      EnumMap<LifecycleEventType, SchedulerService> schedulerServiceMap
  ); @Transactional void scheduleBeekeeperEvent(); void close(); }
SchedulerApiary { @Transactional public void scheduleBeekeeperEvent() { Optional<BeekeeperEvent> housekeepingEntitiesToBeScheduled = beekeeperEventReader.read(); if (housekeepingEntitiesToBeScheduled.isEmpty()) { return; } BeekeeperEvent beekeeperEvent = housekeepingEntitiesToBeScheduled.get(); List<HousekeepingEntity> housekeepingEntities = beekeeperEvent.getHousekeepingEntities(); for (HousekeepingEntity entity : housekeepingEntities) { try { LifecycleEventType eventType = LifecycleEventType.valueOf(entity.getLifecycleType()); SchedulerService scheduler = schedulerServiceMap.get(eventType); scheduler.scheduleForHousekeeping(entity); } catch (Exception e) { throw new BeekeeperException(format( "Unable to schedule %s deletion for entity, this message will go back on the queue", entity.getLifecycleType()), e); } } beekeeperEventReader.delete(beekeeperEvent); } @Autowired  SchedulerApiary(
      BeekeeperEventReader beekeeperEventReader,
      EnumMap<LifecycleEventType, SchedulerService> schedulerServiceMap
  ); @Transactional void scheduleBeekeeperEvent(); void close();  }