Package com.coditory.sherlock
Class DistributedLockMock
- java.lang.Object
-
- com.coditory.sherlock.DistributedLockMock
-
- All Implemented Interfaces:
DistributedLock
public final class DistributedLockMock extends java.lang.Object implements DistributedLock
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.coditory.sherlock.DistributedLock
DistributedLock.AcquireAndExecuteResult, DistributedLock.ReleaseAndExecuteResult
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanacquire()Try to acquire the lock.booleanacquire(java.time.Duration duration)Try to acquire the lock for a given duration.static DistributedLockMockacquiredInMemoryLock()static DistributedLockMockacquiredInMemoryLock(java.lang.String lockId)static DistributedLockMockacquiredReentrantInMemoryLock()static DistributedLockMockacquiredReentrantInMemoryLock(java.lang.String lockId)booleanacquireForever()Try to acquire the lock without expiring date.intacquisitions()java.lang.StringgetId()Return the lock id.static DistributedLockMocklockStub(boolean result)static DistributedLockMocklockStub(boolean acquireResult, boolean releaseResult)static DistributedLockMocklockStub(java.lang.String lockId, boolean result)static DistributedLockMocklockStub(java.lang.String lockId, boolean acquireResult, boolean releaseResult)intrejectedAcquisitions()intrejectedReleases()booleanrelease()Try to release the lock.static DistributedLockMockreleasedInMemoryLock()static DistributedLockMockreleasedInMemoryLock(java.lang.String lockId)static DistributedLockMockreleasedReentrantInMemoryLock()static DistributedLockMockreleasedReentrantInMemoryLock(java.lang.String lockId)intreleases()static DistributedLockMocksequencedLock(java.lang.String lockId, java.util.List<java.lang.Boolean> acquireResults, java.util.List<java.lang.Boolean> releaseResults)static DistributedLockMocksequencedLock(java.util.List<java.lang.Boolean> acquireResults, java.util.List<java.lang.Boolean> releaseResults)intsuccessfulAcquisitions()intsuccessfulReleases()booleanwasAcquired()booleanwasAcquiredAndReleased()booleanwasAcquireInvoked()booleanwasAcquireRejected()booleanwasReleased()booleanwasReleaseInvoked()booleanwasReleaseRejected()-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.coditory.sherlock.DistributedLock
acquireAndExecute, acquireAndExecute, acquireForeverAndExecute, releaseAndExecute
-
-
-
-
Method Detail
-
releasedInMemoryLock
public static DistributedLockMock releasedInMemoryLock()
-
acquiredInMemoryLock
public static DistributedLockMock acquiredInMemoryLock()
-
releasedInMemoryLock
public static DistributedLockMock releasedInMemoryLock(java.lang.String lockId)
-
acquiredInMemoryLock
public static DistributedLockMock acquiredInMemoryLock(java.lang.String lockId)
-
releasedReentrantInMemoryLock
public static DistributedLockMock releasedReentrantInMemoryLock()
-
acquiredReentrantInMemoryLock
public static DistributedLockMock acquiredReentrantInMemoryLock()
-
releasedReentrantInMemoryLock
public static DistributedLockMock releasedReentrantInMemoryLock(java.lang.String lockId)
-
acquiredReentrantInMemoryLock
public static DistributedLockMock acquiredReentrantInMemoryLock(java.lang.String lockId)
-
lockStub
public static DistributedLockMock lockStub(boolean result)
-
lockStub
public static DistributedLockMock lockStub(boolean acquireResult, boolean releaseResult)
-
lockStub
public static DistributedLockMock lockStub(java.lang.String lockId, boolean result)
-
lockStub
public static DistributedLockMock lockStub(java.lang.String lockId, boolean acquireResult, boolean releaseResult)
-
sequencedLock
public static DistributedLockMock sequencedLock(java.util.List<java.lang.Boolean> acquireResults, java.util.List<java.lang.Boolean> releaseResults)
-
sequencedLock
public static DistributedLockMock sequencedLock(java.lang.String lockId, java.util.List<java.lang.Boolean> acquireResults, java.util.List<java.lang.Boolean> releaseResults)
-
getId
public java.lang.String getId()
Description copied from interface:DistributedLockReturn the lock id.- Specified by:
getIdin interfaceDistributedLock- Returns:
- the lock id
-
acquire
public boolean acquire()
Description copied from interface:DistributedLockTry to acquire the lock. Lock is acquired for a pre configured duration.- Specified by:
acquirein interfaceDistributedLock- Returns:
- true if lock is acquired
-
acquire
public boolean acquire(java.time.Duration duration)
Description copied from interface:DistributedLockTry to acquire the lock for a given duration.- Specified by:
acquirein interfaceDistributedLock- Parameters:
duration- how much time must pass for the acquired lock to expire- Returns:
- true if lock is acquired
-
acquireForever
public boolean acquireForever()
Description copied from interface:DistributedLockTry to acquire the lock without expiring date.It is potentially dangerous. Lookout for a situation when the lock owning instance goes down with out releasing the lock.
- Specified by:
acquireForeverin interfaceDistributedLock- Returns:
- true if lock is acquired
-
release
public boolean release()
Description copied from interface:DistributedLockTry 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
-
-