Search in sources :

Example 1 with SimpleLock

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

the class KeepAliveLockProviderTest method shouldExtendMultipleTimes.

@Test
void shouldExtendMultipleTimes() {
    SimpleLock extendedLock = mock(SimpleLock.class);
    mockExtension(originalLock, Optional.of(extendedLock));
    mockExtension(extendedLock, Optional.of(extendedLock));
    Optional<SimpleLock> lock = provider.lock(lockConfiguration);
    assertThat(lock).isNotNull();
    tickMs(1_500);
    verify(originalLock).extend(lockConfiguration.getLockAtMostFor(), ofMillis(500));
    tickMs(1_500);
    verify(extendedLock).extend(lockConfiguration.getLockAtMostFor(), ZERO);
    lock.get().unlock();
    verify(extendedLock).unlock();
    tickMs(10_000);
    verifyNoMoreInteractions(originalLock);
}
Also used : SimpleLock(net.javacrumbs.shedlock.core.SimpleLock) Test(org.junit.jupiter.api.Test)

Example 2 with SimpleLock

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

the class AbstractExtensibleLockProviderIntegrationTest method shouldBeAbleToExtendAtLeast.

@Test
public void shouldBeAbleToExtendAtLeast() {
    SimpleLock lock = lock(Duration.ofSeconds(10));
    SimpleLock newLock = extendLock(lock);
    newLock.unlock();
    assertLocked(LOCK_NAME1);
}
Also used : SimpleLock(net.javacrumbs.shedlock.core.SimpleLock) Test(org.junit.jupiter.api.Test)

Example 3 with SimpleLock

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

the class AbstractExtensibleLockProviderIntegrationTest method lockCanNotBeUnlockedAfterExtending.

@Test
public void lockCanNotBeUnlockedAfterExtending() {
    SimpleLock lock = lock(Duration.ofSeconds(10));
    extendLock(lock);
    assertInvalidLock(lock::unlock);
}
Also used : SimpleLock(net.javacrumbs.shedlock.core.SimpleLock) Test(org.junit.jupiter.api.Test)

Example 4 with SimpleLock

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

Example 5 with SimpleLock

use of net.javacrumbs.shedlock.core.SimpleLock 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();
}
Also used : LockConfiguration(net.javacrumbs.shedlock.core.LockConfiguration) SimpleLock(net.javacrumbs.shedlock.core.SimpleLock) StorageBasedLockProvider(net.javacrumbs.shedlock.support.StorageBasedLockProvider) 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