Package com.coditory.sherlock.test
Class DistributedLockMock
java.lang.Object
com.coditory.sherlock.test.DistributedLockMock
- All Implemented Interfaces:
DistributedLock
-
Method Summary
Modifier and TypeMethodDescriptionbooleanacquire()Tries to acquire the lock.booleanTries to acquire the lock for a given duration.static @NotNull DistributedLockMockstatic @NotNull DistributedLockMockacquiredInMemoryLock(@NotNull String lockId) static @NotNull DistributedLockMockstatic @NotNull DistributedLockMockacquiredReentrantInMemoryLock(@NotNull String lockId) booleanTries to acquire the lock without expiration date.int@NotNull StringgetId()Returns the lock id.static @NotNull DistributedLockMocklockStub(boolean result) static @NotNull DistributedLockMocklockStub(boolean acquireResult, boolean releaseResult) static @NotNull DistributedLockMockstatic @NotNull DistributedLockMockintintbooleanrelease()Tries to release the lock.static @NotNull DistributedLockMockstatic @NotNull DistributedLockMockreleasedInMemoryLock(@NotNull String lockId) static @NotNull DistributedLockMockstatic @NotNull DistributedLockMockreleasedReentrantInMemoryLock(@NotNull String lockId) intreleases()static @NotNull DistributedLockMocksequencedLock(@NotNull String lockId, @NotNull List<Boolean> acquireResults, @NotNull List<Boolean> releaseResults) static @NotNull DistributedLockMocksequencedLock(@NotNull List<Boolean> acquireResults, @NotNull List<Boolean> releaseResults) intintbooleanbooleanbooleanbooleanbooleanbooleanbooleanMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.coditory.sherlock.DistributedLock
runLocked, runLocked, runLocked, runLocked
-
Method Details
-
releasedInMemoryLock
-
acquiredInMemoryLock
-
releasedInMemoryLock
@NotNull public static @NotNull DistributedLockMock releasedInMemoryLock(@NotNull @NotNull String lockId) -
acquiredInMemoryLock
@NotNull public static @NotNull DistributedLockMock acquiredInMemoryLock(@NotNull @NotNull String lockId) -
releasedReentrantInMemoryLock
-
acquiredReentrantInMemoryLock
-
releasedReentrantInMemoryLock
@NotNull public static @NotNull DistributedLockMock releasedReentrantInMemoryLock(@NotNull @NotNull String lockId) -
acquiredReentrantInMemoryLock
@NotNull public static @NotNull DistributedLockMock acquiredReentrantInMemoryLock(@NotNull @NotNull String lockId) -
lockStub
-
lockStub
@NotNull public static @NotNull DistributedLockMock lockStub(boolean acquireResult, boolean releaseResult) -
lockStub
@NotNull public static @NotNull DistributedLockMock lockStub(@NotNull @NotNull String lockId, boolean result) -
lockStub
@NotNull public static @NotNull DistributedLockMock lockStub(@NotNull @NotNull String lockId, boolean acquireResult, boolean releaseResult) -
sequencedLock
@NotNull public static @NotNull DistributedLockMock sequencedLock(@NotNull @NotNull List<Boolean> acquireResults, @NotNull @NotNull List<Boolean> releaseResults) -
sequencedLock
-
getId
Description copied from interface:DistributedLockReturns the lock id.- Specified by:
getIdin interfaceDistributedLock- Returns:
- the lock id
-
acquire
public boolean acquire()Description copied from interface:DistributedLockTries to acquire the lock. Lock is acquired for a pre-configured duration. I lock is not released manually, it becomes released after expiration time.- Specified by:
acquirein interfaceDistributedLock- Returns:
- true if lock is acquired
-
acquire
Description copied from interface:DistributedLockTries to acquire the lock for a given duration. If lock is not released manually, it becomes released after expiration time.- Specified by:
acquirein interfaceDistributedLock- Parameters:
duration- lock expiration time when release is not executed- Returns:
- true if lock is acquired
-
acquireForever
public boolean acquireForever()Description copied from interface:DistributedLockTries to acquire the lock without expiration date.It is potentially dangerous. Lookout for a situation when the lock owning instance goes down without releasing the lock.
- Specified by:
acquireForeverin interfaceDistributedLock- Returns:
- true if lock is acquired
-
release
public boolean release()Description copied from interface:DistributedLockTries to release the lock.- Specified by:
releasein interfaceDistributedLock- Returns:
- true if lock was released by this method invocation. If lock has expired or was released earlier then false is returned.
-
successfulReleases
public int successfulReleases()- Returns:
- the count of successful releases
-
successfulAcquisitions
public int successfulAcquisitions()- Returns:
- the count of successful acquisitions
-
releases
public int releases()- Returns:
- the count of all releases (successful and unsuccessful)
-
acquisitions
public int acquisitions()- Returns:
- the count of all acquisitions (successful and unsuccessful)
-
rejectedReleases
public int rejectedReleases()- Returns:
- the count of rejected releases
-
rejectedAcquisitions
public int rejectedAcquisitions()- Returns:
- the count of rejected acquisitions
-
wasAcquired
public boolean wasAcquired()- Returns:
- true if lock was successfully acquired at least once
-
wasReleased
public boolean wasReleased()- Returns:
- true if lock was successfully released at least once
-
wasAcquiredAndReleased
public boolean wasAcquiredAndReleased()- Returns:
- true if lock was successfully acquired and released
-
wasAcquireRejected
public boolean wasAcquireRejected()- Returns:
- true if lock was acquired without success at least once
-
wasReleaseRejected
public boolean wasReleaseRejected()- Returns:
- true if lock was released without success at least once
-
wasAcquireInvoked
public boolean wasAcquireInvoked()- Returns:
- true if acquire operation was invoked at least once
-
wasReleaseInvoked
public boolean wasReleaseInvoked()- Returns:
- true if release operation was invoked at least once
-