Search in sources :

Example 26 with LockToken

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

the class LegacyTimelockServiceTest method unlockReturnsSubsetThatWereUnlocked.

@Test
public void unlockReturnsSubsetThatWereUnlocked() {
    LockToken tokenA = randomLockToken();
    LockToken tokenB = randomLockToken();
    when(lockService.unlock(toLegacyToken(tokenA))).thenReturn(true);
    when(lockService.unlock(toLegacyToken(tokenB))).thenReturn(false);
    Set<LockToken> expected = ImmutableSet.of(tokenA);
    assertEquals(expected, timelock.unlock(ImmutableSet.of(tokenA, tokenB)));
}
Also used : LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Example 27 with LockToken

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

the class LockTokenConverterTest method assertConversionFromAndToLegacyPreservesId.

private void assertConversionFromAndToLegacyPreservesId(LockRefreshToken lockRefreshToken) {
    LockToken tokenV2 = LockTokenConverter.toTokenV2(lockRefreshToken);
    LockRefreshToken reconverted = LockTokenConverter.toLegacyToken(tokenV2);
    assertThat(reconverted).isEqualTo(lockRefreshToken);
}
Also used : LockToken(com.palantir.lock.v2.LockToken) LockRefreshToken(com.palantir.lock.LockRefreshToken)

Example 28 with LockToken

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

the class AsyncTimelockServiceImpl method lockImmutableTimestamp.

@Override
public LockImmutableTimestampResponse lockImmutableTimestamp(LockImmutableTimestampRequest request) {
    long timestamp = timestampService.getFreshTimestamp();
    // this will always return synchronously
    LockToken token = lockService.lockImmutableTimestamp(request.getRequestId(), timestamp).get();
    long immutableTs = lockService.getImmutableTimestamp().orElse(timestamp);
    return LockImmutableTimestampResponse.of(immutableTs, token);
}
Also used : LockToken(com.palantir.lock.v2.LockToken)

Example 29 with LockToken

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

the class AsyncTimelockServiceIntegrationTest method waitForLocksRequestCanTimeOut.

@Test
public void waitForLocksRequestCanTimeOut() {
    if (isUsingSyncAdapter(cluster)) {
        // legacy API does not support timeouts on this endpoint
        return;
    }
    LockToken token = cluster.lock(requestFor(LOCK_A)).getToken();
    WaitForLocksResponse response = cluster.waitForLocks(waitRequestFor(SHORT_TIMEOUT, LOCK_A));
    assertThat(response.wasSuccessful()).isFalse();
    cluster.unlock(token);
}
Also used : WaitForLocksResponse(com.palantir.lock.v2.WaitForLocksResponse) LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Example 30 with LockToken

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

the class AsyncTimelockServiceIntegrationTest method lockRequestsAreIdempotent.

@Test
public void lockRequestsAreIdempotent() {
    if (isUsingSyncAdapter(cluster)) {
        // legacy API does not support idempotence
        return;
    }
    LockToken token = cluster.lock(requestFor(LOCK_A)).getToken();
    LockRequest request = requestFor(LOCK_A);
    CompletableFuture<LockResponse> response = cluster.lockAsync(request);
    CompletableFuture<LockResponse> duplicateResponse = cluster.lockAsync(request);
    cluster.unlock(token);
    assertThat(response.join()).isEqualTo(duplicateResponse.join());
    cluster.unlock(response.join().getToken());
}
Also used : LockResponse(com.palantir.lock.v2.LockResponse) LockToken(com.palantir.lock.v2.LockToken) LockRequest(com.palantir.lock.v2.LockRequest) 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