Search in sources :

Example 11 with SimpleLock

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();
}
Also used : SimpleLock(net.javacrumbs.shedlock.core.SimpleLock) LockProvider(net.javacrumbs.shedlock.core.LockProvider) Test(org.junit.jupiter.api.Test)

Example 12 with SimpleLock

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)));
}
Also used : LockConfiguration(net.javacrumbs.shedlock.core.LockConfiguration) Instant(java.time.Instant) SimpleLock(net.javacrumbs.shedlock.core.SimpleLock) Test(org.junit.jupiter.api.Test)

Example 13 with SimpleLock

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)));
}
Also used : SimpleLock(net.javacrumbs.shedlock.core.SimpleLock) Test(org.junit.jupiter.api.Test)

Example 14 with SimpleLock

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);
}
Also used : SimpleLock(net.javacrumbs.shedlock.core.SimpleLock) Test(org.junit.jupiter.api.Test)

Example 15 with SimpleLock

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));
}
Also used : SimpleLock(net.javacrumbs.shedlock.core.SimpleLock) Test(org.junit.jupiter.api.Test)

Aggregations

SimpleLock (net.javacrumbs.shedlock.core.SimpleLock)18 Test (org.junit.jupiter.api.Test)16 LockConfiguration (net.javacrumbs.shedlock.core.LockConfiguration)9 LockProvider (net.javacrumbs.shedlock.core.LockProvider)3 Duration (java.time.Duration)2 AbstractLockProviderIntegrationTest (net.javacrumbs.shedlock.test.support.AbstractLockProviderIntegrationTest)2 Connection (java.sql.Connection)1 Statement (java.sql.Statement)1 Instant (java.time.Instant)1 ColumnNames (net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.ColumnNames)1 StorageBasedLockProvider (net.javacrumbs.shedlock.support.StorageBasedLockProvider)1 AbstractStorageBasedLockProviderIntegrationTest (net.javacrumbs.shedlock.test.support.AbstractStorageBasedLockProviderIntegrationTest)1 Disabled (org.junit.jupiter.api.Disabled)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1