Class ReactorSherlockStub
- java.lang.Object
-
- com.coditory.sherlock.reactor.test.ReactorSherlockStub
-
- All Implemented Interfaces:
ReactorSherlock
public final class ReactorSherlockStub extends java.lang.Object implements ReactorSherlock
Use to stubReactorSherlock
in tests.
-
-
Constructor Summary
Constructors Constructor Description ReactorSherlockStub()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ReactorDistributedLock
createLock(java.lang.String lockId)
Create a distributed lock.ReactorDistributedLock
createLock(java.lang.String lockId, java.time.Duration duration)
Create a lock.ReactorDistributedLock
createOverridingLock(java.lang.String lockId)
Create a distributed overriding lock.ReactorDistributedLock
createOverridingLock(java.lang.String lockId, java.time.Duration duration)
Create a distributed overriding lock.ReactorDistributedLock
createReentrantLock(java.lang.String lockId)
Create a distributed reentrant lock.ReactorDistributedLock
createReentrantLock(java.lang.String lockId, java.time.Duration duration)
Create a distributed reentrant lock.java.time.Duration
getLockDuration()
java.lang.String
getOwnerId()
static ReactorSherlockStub
withAcquiredLocks()
Make the stub produce acquired locks by defaultReactorSherlockStub
withLock(ReactorDistributedLock lock)
Make the stub produce return a predefined lock.ReactorSherlockStub
withLockDuration(java.time.Duration duration)
Make the stub produce locks with given lock durationReactorSherlockStub
withOwnerId(java.lang.String ownerId)
Make the stub produce locks with given application instance idstatic ReactorSherlockStub
withReleasedLocks()
Make the stub produce released locks by default
-
-
-
Method Detail
-
withReleasedLocks
public static ReactorSherlockStub withReleasedLocks()
Make the stub produce released locks by default- Returns:
- the instance
-
withAcquiredLocks
public static ReactorSherlockStub withAcquiredLocks()
Make the stub produce acquired locks by default- Returns:
- the instance
-
withOwnerId
public ReactorSherlockStub withOwnerId(java.lang.String ownerId)
Make the stub produce locks with given application instance id- Parameters:
ownerId
- lock owner id- Returns:
- the instance
-
withLockDuration
public ReactorSherlockStub withLockDuration(java.time.Duration duration)
Make the stub produce locks with given lock duration- Parameters:
duration
- lock duration- Returns:
- the instance
-
withLock
public ReactorSherlockStub withLock(ReactorDistributedLock lock)
Make the stub produce return a predefined lock.- Parameters:
lock
- returned when creating a lock with the same id- Returns:
- the instance
-
getOwnerId
public java.lang.String getOwnerId()
- Specified by:
getOwnerId
in interfaceReactorSherlock
- Returns:
- owner id is most often the application instance id
-
getLockDuration
public java.time.Duration getLockDuration()
- Specified by:
getLockDuration
in interfaceReactorSherlock
- Returns:
- the default lock duration
-
createReentrantLock
public ReactorDistributedLock createReentrantLock(java.lang.String lockId)
Description copied from interface:ReactorSherlock
Create a distributed reentrant lock. Lock expires afterReactorSherlock.getLockDuration()
.- Specified by:
createReentrantLock
in interfaceReactorSherlock
- Parameters:
lockId
- the lock id- Returns:
- the reentrant lock
- See Also:
ReactorSherlock.createReentrantLock(String, Duration)
-
createReentrantLock
public ReactorDistributedLock createReentrantLock(java.lang.String lockId, java.time.Duration duration)
Description copied from interface:ReactorSherlock
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 interfaceReactorSherlock
- Parameters:
lockId
- the lock idduration
- after that time lock expires and is released- Returns:
- the reentrant lock
-
createLock
public ReactorDistributedLock createLock(java.lang.String lockId)
Description copied from interface:ReactorSherlock
Create a distributed lock. Lock expires afterReactorSherlock.getLockDuration()
.- Specified by:
createLock
in interfaceReactorSherlock
- Parameters:
lockId
- the lock id- Returns:
- the lock
- See Also:
ReactorSherlock.createLock(String, Duration)
-
createLock
public ReactorDistributedLock createLock(java.lang.String lockId, java.time.Duration duration)
Description copied from interface:ReactorSherlock
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 interfaceReactorSherlock
- Parameters:
lockId
- the lock idduration
- after that time lock expires and is released- Returns:
- the lock
-
createOverridingLock
public ReactorDistributedLock createOverridingLock(java.lang.String lockId)
Description copied from interface:ReactorSherlock
Create a distributed overriding lock. Lock expires afterReactorSherlock.getLockDuration()
.- Specified by:
createOverridingLock
in interfaceReactorSherlock
- Parameters:
lockId
- the lock id- Returns:
- the reentrant lock
- See Also:
ReactorSherlock.createOverridingLock(String, Duration)
-
createOverridingLock
public ReactorDistributedLock createOverridingLock(java.lang.String lockId, java.time.Duration duration)
Description copied from interface:ReactorSherlock
Create a distributed overriding lock. Returned lock overrides lock state without checking if it was released.- Specified by:
createOverridingLock
in interfaceReactorSherlock
- Parameters:
lockId
- the lock idduration
- after that time lock expires and is released- Returns:
- the reentrant lock
-
-