Search in sources :

Example 1 with LockToken

use of com.palantir.lock.v2.LockToken in project atlasdb by palantir.

the class AsyncTimelockServiceIntegrationTest method canLockRefreshAndUnlock.

@Test
public void canLockRefreshAndUnlock() {
    LockToken token = cluster.lock(requestFor(LOCK_A)).getToken();
    boolean wasRefreshed = cluster.refreshLockLease(token);
    boolean wasUnlocked = cluster.unlock(token);
    assertTrue(wasRefreshed);
    assertTrue(wasUnlocked);
}
Also used : LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Example 2 with LockToken

use of com.palantir.lock.v2.LockToken in project atlasdb by palantir.

the class AsyncTimelockServiceIntegrationTest method locksAreExclusive.

@Test
public void locksAreExclusive() {
    LockToken token = cluster.lock(requestFor(LOCK_A)).getToken();
    Future<LockToken> futureToken = cluster.lockAsync(requestFor(LOCK_A)).thenApply(LockResponse::getToken);
    assertNotYetLocked(futureToken);
    cluster.unlock(token);
    assertLockedAndUnlock(futureToken);
}
Also used : LockResponse(com.palantir.lock.v2.LockResponse) LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Example 3 with LockToken

use of com.palantir.lock.v2.LockToken in project atlasdb by palantir.

the class AsyncTimelockServiceIntegrationTest method canWaitForLocks.

@Test
public void canWaitForLocks() {
    LockToken token = cluster.lock(requestFor(LOCK_A, LOCK_B)).getToken();
    CompletableFuture<WaitForLocksResponse> future = cluster.waitForLocksAsync(waitRequestFor(LOCK_A, LOCK_B));
    assertNotDone(future);
    cluster.unlock(token);
    assertDone(future);
    assertThat(future.join().wasSuccessful()).isTrue();
}
Also used : WaitForLocksResponse(com.palantir.lock.v2.WaitForLocksResponse) LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Example 4 with LockToken

use of com.palantir.lock.v2.LockToken in project atlasdb by palantir.

the class AsyncTimelockServiceIntegrationTest method waitForLockRequestsAreIdempotent.

@Test
public void waitForLockRequestsAreIdempotent() {
    if (isUsingSyncAdapter(cluster)) {
        // legacy API does not support idempotence
        return;
    }
    LockToken token = cluster.lock(requestFor(LOCK_A)).getToken();
    WaitForLocksRequest request = waitRequestFor(LOCK_A);
    CompletableFuture<WaitForLocksResponse> response = cluster.waitForLocksAsync(request);
    CompletableFuture<WaitForLocksResponse> duplicateResponse = cluster.waitForLocksAsync(request);
    cluster.unlock(token);
    assertThat(response.join()).isEqualTo(duplicateResponse.join());
}
Also used : WaitForLocksRequest(com.palantir.lock.v2.WaitForLocksRequest) WaitForLocksResponse(com.palantir.lock.v2.WaitForLocksResponse) LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Example 5 with LockToken

use of com.palantir.lock.v2.LockToken in project atlasdb by palantir.

the class MultiNodePaxosTimeLockServerIntegrationTest method locksAreInvalidatedAcrossFailures.

@Test
public void locksAreInvalidatedAcrossFailures() throws InterruptedException {
    LockToken token = CLUSTER.lock(LockRequest.of(LOCKS, DEFAULT_LOCK_TIMEOUT_MS)).getToken();
    for (int i = 0; i < 3; i++) {
        CLUSTER.failoverToNewLeader();
        assertThat(CLUSTER.unlock(token)).isFalse();
        token = CLUSTER.lock(LockRequest.of(LOCKS, DEFAULT_LOCK_TIMEOUT_MS)).getToken();
    }
}
Also used : LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Aggregations

LockToken (com.palantir.lock.v2.LockToken)42 Test (org.junit.Test)32 LockResponse (com.palantir.lock.v2.LockResponse)5 TimelockService (com.palantir.lock.v2.TimelockService)4 LockRequest (com.palantir.lock.v2.LockRequest)3 WaitForLocksResponse (com.palantir.lock.v2.WaitForLocksResponse)3 Timer (com.codahale.metrics.Timer)1 SafeAndUnsafeTableReferences (com.palantir.atlasdb.logging.LoggingArgs.SafeAndUnsafeTableReferences)1 TransactionLockAcquisitionTimeoutException (com.palantir.atlasdb.transaction.api.TransactionLockAcquisitionTimeoutException)1 TransactionLockTimeoutException (com.palantir.atlasdb.transaction.api.TransactionLockTimeoutException)1 ShouldRetry (com.palantir.flake.ShouldRetry)1 AtlasCellLockDescriptor (com.palantir.lock.AtlasCellLockDescriptor)1 AtlasRowLockDescriptor (com.palantir.lock.AtlasRowLockDescriptor)1 LockDescriptor (com.palantir.lock.LockDescriptor)1 LockRefreshToken (com.palantir.lock.LockRefreshToken)1 LockImmutableTimestampResponse (com.palantir.lock.v2.LockImmutableTimestampResponse)1 WaitForLocksRequest (com.palantir.lock.v2.WaitForLocksRequest)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1