use of net.javacrumbs.shedlock.core.SimpleLock in project ShedLock by lukas-krecan.
the class ConsulLockProviderIntegrationTest method shouldTimeout.
@Test
@Override
public void shouldTimeout() throws InterruptedException {
// as consul has 10 seconds ttl minimum and has double ttl unlocking time, you have to wait for 20 seconds for the unlock time.
Duration lockAtMostFor = Duration.ofSeconds(11);
LockConfiguration configWithShortTimeout = lockConfig(LOCK_NAME1, lockAtMostFor, Duration.ZERO);
Optional<SimpleLock> lock1 = getLockProvider().lock(configWithShortTimeout);
assertThat(lock1).isNotEmpty();
sleep(lockAtMostFor.multipliedBy(2).toMillis() + 100);
assertUnlocked(LOCK_NAME1);
Optional<SimpleLock> lock2 = getLockProvider().lock(lockConfig(LOCK_NAME1, Duration.ofMillis(50), Duration.ZERO));
assertThat(lock2).isNotEmpty();
lock2.get().unlock();
}
use of net.javacrumbs.shedlock.core.SimpleLock in project ShedLock by lukas-krecan.
the class ConsulLockProviderIntegrationTest method shouldNotTimeoutIfLessThanMinTtlPassed.
@Test
public void shouldNotTimeoutIfLessThanMinTtlPassed() throws InterruptedException {
Duration lockAtMostFor = Duration.ofSeconds(1);
LockConfiguration configWithShortTimeout = lockConfig(LOCK_NAME1, lockAtMostFor, Duration.ZERO);
Optional<SimpleLock> lock1 = getLockProvider().lock(configWithShortTimeout);
assertThat(lock1).isNotEmpty();
sleep(lockAtMostFor.multipliedBy(2).toMillis() + 100);
assertLocked(LOCK_NAME1);
// release lock to satisfy condition for #checkSessions()
lock1.get().unlock();
}
use of net.javacrumbs.shedlock.core.SimpleLock in project ShedLock by lukas-krecan.
the class HsqlJdbcTemplateLockProviderIntegrationTest method shouldBeAbleToSetCustomColumnNames.
@Test
public void shouldBeAbleToSetCustomColumnNames() throws SQLException {
try (Connection conn = dbConfig.getDataSource().getConnection();
Statement statement = conn.createStatement()) {
statement.execute("CREATE TABLE shdlck(n VARCHAR(64), lck_untl TIMESTAMP(3), lckd_at TIMESTAMP(3), lckd_by VARCHAR(255), PRIMARY KEY (n))");
}
JdbcTemplateLockProvider provider = new JdbcTemplateLockProvider(builder().withTableName("shdlck").withColumnNames(new ColumnNames("n", "lck_untl", "lckd_at", "lckd_by")).withJdbcTemplate(new JdbcTemplate(dbConfig.getDataSource())).withLockedByValue("my-value").build());
Optional<SimpleLock> lock = provider.lock(new LockConfiguration(now(), "test", Duration.ofSeconds(10), Duration.ZERO));
lock.get().unlock();
}
use of net.javacrumbs.shedlock.core.SimpleLock in project ShedLock by lukas-krecan.
the class MemcachedLockProviderIntegrationTest method doTestTimeout.
/**
* memcached smallest unit is second.
*/
@Override
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.ofSeconds(1), Duration.ZERO));
assertThat(lock2).isNotEmpty();
lock2.get().unlock();
}
use of net.javacrumbs.shedlock.core.SimpleLock in project ShedLock by lukas-krecan.
the class AbstractJdbcLockProviderIntegrationTest method shouldNotFailIfKeyNameTooLong.
@Test
@Disabled
public void shouldNotFailIfKeyNameTooLong() {
LockConfiguration configuration = lockConfig("lock name that is too long Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
Optional<SimpleLock> lock = getLockProvider().lock(configuration);
assertThat(lock).isEmpty();
}
Aggregations