Search in sources :

Example 16 with LockToken

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

the class AsyncLockServiceEteTest method requestsAreIdempotentAfterBeingAcquired.

@Test
public void requestsAreIdempotentAfterBeingAcquired() {
    LockToken token = lockSynchronously(REQUEST_1, LOCK_A);
    LockToken duplicate = lockSynchronously(REQUEST_1, LOCK_A);
    assertThat(token).isEqualTo(duplicate);
}
Also used : LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Example 17 with LockToken

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

the class AsyncLockServiceEteTest method canUnlockAfterRefreshing.

@Test
public void canUnlockAfterRefreshing() {
    LockToken token = lockSynchronously(REQUEST_1, LOCK_A);
    service.refresh(token);
    assertTrue(service.unlock(token));
}
Also used : LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Example 18 with LockToken

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

the class HeldLocksCollectionTest method mockFailedRequest.

private LockToken mockFailedRequest() {
    LockToken request = LockToken.of(UUID.randomUUID());
    AsyncResult failedLocks = new AsyncResult();
    failedLocks.fail(new RuntimeException());
    heldLocksCollection.getExistingOrAcquire(request.getRequestId(), () -> failedLocks);
    return request;
}
Also used : LockToken(com.palantir.lock.v2.LockToken)

Example 19 with LockToken

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

the class HeldLocksCollectionTest method refreshReturnsSubsetOfUnlockedLocks.

@Test
public void refreshReturnsSubsetOfUnlockedLocks() {
    LockToken unlockableRequest = mockRefreshableRequest();
    LockToken nonUnlockableRequest = mockNonRefreshableRequest();
    Set<LockToken> expected = ImmutableSet.of(unlockableRequest);
    Set<LockToken> actual = heldLocksCollection.refresh(ImmutableSet.of(unlockableRequest, nonUnlockableRequest));
    assertThat(actual).isEqualTo(expected);
}
Also used : LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Example 20 with LockToken

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

the class HeldLocksCollectionTest method successfulUnlockRemovesHeldLocks.

@Test
public void successfulUnlockRemovesHeldLocks() {
    LockToken token = mockRefreshableRequest();
    heldLocksCollection.unlock(ImmutableSet.of(token));
    assertThat(heldLocksCollection.heldLocksById.isEmpty()).isTrue();
}
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