@Test void shouldRethrowExceptionFromUpdate() { when(storageAccessor.insertRecord(LOCK_CONFIGURATION)).thenReturn(false); when(storageAccessor.updateRecord(LOCK_CONFIGURATION)).thenThrow(LOCK_EXCEPTION); assertThatThrownBy(() -> lockProvider.lock(LOCK_CONFIGURATION)).isSameAs(LOCK_EXCEPTION); }
@Override @NonNull public Optional<SimpleLock> lock(@NonNull LockConfiguration lockConfiguration) { boolean lockObtained = doLock(lockConfiguration); if (lockObtained) { return Optional.of(new StorageLock(lockConfiguration, storageAccessor)); } else { return Optional.empty(); } }
StorageBasedLockProvider implements LockProvider { @Override @NonNull public Optional<SimpleLock> lock(@NonNull LockConfiguration lockConfiguration) { boolean lockObtained = doLock(lockConfiguration); if (lockObtained) { return Optional.of(new StorageLock(lockConfiguration, storageAccessor)); } else { return Optional.empty(); } } }
StorageBasedLockProvider implements LockProvider { @Override @NonNull public Optional<SimpleLock> lock(@NonNull LockConfiguration lockConfiguration) { boolean lockObtained = doLock(lockConfiguration); if (lockObtained) { return Optional.of(new StorageLock(lockConfiguration, storageAccessor)); } else { return Optional.empty(); } } protected  StorageBasedLockProvider(@NonNull StorageAccessor storageAccessor); }
StorageBasedLockProvider implements LockProvider { @Override @NonNull public Optional<SimpleLock> lock(@NonNull LockConfiguration lockConfiguration) { boolean lockObtained = doLock(lockConfiguration); if (lockObtained) { return Optional.of(new StorageLock(lockConfiguration, storageAccessor)); } else { return Optional.empty(); } } protected  StorageBasedLockProvider(@NonNull StorageAccessor storageAccessor); void clearCache(); @Override @NonNull Optional<SimpleLock> lock(@NonNull LockConfiguration lockConfiguration); }
StorageBasedLockProvider implements LockProvider { @Override @NonNull public Optional<SimpleLock> lock(@NonNull LockConfiguration lockConfiguration) { boolean lockObtained = doLock(lockConfiguration); if (lockObtained) { return Optional.of(new StorageLock(lockConfiguration, storageAccessor)); } else { return Optional.empty(); } } protected  StorageBasedLockProvider(@NonNull StorageAccessor storageAccessor); void clearCache(); @Override @NonNull Optional<SimpleLock> lock(@NonNull LockConfiguration lockConfiguration);  }