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 DistributedLock
createLock(java.lang.String lockId)
Create a distributed lock.DistributedLock
createLock(java.lang.String lockId, java.time.Duration duration)
Create a lock.DistributedLock
createOverridingLock(java.lang.String lockId)
Create a distributed overriding lock.DistributedLock
createOverridingLock(java.lang.String lockId, java.time.Duration duration)
Create a distributed overriding lock.DistributedLock
createReentrantLock(java.lang.String lockId)
Create a distributed reentrant lock.DistributedLock
createReentrantLock(java.lang.String lockId, java.time.Duration duration)
Create a distributed reentrant lock.java.time.Duration
getLockDuration()
java.lang.String
getOwnerId()
static SherlockStub
withAcquiredLocks()
Make the stub produce acquired locks by defaultSherlockStub
withLock(DistributedLock lock)
Make the stub produce return a predefined lock.SherlockStub
withLockDuration(java.time.Duration duration)
Make the stub produce locks with given lock durationSherlockStub
withOwnerId(java.lang.String ownerId)
Make the stub produce locks with given application instance idstatic SherlockStub
withReleasedLocks()
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:
getOwnerId
in interfaceSherlock
- Returns:
- owner id is most often the application instance id
-
getLockDuration
public java.time.Duration getLockDuration()
- Specified by:
getLockDuration
in interfaceSherlock
- Returns:
- the default lock duration
-
createReentrantLock
public DistributedLock createReentrantLock(java.lang.String lockId)
Description copied from interface:Sherlock
Create a distributed reentrant lock. Lock expires afterSherlock.getLockDuration()
.- Specified by:
createReentrantLock
in 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:Sherlock
Create 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:
createReentrantLock
in 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:Sherlock
Create a distributed lock. Lock expires afterSherlock.getLockDuration()
.- Specified by:
createLock
in 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:Sherlock
Create a lock. Created lock may be acquired only once by the same application instance:assert reentrantLock.acquire() == true assert reentrantLock.acquire() == false
- Specified by:
createLock
in 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:Sherlock
Create a distributed overriding lock. Lock expires afterSherlock.getLockDuration()
.- Specified by:
createOverridingLock
in 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:Sherlock
Create a distributed overriding lock. Returned lock overrides lock state without checking if it was released.- Specified by:
createOverridingLock
in interfaceSherlock
- Parameters:
lockId
- the lock idduration
- after that time lock expires and is released- Returns:
- the reentrant lock
-
-