Package com.coditory.sherlock.test
Class SherlockStub
java.lang.Object
com.coditory.sherlock.test.SherlockStub
- All Implemented Interfaces:
Sherlock
Used to stub
Sherlock in tests.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NotNull com.coditory.sherlock.DistributedLockBuilder<DistributedLock> Creates a distributed single-entrant lock builder.@NotNull com.coditory.sherlock.DistributedLockBuilder<DistributedLock> Create a distributed overriding lock.@NotNull com.coditory.sherlock.DistributedLockBuilder<DistributedLock> Creates a distributed reentrant lock.booleanForce releases all acquired locks.voidInitializes underlying infrastructure.static @NotNull SherlockStubMake the stub produce acquired locks by default@NotNull SherlockStubwithLock(@NotNull DistributedLock lock) Make the stub produce return a predefined lock.static @NotNull SherlockStubMake the stub produce released locks by defaultMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:SherlockInitializes 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.Initialization creates indexes and tables.
- Specified by:
initializein interfaceSherlock
-
createLock
Description copied from interface:SherlockCreates a distributed single-entrant lock builder. Single-entrant lock can be acquired only once. Even the same owner cannot acquire the same lock again.assert lock.acquire() == true assert lock.acquire() == false- Specified by:
createLockin interfaceSherlock- Returns:
- the lock builder
-
createReentrantLock
@NotNull public @NotNull com.coditory.sherlock.DistributedLockBuilder<DistributedLock> createReentrantLock()Description copied from interface:SherlockCreates 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:
createReentrantLockin interfaceSherlock- Returns:
- the reentrant lock builder
-
createOverridingLock
@NotNull public @NotNull com.coditory.sherlock.DistributedLockBuilder<DistributedLock> createOverridingLock()Description copied from interface:SherlockCreate a distributed overriding lock. Returned lock may acquire or release any other lock without checking its state:assert someLock.acquire() == true assert overridingLock.acquire() == trueIt could be used for administrative actions.
- Specified by:
createOverridingLockin interfaceSherlock- Returns:
- the overriding lock builder
-
forceReleaseAllLocks
public boolean forceReleaseAllLocks()Description copied from interface:SherlockForce releases all acquired locks.It could be used for administrative actions.
- Specified by:
forceReleaseAllLocksin interfaceSherlock- Returns:
ReleaseResult
-