@Test public void shouldNotAttemptCleanupWhenNonFinalState() { cleaner.cleanupIfFinalState("1", createTransitionInState(RECHARGE_REQUESTED_STATE)); verify(repository, never()).tryLock(eq("1"), 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();  }