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
      • withOwnerId

        public SherlockStub withOwnerId​(java.lang.String ownerId)
        Make the stub produce locks with given application instance id
        Parameters:
        ownerId - lock owner id
        Returns:
        the stub instance
      • withLockDuration

        public SherlockStub withLockDuration​(java.time.Duration duration)
        Make the stub produce locks with given lock duration
        Parameters:
        duration - lock duration
        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
      • getOwnerId

        public java.lang.String getOwnerId()
        Specified by:
        getOwnerId in interface Sherlock
        Returns:
        owner id is most often the application instance id
      • getLockDuration

        public java.time.Duration getLockDuration()
        Specified by:
        getLockDuration in interface Sherlock
        Returns:
        the default lock duration
      • 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
      • 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