Search in sources :

Example 1 with LockProvider

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

the class AbstractSchedulerConfig method lockProvider.

@Bean
public LockProvider lockProvider() {
    LockProvider lockProvider = mock(LockProvider.class);
    when(lockProvider.lock(any())).thenReturn(Optional.of(mock(SimpleLock.class)));
    return lockProvider;
}
Also used : LockProvider(net.javacrumbs.shedlock.core.LockProvider) Bean(org.springframework.context.annotation.Bean)

Example 2 with LockProvider

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

the class MongoLockProviderIntegrationTest method shouldLockWhenDocumentRemovedExternally.

@Test
public void shouldLockWhenDocumentRemovedExternally() {
    LockProvider provider = getLockProvider();
    assertThat(provider.lock(lockConfig(LOCK_NAME1))).isNotEmpty();
    assertLocked(LOCK_NAME1);
    DeleteResult result = getLockCollection().deleteOne(eq(ID, LOCK_NAME1));
    assumeThat(result.getDeletedCount()).isEqualTo(1);
    assertThat(provider.lock(lockConfig(LOCK_NAME1))).isNotEmpty();
    assertLocked(LOCK_NAME1);
}
Also used : LockProvider(net.javacrumbs.shedlock.core.LockProvider) ExtensibleLockProvider(net.javacrumbs.shedlock.core.ExtensibleLockProvider) DeleteResult(com.mongodb.client.result.DeleteResult) AbstractExtensibleLockProviderIntegrationTest(net.javacrumbs.shedlock.test.support.AbstractExtensibleLockProviderIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with LockProvider

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

the class ReactiveStreamsMongoLockProviderIntegrationTest method shouldLockWhenDocumentRemovedExternally.

@Test
public void shouldLockWhenDocumentRemovedExternally() {
    LockProvider provider = getLockProvider();
    assertThat(provider.lock(lockConfig(LOCK_NAME1))).isNotEmpty();
    assertLocked(LOCK_NAME1);
    DeleteResult result = execute(getLockCollection().deleteOne(eq(ID, LOCK_NAME1)));
    assumeThat(result.getDeletedCount()).isEqualTo(1);
    assertThat(provider.lock(lockConfig(LOCK_NAME1))).isNotEmpty();
    assertLocked(LOCK_NAME1);
}
Also used : LockProvider(net.javacrumbs.shedlock.core.LockProvider) ExtensibleLockProvider(net.javacrumbs.shedlock.core.ExtensibleLockProvider) DeleteResult(com.mongodb.client.result.DeleteResult) AbstractExtensibleLockProviderIntegrationTest(net.javacrumbs.shedlock.test.support.AbstractExtensibleLockProviderIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with LockProvider

use of net.javacrumbs.shedlock.core.LockProvider 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 5 with LockProvider

use of net.javacrumbs.shedlock.core.LockProvider 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)

Aggregations

LockProvider (net.javacrumbs.shedlock.core.LockProvider)6 Test (org.junit.jupiter.api.Test)5 SimpleLock (net.javacrumbs.shedlock.core.SimpleLock)3 DeleteResult (com.mongodb.client.result.DeleteResult)2 ExtensibleLockProvider (net.javacrumbs.shedlock.core.ExtensibleLockProvider)2 AbstractExtensibleLockProviderIntegrationTest (net.javacrumbs.shedlock.test.support.AbstractExtensibleLockProviderIntegrationTest)2 Bean (org.springframework.context.annotation.Bean)1