@Test public void shouldAttemptCleanupWhenFinalState() { final Transition transition = createTransitionInState(RECHARGE_ACCEPTED_FINAL_STATE); when(repository.tryLock("2", 1, SECONDS)).thenReturn(Optional.of(lock)); when(lock.getLast()).thenReturn(transition); cleaner.cleanupIfFinalState("2", transition); verify(repository).tryLock(eq("2"), anyLong(), any(TimeUnit.class)); }
@VisibleForTesting void cleanupIfFinalState(String id, Transition transition) { if (transition.getState() instanceof FinalState) { Optional<Lock> lock = repository.tryLock(id, 1, SECONDS); try { lock.ifPresent(this::cleanupIfFinalizedTimeHasExpired); } finally { lock.ifPresent(Lock::unlock); } } }
CleanUpFinalisedStateMachines { @VisibleForTesting void cleanupIfFinalState(String id, Transition transition) { if (transition.getState() instanceof FinalState) { Optional<Lock> lock = repository.tryLock(id, 1, SECONDS); try { lock.ifPresent(this::cleanupIfFinalizedTimeHasExpired); } finally { lock.ifPresent(Lock::unlock); } } } }
CleanUpFinalisedStateMachines { @VisibleForTesting void cleanupIfFinalState(String id, Transition transition) { if (transition.getState() instanceof FinalState) { Optional<Lock> lock = repository.tryLock(id, 1, SECONDS); try { lock.ifPresent(this::cleanupIfFinalizedTimeHasExpired); } finally { lock.ifPresent(Lock::unlock); } } } CleanUpFinalisedStateMachines(TransitionRepository repository,
                                         Collection<OnCleanupListener> cleanupListeners,
                                         long scheduleFrequency, TimeUnit scheduleTimeUnit,
                                         long keepFinalised, ChronoUnit keepFinalisedTimeUnit); }
CleanUpFinalisedStateMachines { @VisibleForTesting void cleanupIfFinalState(String id, Transition transition) { if (transition.getState() instanceof FinalState) { Optional<Lock> lock = repository.tryLock(id, 1, SECONDS); try { lock.ifPresent(this::cleanupIfFinalizedTimeHasExpired); } finally { lock.ifPresent(Lock::unlock); } } } CleanUpFinalisedStateMachines(TransitionRepository repository,
                                         Collection<OnCleanupListener> cleanupListeners,
                                         long scheduleFrequency, TimeUnit scheduleTimeUnit,
                                         long keepFinalised, ChronoUnit keepFinalisedTimeUnit); void startScheduler(); void stopScheduler(); void checkForFinalizedStateMachinesAndCleanupIfRequired(); }
CleanUpFinalisedStateMachines { @VisibleForTesting void cleanupIfFinalState(String id, Transition transition) { if (transition.getState() instanceof FinalState) { Optional<Lock> lock = repository.tryLock(id, 1, SECONDS); try { lock.ifPresent(this::cleanupIfFinalizedTimeHasExpired); } finally { lock.ifPresent(Lock::unlock); } } } CleanUpFinalisedStateMachines(TransitionRepository repository,
                                         Collection<OnCleanupListener> cleanupListeners,
                                         long scheduleFrequency, TimeUnit scheduleTimeUnit,
                                         long keepFinalised, ChronoUnit keepFinalisedTimeUnit); void startScheduler(); void stopScheduler(); void checkForFinalizedStateMachinesAndCleanupIfRequired();  }