Search in sources :

Example 16 with LockRefreshToken

use of com.palantir.lock.LockRefreshToken in project atlasdb by palantir.

the class LockTokenConverterTest method throwsIfBigIntegerHasMoreThan127Bits.

@Test
public void throwsIfBigIntegerHasMoreThan127Bits() {
    BigInteger bigInt = BigInteger.valueOf(2).pow(127);
    LockRefreshToken token = new LockRefreshToken(bigInt, 0L);
    assertThatThrownBy(() -> LockTokenConverter.toTokenV2(token)).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("too many bits");
}
Also used : BigInteger(java.math.BigInteger) LockRefreshToken(com.palantir.lock.LockRefreshToken) Test(org.junit.Test)

Example 17 with LockRefreshToken

use of com.palantir.lock.LockRefreshToken in project atlasdb by palantir.

the class AsyncTimelockServiceIntegrationTest method unlockAndFreezeDoesNotAllowRefreshes.

@Test
public void unlockAndFreezeDoesNotAllowRefreshes() throws InterruptedException {
    HeldLocksToken token = lockWithFullResponse(requestForWriteLock(LOCK_A), TEST_CLIENT);
    cluster.lockService().unlockAndFreeze(token);
    Set<LockRefreshToken> lockRefreshTokens = cluster.lockService().refreshLockRefreshTokens(ImmutableList.of(token.getLockRefreshToken()));
    assertThat(lockRefreshTokens).isEmpty();
}
Also used : HeldLocksToken(com.palantir.lock.HeldLocksToken) SimpleHeldLocksToken(com.palantir.lock.SimpleHeldLocksToken) LockRefreshToken(com.palantir.lock.LockRefreshToken) Test(org.junit.Test)

Example 18 with LockRefreshToken

use of com.palantir.lock.LockRefreshToken in project atlasdb by palantir.

the class AsyncTimelockServiceIntegrationTest method canPerformLockAndRefreshLock.

@Test
public void canPerformLockAndRefreshLock() throws InterruptedException {
    HeldLocksToken token1 = lockWithFullResponse(requestForWriteLock(LOCK_A), TEST_CLIENT);
    LockRefreshToken token = token1.getLockRefreshToken();
    Set<LockRefreshToken> lockRefreshTokens = cluster.lockService().refreshLockRefreshTokens(ImmutableList.of(token));
    assertThat(lockRefreshTokens).contains(token);
    unlock(token1);
}
Also used : HeldLocksToken(com.palantir.lock.HeldLocksToken) SimpleHeldLocksToken(com.palantir.lock.SimpleHeldLocksToken) LockRefreshToken(com.palantir.lock.LockRefreshToken) Test(org.junit.Test)

Example 19 with LockRefreshToken

use of com.palantir.lock.LockRefreshToken in project atlasdb by palantir.

the class MultiNodePaxosTimeLockServerIntegrationTest method blockedLockRequestThrows503OnLeaderElectionForRemoteLock.

@Test
public void blockedLockRequestThrows503OnLeaderElectionForRemoteLock() throws InterruptedException {
    LockRefreshToken lock = CLUSTER.remoteLock(CLIENT_1, BLOCKING_LOCK_REQUEST);
    assertThat(lock).isNotNull();
    TestableTimelockServer leader = CLUSTER.currentLeader();
    CompletableFuture<LockRefreshToken> lockRefreshTokenCompletableFuture = CompletableFuture.supplyAsync(() -> {
        try {
            return leader.remoteLock(CLIENT_2, BLOCKING_LOCK_REQUEST);
        } catch (InterruptedException e) {
            return null;
        }
    });
    Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
    CLUSTER.nonLeaders().forEach(TestableTimelockServer::kill);
    // Lock on leader so that AwaitingLeadershipProxy notices leadership loss.
    assertThatThrownBy(() -> leader.remoteLock(CLIENT_3, BLOCKING_LOCK_REQUEST)).satisfies(ExceptionMatchers::isRetryableExceptionWhereLeaderCannotBeFound);
    assertThat(catchThrowable(lockRefreshTokenCompletableFuture::get).getCause()).satisfies(ExceptionMatchers::isRetryableExceptionWhereLeaderCannotBeFound);
}
Also used : LockRefreshToken(com.palantir.lock.LockRefreshToken) ExceptionMatchers(com.palantir.atlasdb.timelock.util.ExceptionMatchers) Test(org.junit.Test)

Example 20 with LockRefreshToken

use of com.palantir.lock.LockRefreshToken in project atlasdb by palantir.

the class PaxosTimeLockServerIntegrationTest method lockServiceShouldNotAllowUsToRefreshLocksFromDifferentNamespaces.

@Test
public void lockServiceShouldNotAllowUsToRefreshLocksFromDifferentNamespaces() throws InterruptedException {
    LockService lockService1 = getLockService(CLIENT_1);
    LockService lockService2 = getLockService(CLIENT_2);
    LockRefreshToken token = lockService1.lock(LOCK_CLIENT_NAME, com.palantir.lock.LockRequest.builder(LOCK_MAP).doNotBlock().build());
    assertThat(token).isNotNull();
    assertThat(lockService1.refreshLockRefreshTokens(ImmutableList.of(token))).isNotEmpty();
    assertThat(lockService2.refreshLockRefreshTokens(ImmutableList.of(token))).isEmpty();
    lockService1.unlock(token);
}
Also used : LockService(com.palantir.lock.LockService) LockRefreshToken(com.palantir.lock.LockRefreshToken) Test(org.junit.Test)

Aggregations

LockRefreshToken (com.palantir.lock.LockRefreshToken)22 Test (org.junit.Test)12 LockService (com.palantir.lock.LockService)6 LockDescriptor (com.palantir.lock.LockDescriptor)5 HeldLocksToken (com.palantir.lock.HeldLocksToken)4 LockRequest (com.palantir.lock.LockRequest)4 SimpleHeldLocksToken (com.palantir.lock.SimpleHeldLocksToken)3 StringLockDescriptor (com.palantir.lock.StringLockDescriptor)3 BigInteger (java.math.BigInteger)3 AtlasTimestampLockDescriptor (com.palantir.lock.AtlasTimestampLockDescriptor)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GlobalClock (com.palantir.atlasdb.cleaner.GlobalClock)1 SingleBackendCliTestRunner (com.palantir.atlasdb.cli.runner.SingleBackendCliTestRunner)1 Cell (com.palantir.atlasdb.keyvalue.api.Cell)1 DaggerTestAtlasDbServices (com.palantir.atlasdb.services.test.DaggerTestAtlasDbServices)1 TestAtlasDbServices (com.palantir.atlasdb.services.test.TestAtlasDbServices)1 ExceptionMatchers (com.palantir.atlasdb.timelock.util.ExceptionMatchers)1 Clock (com.palantir.common.time.Clock)1 AtlasRowLockDescriptor (com.palantir.lock.AtlasRowLockDescriptor)1 LockClient (com.palantir.lock.LockClient)1