Class SherlockStub

  • All Implemented Interfaces:
    Sherlock

    public final class SherlockStub
    extends java.lang.Object
    implements Sherlock
    Used to stub Sherlock in tests.
    • Constructor Detail

      • SherlockStub

        public SherlockStub()
    • 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
      • 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
      • 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 interface Sherlock
      • createLock

        public com.coditory.sherlock.DistributedLockBuilder<DistributedLock> 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 interface Sherlock
        Returns:
        the lock builder
      • createReentrantLock

        public com.coditory.sherlock.DistributedLockBuilder<DistributedLock> 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 interface Sherlock
        Returns:
        the reentrant lock builder
      • createOverridingLock

        public com.coditory.sherlock.DistributedLockBuilder<DistributedLock> 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 interface Sherlock
        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 interface Sherlock
        Returns:
        true if any lock was released