@Test public void sleepsForLongerDurationIfCompactFails() { assertThat(BackgroundCompactor.getSleepTime( () -> COMPACTOR_CONFIG, BackgroundCompactor.CompactionOutcome.FAILED_TO_COMPACT)) .isEqualTo(COMPACT_PAUSE_ON_FAILURE_MILLIS); assertThat(BackgroundCompactor.getSleepTime( () -> COMPACTOR_CONFIG, BackgroundCompactor.CompactionOutcome.UNABLE_TO_ACQUIRE_LOCKS)) .isEqualTo(COMPACT_PAUSE_ON_FAILURE_MILLIS); }
@VisibleForTesting static long getSleepTime( Supplier<CompactorConfig> compactorConfigSupplier, CompactionOutcome outcome) { switch (outcome) { case SUCCESS: case COMPACTED_BUT_NOT_REGISTERED: case SHUTDOWN: return compactorConfigSupplier.get().compactPauseMillis(); case NOTHING_TO_COMPACT: case DISABLED: return Math.max(compactorConfigSupplier.get().compactPauseMillis(), SLEEP_TIME_WHEN_NOTHING_TO_COMPACT_MIN_MILLIS); case UNABLE_TO_ACQUIRE_LOCKS: case FAILED_TO_COMPACT: return compactorConfigSupplier.get().compactPauseOnFailureMillis(); default: throw new IllegalStateException("Unexpected outcome enum type: " + outcome); } }
BackgroundCompactor implements AutoCloseable { @VisibleForTesting static long getSleepTime( Supplier<CompactorConfig> compactorConfigSupplier, CompactionOutcome outcome) { switch (outcome) { case SUCCESS: case COMPACTED_BUT_NOT_REGISTERED: case SHUTDOWN: return compactorConfigSupplier.get().compactPauseMillis(); case NOTHING_TO_COMPACT: case DISABLED: return Math.max(compactorConfigSupplier.get().compactPauseMillis(), SLEEP_TIME_WHEN_NOTHING_TO_COMPACT_MIN_MILLIS); case UNABLE_TO_ACQUIRE_LOCKS: case FAILED_TO_COMPACT: return compactorConfigSupplier.get().compactPauseOnFailureMillis(); default: throw new IllegalStateException("Unexpected outcome enum type: " + outcome); } } }
BackgroundCompactor implements AutoCloseable { @VisibleForTesting static long getSleepTime( Supplier<CompactorConfig> compactorConfigSupplier, CompactionOutcome outcome) { switch (outcome) { case SUCCESS: case COMPACTED_BUT_NOT_REGISTERED: case SHUTDOWN: return compactorConfigSupplier.get().compactPauseMillis(); case NOTHING_TO_COMPACT: case DISABLED: return Math.max(compactorConfigSupplier.get().compactPauseMillis(), SLEEP_TIME_WHEN_NOTHING_TO_COMPACT_MIN_MILLIS); case UNABLE_TO_ACQUIRE_LOCKS: case FAILED_TO_COMPACT: return compactorConfigSupplier.get().compactPauseOnFailureMillis(); default: throw new IllegalStateException("Unexpected outcome enum type: " + outcome); } } @VisibleForTesting  BackgroundCompactor(
            MetricsManager metricsManager,
            TransactionManager transactionManager,
            KeyValueService keyValueService,
            LockService lockService,
            Supplier<CompactorConfig> compactorConfigSupplier,
            CompactPriorityCalculator compactPriorityCalculator); }
BackgroundCompactor implements AutoCloseable { @VisibleForTesting static long getSleepTime( Supplier<CompactorConfig> compactorConfigSupplier, CompactionOutcome outcome) { switch (outcome) { case SUCCESS: case COMPACTED_BUT_NOT_REGISTERED: case SHUTDOWN: return compactorConfigSupplier.get().compactPauseMillis(); case NOTHING_TO_COMPACT: case DISABLED: return Math.max(compactorConfigSupplier.get().compactPauseMillis(), SLEEP_TIME_WHEN_NOTHING_TO_COMPACT_MIN_MILLIS); case UNABLE_TO_ACQUIRE_LOCKS: case FAILED_TO_COMPACT: return compactorConfigSupplier.get().compactPauseOnFailureMillis(); default: throw new IllegalStateException("Unexpected outcome enum type: " + outcome); } } @VisibleForTesting  BackgroundCompactor(
            MetricsManager metricsManager,
            TransactionManager transactionManager,
            KeyValueService keyValueService,
            LockService lockService,
            Supplier<CompactorConfig> compactorConfigSupplier,
            CompactPriorityCalculator compactPriorityCalculator); static Optional<BackgroundCompactor> createAndRun(
            MetricsManager metricsManager,
            TransactionManager transactionManager,
            KeyValueService keyValueService,
            LockService lockService,
            Supplier<CompactorConfig> compactorConfigSupplier); @Override void close(); void run(); }
BackgroundCompactor implements AutoCloseable { @VisibleForTesting static long getSleepTime( Supplier<CompactorConfig> compactorConfigSupplier, CompactionOutcome outcome) { switch (outcome) { case SUCCESS: case COMPACTED_BUT_NOT_REGISTERED: case SHUTDOWN: return compactorConfigSupplier.get().compactPauseMillis(); case NOTHING_TO_COMPACT: case DISABLED: return Math.max(compactorConfigSupplier.get().compactPauseMillis(), SLEEP_TIME_WHEN_NOTHING_TO_COMPACT_MIN_MILLIS); case UNABLE_TO_ACQUIRE_LOCKS: case FAILED_TO_COMPACT: return compactorConfigSupplier.get().compactPauseOnFailureMillis(); default: throw new IllegalStateException("Unexpected outcome enum type: " + outcome); } } @VisibleForTesting  BackgroundCompactor(
            MetricsManager metricsManager,
            TransactionManager transactionManager,
            KeyValueService keyValueService,
            LockService lockService,
            Supplier<CompactorConfig> compactorConfigSupplier,
            CompactPriorityCalculator compactPriorityCalculator); static Optional<BackgroundCompactor> createAndRun(
            MetricsManager metricsManager,
            TransactionManager transactionManager,
            KeyValueService keyValueService,
            LockService lockService,
            Supplier<CompactorConfig> compactorConfigSupplier); @Override void close(); void run(); static final long SLEEP_TIME_WHEN_NOTHING_TO_COMPACT_MIN_MILLIS; }