use of net.javacrumbs.shedlock.core.LockConfiguration in project ShedLock by lukas-krecan.
the class AbstractLockProviderIntegrationTest method shouldBeAbleToLockRightAfterUnlock.
@Test
public void shouldBeAbleToLockRightAfterUnlock() {
LockConfiguration lockConfiguration = lockConfig(LOCK_NAME1);
for (int i = 0; i < 10; i++) {
Optional<SimpleLock> lock = getLockProvider().lock(lockConfiguration);
assertThat(lock).describedAs("Successfully locked").isNotEmpty();
assertThat(getLockProvider().lock(lockConfiguration)).isEmpty();
assertThat(lock).isNotEmpty();
lock.get().unlock();
}
}
use of net.javacrumbs.shedlock.core.LockConfiguration in project ShedLock by lukas-krecan.
the class AbstractStorageBasedLockProviderIntegrationTest method lockShouldSurviveCacheClearingInTheMiddle.
@Test
public void lockShouldSurviveCacheClearingInTheMiddle() {
StorageBasedLockProvider provider = getLockProvider();
LockConfiguration configuration = lockConfig(LOCK_NAME1);
Optional<SimpleLock> lock = provider.lock(configuration);
assertThat(lock).isPresent();
provider.clearCache();
// lock is still locked
assertThat(provider.lock(lockConfig(LOCK_NAME1))).isEmpty();
lock.get().unlock();
}
use of net.javacrumbs.shedlock.core.LockConfiguration in project ShedLock by lukas-krecan.
the class ConsulLockProviderIntegrationTest method shouldTimeout.
@Test
@Override
public void shouldTimeout() throws InterruptedException {
// as consul has 10 seconds ttl minimum and has double ttl unlocking time, you have to wait for 20 seconds for the unlock time.
Duration lockAtMostFor = Duration.ofSeconds(11);
LockConfiguration configWithShortTimeout = lockConfig(LOCK_NAME1, lockAtMostFor, Duration.ZERO);
Optional<SimpleLock> lock1 = getLockProvider().lock(configWithShortTimeout);
assertThat(lock1).isNotEmpty();
sleep(lockAtMostFor.multipliedBy(2).toMillis() + 100);
assertUnlocked(LOCK_NAME1);
Optional<SimpleLock> lock2 = getLockProvider().lock(lockConfig(LOCK_NAME1, Duration.ofMillis(50), Duration.ZERO));
assertThat(lock2).isNotEmpty();
lock2.get().unlock();
}
use of net.javacrumbs.shedlock.core.LockConfiguration in project ShedLock by lukas-krecan.
the class ConsulLockProviderIntegrationTest method shouldNotTimeoutIfLessThanMinTtlPassed.
@Test
public void shouldNotTimeoutIfLessThanMinTtlPassed() throws InterruptedException {
Duration lockAtMostFor = Duration.ofSeconds(1);
LockConfiguration configWithShortTimeout = lockConfig(LOCK_NAME1, lockAtMostFor, Duration.ZERO);
Optional<SimpleLock> lock1 = getLockProvider().lock(configWithShortTimeout);
assertThat(lock1).isNotEmpty();
sleep(lockAtMostFor.multipliedBy(2).toMillis() + 100);
assertLocked(LOCK_NAME1);
// release lock to satisfy condition for #checkSessions()
lock1.get().unlock();
}
use of net.javacrumbs.shedlock.core.LockConfiguration in project ShedLock by lukas-krecan.
the class AbstractJdbcTemplateStorageAccessorTest method shouldNotUpdateOtherLockConfigurations.
private void shouldNotUpdateOtherLockConfigurations(boolean usingDbTime) throws InterruptedException {
JdbcTemplateStorageAccessor accessor = getAccessor(usingDbTime);
Duration lockAtMostFor = Duration.ofMillis(10);
assertThat(accessor.insertRecord(lockConfig(MY_LOCK, lockAtMostFor))).isEqualTo(true);
assertThat(accessor.insertRecord(lockConfig(OTHER_LOCK, lockAtMostFor))).isEqualTo(true);
Timestamp myLockLockedUntil = testUtils.getLockedUntil(MY_LOCK);
Timestamp otherLockLockedUntil = testUtils.getLockedUntil(OTHER_LOCK);
// wait for a while so there will be a difference in the timestamp
// when system time is used seems there is no milliseconds in the timestamp so to make a difference we have to wait for at least a second
sleep(1000);
// act
assertThat(accessor.updateRecord(new LockConfiguration(now(), MY_LOCK, lockAtMostFor, Duration.ZERO))).isEqualTo(true);
// assert
assertThat(testUtils.getLockedUntil(MY_LOCK)).isAfter(myLockLockedUntil);
// check that the other lock has not been affected by "my-lock" update
assertThat(testUtils.getLockedUntil(OTHER_LOCK)).isEqualTo(otherLockLockedUntil);
}
Aggregations