Search in sources :

Example 16 with SimpleLock

use of net.javacrumbs.shedlock.core.SimpleLock in project ShedLock by lukas-krecan.

the class AbstractLockProviderIntegrationTest method shouldLockTwiceInARow.

@Test
public void shouldLockTwiceInARow() {
    LockProvider lockProvider = getLockProvider();
    Optional<SimpleLock> lock1 = lockProvider.lock(lockConfig(LOCK_NAME1));
    assertThat(lock1).isNotEmpty();
    lock1.get().unlock();
    Optional<SimpleLock> lock2 = lockProvider.lock(lockConfig(LOCK_NAME1));
    assertThat(lock2).isNotEmpty();
    lock2.get().unlock();
}
Also used : SimpleLock(net.javacrumbs.shedlock.core.SimpleLock) LockProvider(net.javacrumbs.shedlock.core.LockProvider) Test(org.junit.jupiter.api.Test)

Example 17 with SimpleLock

use of net.javacrumbs.shedlock.core.SimpleLock in project ShedLock by lukas-krecan.

the class AbstractLockProviderIntegrationTest method shouldNotReturnSecondLock.

@Test
public void shouldNotReturnSecondLock() {
    LockProvider lockProvider = getLockProvider();
    Optional<SimpleLock> lock = lockProvider.lock(lockConfig(LOCK_NAME1));
    assertThat(lock).isNotEmpty();
    assertThat(lockProvider.lock(lockConfig(LOCK_NAME1))).isEmpty();
    lock.get().unlock();
}
Also used : SimpleLock(net.javacrumbs.shedlock.core.SimpleLock) LockProvider(net.javacrumbs.shedlock.core.LockProvider) Test(org.junit.jupiter.api.Test)

Example 18 with SimpleLock

use of net.javacrumbs.shedlock.core.SimpleLock in project ShedLock by lukas-krecan.

the class AbstractLockProviderIntegrationTest method doTestTimeout.

protected void doTestTimeout(Duration lockAtMostFor) throws InterruptedException {
    LockConfiguration configWithShortTimeout = lockConfig(LOCK_NAME1, lockAtMostFor, Duration.ZERO);
    Optional<SimpleLock> lock1 = getLockProvider().lock(configWithShortTimeout);
    assertThat(lock1).isNotEmpty();
    sleep(lockAtMostFor.toMillis() * 2);
    assertUnlocked(LOCK_NAME1);
    Optional<SimpleLock> lock2 = getLockProvider().lock(lockConfig(LOCK_NAME1, Duration.ofMillis(50), Duration.ZERO));
    assertThat(lock2).isNotEmpty();
    lock2.get().unlock();
}
Also used : LockConfiguration(net.javacrumbs.shedlock.core.LockConfiguration) SimpleLock(net.javacrumbs.shedlock.core.SimpleLock)

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