Package com.coditory.sherlock.test
Class SherlockStub
- java.lang.Object
-
- com.coditory.sherlock.test.SherlockStub
-
-
Constructor Summary
Constructors Constructor Description SherlockStub()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DistributedLockcreateLock(java.lang.String lockId)Create a distributed lock.DistributedLockcreateLock(java.lang.String lockId, java.time.Duration duration)Create a lock.DistributedLockcreateOverridingLock(java.lang.String lockId)Create a distributed overriding lock.DistributedLockcreateOverridingLock(java.lang.String lockId, java.time.Duration duration)Create a distributed overriding lock.DistributedLockcreateReentrantLock(java.lang.String lockId)Create a distributed reentrant lock.DistributedLockcreateReentrantLock(java.lang.String lockId, java.time.Duration duration)Create a distributed reentrant lock.voidinitialize()Initializes underlying infrastructure.static SherlockStubwithAcquiredLocks()Make the stub produce acquired locks by defaultSherlockStubwithLock(DistributedLock lock)Make the stub produce return a predefined lock.static SherlockStubwithReleasedLocks()Make the stub produce released locks by default
-
-
-
Method Detail
-
withReleasedLocks
public static SherlockStub withReleasedLocks()
Make the stub produce released locks by default- Returns:
- the stub instance
-
withAcquiredLocks
public static SherlockStub withAcquiredLocks()
Make the stub produce acquired locks by default- Returns:
- the stub instance
-
withLock
public SherlockStub withLock(DistributedLock lock)
Make the stub produce return a predefined lock.- Parameters:
lock- returned when creating a lock with the same id- Returns:
- the stub instance
-
createReentrantLock
public DistributedLock createReentrantLock(java.lang.String lockId)
Description copied from interface:SherlockCreate a distributed reentrant lock. Lock expires after configured lock duration.- Specified by:
createReentrantLockin interfaceSherlock- Parameters:
lockId- the lock id- Returns:
- the reentrant lock
- See Also:
Sherlock.createReentrantLock(String, Duration)
-
createReentrantLock
public DistributedLock createReentrantLock(java.lang.String lockId, java.time.Duration duration)
Description copied from interface:SherlockCreate a distributed reentrant lock. Reentrant lock maybe acquired multiple times by the same application instance:assert reentrantLock.acquire() == true assert reentrantLock.acquire() == true- Specified by:
createReentrantLockin interfaceSherlock- Parameters:
lockId- the lock idduration- after that time lock expires and is released- Returns:
- the reentrant lock
-
initialize
public void initialize()
Description copied from interface:SherlockInitializes underlying infrastructure. If it's database then indexes and tables are created. If this method is not invoked directly then it is invoked implicitly when acquiring or releasing a lock for the first time.- Specified by:
initializein interfaceSherlock
-
createLock
public DistributedLock createLock(java.lang.String lockId)
Description copied from interface:SherlockCreate a distributed lock. Lock expires after configured lock duration.- Specified by:
createLockin interfaceSherlock- Parameters:
lockId- the lock id- Returns:
- the lock
- See Also:
Sherlock.createLock(String, Duration)
-
createLock
public DistributedLock createLock(java.lang.String lockId, java.time.Duration duration)
Description copied from interface:SherlockCreate a lock. Created lock may be acquired only once by the same application instance:assert reentrantLock.acquire() == true assert reentrantLock.acquire() == false- Specified by:
createLockin interfaceSherlock- Parameters:
lockId- the lock idduration- after that time lock expires and is released- Returns:
- the lock
-
createOverridingLock
public DistributedLock createOverridingLock(java.lang.String lockId)
Description copied from interface:SherlockCreate a distributed overriding lock. Lock expires after configured lock duration.- Specified by:
createOverridingLockin interfaceSherlock- Parameters:
lockId- the lock id- Returns:
- the reentrant lock
- See Also:
Sherlock.createOverridingLock(String, Duration)
-
createOverridingLock
public DistributedLock createOverridingLock(java.lang.String lockId, java.time.Duration duration)
Description copied from interface:SherlockCreate a distributed overriding lock. Returned lock overrides lock state without checking if it was released.- Specified by:
createOverridingLockin interfaceSherlock- Parameters:
lockId- the lock idduration- after that time lock expires and is released- Returns:
- the reentrant lock
-
-