use of net.javacrumbs.shedlock.core.SimpleLock in project ShedLock by lukas-krecan.
the class MultiTenancyLockProviderIntegrationTest method shouldUseDifferDatabaseForEachTennant.
@Test
void shouldUseDifferDatabaseForEachTennant() {
LockProvider lockProvider = getLockProvider();
Optional<SimpleLock> lock1 = lockProvider.lock(LOCK_CONFIGURATION);
assertThat(lock1).isNotEmpty();
assertThat(h2TestUtils.getLockInfo(LOCK_NAME).getLockUntil()).isAfter(ClockProvider.now());
assertThatThrownBy(() -> hsqlTestUtils.getLockedUntil(LOCK_NAME)).isInstanceOf(EmptyResultDataAccessException.class);
lock1.get().unlock();
Optional<SimpleLock> lock2 = lockProvider.lock(LOCK_CONFIGURATION);
assertThat(lock2).isNotEmpty();
assertThat(hsqlTestUtils.getLockInfo(LOCK_NAME).getLockUntil()).isAfter(ClockProvider.now());
lock2.get().unlock();
}
use of net.javacrumbs.shedlock.core.SimpleLock in project ShedLock by lukas-krecan.
the class ServerTimeTest method lockUntilShouldBeInUtc.
@Test
default void lockUntilShouldBeInUtc() {
Instant time = Instant.now();
Optional<SimpleLock> lock = getLockProvider().lock(new LockConfiguration(now(), LOCK_NAME, Duration.ofSeconds(60), Duration.ZERO));
assertThat(getTestUtils().getLockedUntil(LOCK_NAME).toLocalDateTime()).isBetween(atUtc(time.plusSeconds(50)), atUtc(time.plusSeconds(70)));
time = Instant.now();
lock.get().unlock();
assertThat(getTestUtils().getLockedUntil(LOCK_NAME).toLocalDateTime()).isBetween(atUtc(time.minusSeconds(10)), atUtc(time.plusSeconds(10)));
time = Instant.now();
getLockProvider().lock(new LockConfiguration(now(), LOCK_NAME, Duration.ofSeconds(120), Duration.ZERO));
assertThat(getTestUtils().getLockedUntil(LOCK_NAME).toLocalDateTime()).isBetween(atUtc(time.plusSeconds(110)), atUtc(time.plusSeconds(130)));
}
use of net.javacrumbs.shedlock.core.SimpleLock in project ShedLock by lukas-krecan.
the class AbstractExtensibleLockProviderIntegrationTest method lockCanNotBeExtendedTwice.
@Test
public void lockCanNotBeExtendedTwice() {
SimpleLock lock = lock(Duration.ofSeconds(10));
extendLock(lock);
assertInvalidLock(() -> lock.extend(Duration.ofSeconds(10), Duration.ofSeconds(9)));
}
use of net.javacrumbs.shedlock.core.SimpleLock in project ShedLock by lukas-krecan.
the class AbstractExtensibleLockProviderIntegrationTest method shouldBeAbleToExtendLock.
@Test
public void shouldBeAbleToExtendLock() {
SimpleLock lock = lock(originalLockDuration);
Optional<SimpleLock> newLock = lock.extend(Duration.ofSeconds(10), Duration.ZERO);
assertThat(newLock).isNotEmpty();
// wait for the original lock to be released
sleepFor(originalLockDuration);
assertLocked(LOCK_NAME1);
newLock.get().unlock();
assertUnlocked(LOCK_NAME1);
}
use of net.javacrumbs.shedlock.core.SimpleLock in project ShedLock by lukas-krecan.
the class AbstractExtensibleLockProviderIntegrationTest method shouldNotBeAbleToExtendUnlockedLock.
@Test
public void shouldNotBeAbleToExtendUnlockedLock() {
SimpleLock lock = lock(originalLockDuration);
lock.unlock();
assertUnlocked(LOCK_NAME1);
assertInvalidLock(() -> lock.extend(Duration.ofSeconds(10), Duration.ZERO));
}
Aggregations