mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-04 10:09:42 +00:00
added test for timed lock impl
This commit is contained in:
1 parent
97c732f9b7
commit
3641f8ef56
1 file changed
+63
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.sap.sse.common.impl.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.sap.sse.common.Duration;
|
||||
import com.sap.sse.common.TimePoint;
|
||||
import com.sap.sse.common.impl.TimedLockImpl;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class TimedLockImplTest {
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link com.sap.sse.common.impl.TimedLockImpl#extendLockDuration()}.
|
||||
*/
|
||||
@Test
|
||||
void testExtendLockDuration() {
|
||||
final TimedLockImpl lock = new TimedLockImpl();
|
||||
final Duration firstLockingDelay = lock.getNextLockingDelay();
|
||||
// initial locking delay should be greater than 0
|
||||
assertTrue(firstLockingDelay.compareTo(Duration.NULL) > 0);
|
||||
assertTrue(firstLockingDelay.compareTo(Duration.ofMillis(0)) > 0);
|
||||
final TimePoint expectedLockedUntil = TimePoint.now().plus(firstLockingDelay);
|
||||
// locking delay should be applied to lockedUntil
|
||||
lock.extendLockDuration();
|
||||
assertEquals(lock.getLockedUntil(), expectedLockedUntil);
|
||||
// locking delay should double
|
||||
final Duration secondLockingDelay = firstLockingDelay.plus(firstLockingDelay);
|
||||
assertEquals(lock.getNextLockingDelay(), secondLockingDelay);
|
||||
// double locking delay should be applied to lockedUntil
|
||||
lock.extendLockDuration();
|
||||
assertEquals(lock.getLockedUntil(), TimePoint.now().plus(secondLockingDelay));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link com.sap.sse.common.impl.TimedLockImpl#resetLock()}.
|
||||
*/
|
||||
@Test
|
||||
void testResetLock() {
|
||||
final TimedLockImpl lock = new TimedLockImpl();
|
||||
lock.extendLockDuration();
|
||||
lock.extendLockDuration();
|
||||
lock.extendLockDuration();
|
||||
assertTrue(lock.isLocked());
|
||||
lock.resetLock();
|
||||
assertFalse(lock.isLocked());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user