4ba96edce130ecb0acc7e440ea2f734b49f04b36
java/com.sap.sse.common.test/src/com/sap/sse/common/impl/test/TimedLockImplTest.java
| ... | ... | @@ -3,7 +3,9 @@ |
| 3 | 3 | */ |
| 4 | 4 | package com.sap.sse.common.impl.test; |
| 5 | 5 | |
| 6 | -import static org.junit.jupiter.api.Assertions.*; |
|
| 6 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
|
| 7 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
|
| 8 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
|
| 7 | 9 | |
| 8 | 10 | import org.junit.jupiter.api.BeforeEach; |
| 9 | 11 | import org.junit.jupiter.api.Test; |
| ... | ... | @@ -31,19 +33,20 @@ class TimedLockImplTest { |
| 31 | 33 | void testExtendLockDuration() { |
| 32 | 34 | final TimedLockImpl lock = new TimedLockImpl(); |
| 33 | 35 | final Duration firstLockingDelay = lock.getNextLockingDelay(); |
| 36 | + // locking delay should double each time extendLockDuration is called |
|
| 37 | + final Duration secondLockingDelay = firstLockingDelay.plus(firstLockingDelay); |
|
| 34 | 38 | // initial locking delay should be greater than 0 |
| 35 | 39 | assertTrue(firstLockingDelay.compareTo(Duration.NULL) > 0); |
| 36 | 40 | assertTrue(firstLockingDelay.compareTo(Duration.ofMillis(0)) > 0); |
| 37 | 41 | final TimePoint expectedLockedUntil = TimePoint.now().plus(firstLockingDelay); |
| 38 | 42 | // locking delay should be applied to lockedUntil |
| 39 | 43 | lock.extendLockDuration(); |
| 40 | - assertEquals(lock.getLockedUntil(), expectedLockedUntil); |
|
| 41 | - // locking delay should double |
|
| 42 | - final Duration secondLockingDelay = firstLockingDelay.plus(firstLockingDelay); |
|
| 44 | + assertFalse(lock.getLockedUntil().before(expectedLockedUntil)); |
|
| 45 | + assertTrue(lock.getLockedUntil().before(TimePoint.now().plus(secondLockingDelay))); |
|
| 43 | 46 | assertEquals(lock.getNextLockingDelay(), secondLockingDelay); |
| 44 | 47 | // double locking delay should be applied to lockedUntil |
| 45 | 48 | lock.extendLockDuration(); |
| 46 | - assertEquals(lock.getLockedUntil(), TimePoint.now().plus(secondLockingDelay)); |
|
| 49 | + assertFalse(lock.getLockedUntil().before(TimePoint.now().plus(secondLockingDelay))); |
|
| 47 | 50 | } |
| 48 | 51 | |
| 49 | 52 | /** |
| ... | ... | @@ -59,5 +62,4 @@ class TimedLockImplTest { |
| 59 | 62 | lock.resetLock(); |
| 60 | 63 | assertFalse(lock.isLocked()); |
| 61 | 64 | } |
| 62 | - |
|
| 63 | 65 | } |