Class SherlockStub

  • All Implemented Interfaces:
    Sherlock

    public class SherlockStub
    extends java.lang.Object
    implements Sherlock
    Use 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
      • 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 interface Sherlock
        Parameters:
        lockId - the lock id
        duration - after that time lock expires and is released
        Returns:
        the reentrant lock
      • initialize

        public void initialize()
        Description copied from interface: Sherlock
        Initializes underlying infrastructure. If it's database then indexes and tables are created. If this method is not invoked directly then it is invoked implicitly when acquiring or releasing a lock for the first time.
        Specified by:
        initialize in interface Sherlock
      • 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 interface Sherlock
        Parameters:
        lockId - the lock id
        duration - after that time lock expires and is released
        Returns:
        the lock
      • 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 interface Sherlock
        Parameters:
        lockId - the lock id
        duration - after that time lock expires and is released
        Returns:
        the reentrant lock