Class DistributedLockMock

    • Method Detail

      • alwaysReleasedLock

        public static DistributedLockMock alwaysReleasedLock​(java.lang.String lockId)
        Create a lock that can be always acquired.
        Parameters:
        lockId - the lock id
        Returns:
        created mock of distributed lock
      • alwaysAcquiredLock

        public static DistributedLockMock alwaysAcquiredLock​(java.lang.String lockId)
        Create a lock that can be never acquired.
        Parameters:
        lockId - the lock id
        Returns:
        created mock of distributed lock
      • singleStateLock

        public static DistributedLockMock singleStateLock​(java.lang.String lockId,
                                                          boolean released)
        Create always released lock if released parameter is true, otherwise always acquired lock is returned
        Parameters:
        lockId - the lock id
        released - the lock state
        Returns:
        created mock of distributed lock
      • sequencedLock

        public static DistributedLockMock sequencedLock​(java.lang.String lockId,
                                                        java.util.List<java.lang.Boolean> results)
        Create a lock returning a sequence of results for acquiring.
        Parameters:
        lockId - the lock id
        results - the sequence of acquire and release results
        Returns:
        created mock of distributed lock
      • sequencedLock

        public static DistributedLockMock sequencedLock​(java.lang.String lockId,
                                                        java.util.List<java.lang.Boolean> acquireResults,
                                                        java.util.List<java.lang.Boolean> releaseResults)
        Create a lock returning a sequence of results for acquiring and releasing.
        Parameters:
        lockId - the lock id
        acquireResults - the sequence of acquire results
        releaseResults - the sequence of release results
        Returns:
        created mock of distributed lock
      • getId

        public java.lang.String getId()
        Description copied from interface: DistributedLock
        Return the lock id.
        Specified by:
        getId in interface DistributedLock
        Returns:
        the lock id
      • acquire

        public boolean acquire()
        Description copied from interface: DistributedLock
        Try to acquire the lock. Lock is acquired for a configured duration.
        Specified by:
        acquire in interface DistributedLock
        Returns:
        true, if lock is acquired
      • acquire

        public boolean acquire​(java.time.Duration duration)
        Description copied from interface: DistributedLock
        Try to acquire the lock for a given duration.
        Specified by:
        acquire in interface DistributedLock
        Parameters:
        duration - how much time must pass for the acquired lock to expire
        Returns:
        true, if lock is acquired
      • acquireForever

        public boolean acquireForever()
        Description copied from interface: DistributedLock
        Try to acquire the lock without expiring date. It is potentially dangerous. Lookout for a situation where the lock owning instance goes down with out releasing the lock.
        Specified by:
        acquireForever in interface DistributedLock
        Returns:
        true, if lock is acquired
      • release

        public boolean release()
        Description copied from interface: DistributedLock
        Release the lock
        Specified by:
        release in interface DistributedLock
        Returns:
        true, if lock was released in this call. If lock has expired or was released by a different instance then false is returned.
      • wasAcquired

        public boolean wasAcquired()
        Returns:
        true if lock was successfully acquired
      • wasReleased

        public boolean wasReleased()
        Returns:
        true if lock was successfully released
      • wasAcquiredAndReleased

        public boolean wasAcquiredAndReleased()
        Returns:
        true if lock was successfully acquired and released
      • wasAcquireRejected

        public boolean wasAcquireRejected()
        Returns:
        true if lock was at least once acquired without success
      • wasReleaseRejected

        public boolean wasReleaseRejected()
        Returns:
        true if lock was at least once acquired without success
      • releaseSuccesses

        public int releaseSuccesses()
        Returns:
        the count of successful releases
      • aquireSuccesses

        public int aquireSuccesses()
        Returns:
        the count of successful acquisitions
      • wasAcquireInvoked

        public boolean wasAcquireInvoked()
        Returns:
        true if acquire operation was invoked
      • wasReleaseInvoked

        public boolean wasReleaseInvoked()
        Returns:
        true if release operation was invoked
      • releaseInvocations

        public int releaseInvocations()
        Returns:
        the count of release invocations
      • acquireInvocations

        public int acquireInvocations()
        Returns:
        the count of acquire invocations