Package com.coditory.sherlock
Class SherlockStub
java.lang.Object
com.coditory.sherlock.SherlockStub
- All Implemented Interfaces:
Sherlock
Used to stub
Sherlock
in tests.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncom.coditory.sherlock.DistributedLockBuilder<DistributedLock>
Creates a distributed lock.com.coditory.sherlock.DistributedLockBuilder<DistributedLock>
Create a distributed overriding lock.com.coditory.sherlock.DistributedLockBuilder<DistributedLock>
Creates a distributed reentrant lock.boolean
Force releases all acquired locks.void
Initializes underlying infrastructure.static SherlockStub
Make the stub produce acquired locks by defaultwithLock
(DistributedLock lock) Make the stub produce return a predefined lock.static SherlockStub
Make the stub produce released locks by defaultMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.coditory.sherlock.Sherlock
createLock, createOverridingLock, createReentrantLock, forceReleaseLock
-
Constructor Details
-
SherlockStub
public SherlockStub()
-
-
Method Details
-
withReleasedLocks
Make the stub produce released locks by default- Returns:
- the stub instance
-
withAcquiredLocks
Make the stub produce acquired locks by default- Returns:
- the stub instance
-
withLock
Make the stub produce return a predefined lock.- Parameters:
lock
- returned when creating a lock with the same id- Returns:
- the stub instance
-
initialize
public void initialize()Description copied from interface:Sherlock
Initializes underlying infrastructure. If this method is not invoked explicitly then it can be invoked implicitly when acquiring or releasing a lock for the first time.Most often initialization is related with creating indexes and tables.
- Specified by:
initialize
in interfaceSherlock
-
createLock
Description copied from interface:Sherlock
Creates a distributed lock. Created lock may be acquired only once by the same owner:assert lock.acquire() == true assert lock.acquire() == false
- Specified by:
createLock
in interfaceSherlock
- Returns:
- the lock builder
-
createReentrantLock
Description copied from interface:Sherlock
Creates a distributed reentrant lock. Reentrant lock may be acquired multiple times by the same owner:assert reentrantLock.acquire() == true assert reentrantLock.acquire() == true
- Specified by:
createReentrantLock
in interfaceSherlock
- Returns:
- the reentrant lock builder
-
createOverridingLock
Description copied from interface:Sherlock
Create a distributed overriding lock. Returned lock may acquire or release any other lock without checking its state:assert someLock.acquire() == true assert overridingLock.acquire() == true
It could be used for administrative actions.
- Specified by:
createOverridingLock
in interfaceSherlock
- Returns:
- the overriding lock builder
-
forceReleaseAllLocks
public boolean forceReleaseAllLocks()Description copied from interface:Sherlock
Force releases all acquired locks.It could be used for administrative actions.
- Specified by:
forceReleaseAllLocks
in interfaceSherlock
- Returns:
- true if any lock was released
-