Package com.coditory.sherlock.test
Class SherlockStub
- java.lang.Object
-
- com.coditory.sherlock.test.SherlockStub
-
-
Constructor Summary
Constructors Constructor Description SherlockStub()
-
Method Summary
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.java.time.DurationgetLockDuration()java.lang.StringgetOwnerId()static SherlockStubwithAcquiredLocks()Make the stub produce acquired locks by defaultSherlockStubwithLock(DistributedLock lock)Make the stub produce return a predefined lock.SherlockStubwithLockDuration(java.time.Duration duration)Make the stub produce locks with given lock durationSherlockStubwithOwnerId(java.lang.String ownerId)Make the stub produce locks with given application instance idstatic 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
-
withOwnerId
public SherlockStub withOwnerId(java.lang.String ownerId)
Make the stub produce locks with given application instance id- Parameters:
ownerId- lock owner id- Returns:
- the stub instance
-
withLockDuration
public SherlockStub withLockDuration(java.time.Duration duration)
Make the stub produce locks with given lock duration- Parameters:
duration- lock duration- 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
-
getOwnerId
public java.lang.String getOwnerId()
- Specified by:
getOwnerIdin interfaceSherlock- Returns:
- owner id is most often the application instance id
-
getLockDuration
public java.time.Duration getLockDuration()
- Specified by:
getLockDurationin interfaceSherlock- Returns:
- the default lock duration
-
createReentrantLock
public DistributedLock createReentrantLock(java.lang.String lockId)
Description copied from interface:SherlockCreate a distributed reentrant lock. Lock expires afterSherlock.getLockDuration().- 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
-
createLock
public DistributedLock createLock(java.lang.String lockId)
Description copied from interface:SherlockCreate a distributed lock. Lock expires afterSherlock.getLockDuration().- 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 afterSherlock.getLockDuration().- 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
-
-