Search in sources :

Example 1 with ConjureLockToken

use of com.palantir.atlasdb.timelock.api.ConjureLockToken in project atlasdb by palantir.

the class LockWatchEventCacheIntegrationTest method commitLocksAreCorrectlyFilteredOutUsingServerToken.

@Test
public void commitLocksAreCorrectlyFilteredOutUsingServerToken() {
    setupInitialState();
    eventCache.processStartTransactionsUpdate(ImmutableSet.of(), SUCCESS);
    // simulates the actual lock token that the client receives
    ConjureLockToken serverToken = ConjureLockToken.of(COMMIT_TOKEN.getRequestId());
    LockToken commitToken = LeasedLockTokenCreator.of(serverToken, Lease.of(LeaderTime.of(LeadershipId.random(), NanoTime.createForTests(1L)), Duration.ZERO));
    eventCache.processGetCommitTimestampsUpdate(ImmutableSet.of(TransactionUpdate.builder().commitTs(5L).startTs(START_TS_1).writesToken(commitToken).build()), SUCCESS_2);
    assertThat(eventCache.getCommitUpdate(START_TS_1).accept(new CommitUpdateVisitor())).containsExactlyInAnyOrder(DESCRIPTOR);
}
Also used : ConjureLockToken(com.palantir.atlasdb.timelock.api.ConjureLockToken) LockToken(com.palantir.lock.v2.LockToken) ConjureLockToken(com.palantir.atlasdb.timelock.api.ConjureLockToken) Test(org.junit.Test)

Example 2 with ConjureLockToken

use of com.palantir.atlasdb.timelock.api.ConjureLockToken in project atlasdb by palantir.

the class MultiNodePaxosTimeLockServerIntegrationTest method invalidateForcesLocksInTheRelevantNamespaceToBeReleased.

@Test
public void invalidateForcesLocksInTheRelevantNamespaceToBeReleased() {
    ConjureLockResponse lockResponse = client.conjureTimelockService().lock(AUTH_HEADER, client.namespace(), ConjureLockRequest.builder().requestId(UUID.randomUUID()).addAllLockDescriptors(ImmutableList.of(ConjureLockDescriptor.of(Bytes.from(PtBytes.toBytes("apple"))))).acquireTimeoutMs(1_000).clientDescription("tester").build());
    Optional<ConjureLockToken> token = lockResponse.accept(ToConjureLockTokenVisitor.INSTANCE);
    assertThat(token).as("could acquire an uncontended lock").isPresent();
    Set<ConjureLockToken> refreshedTokens = client.conjureTimelockService().refreshLocks(AUTH_HEADER, client.namespace(), ConjureRefreshLocksRequest.builder().tokens(token.get()).build()).getRefreshedTokens();
    assertThat(refreshedTokens).as("should still have the lock, as there were no intervening actions").containsExactly(token.get());
    invalidateMainClientResources();
    refreshedTokens = client.conjureTimelockService().refreshLocks(AUTH_HEADER, client.namespace(), ConjureRefreshLocksRequest.builder().tokens(token.get()).build()).getRefreshedTokens();
    assertThat(refreshedTokens).as("should no longer have the lock, because resources were invalidated").isEmpty();
}
Also used : ConjureLockToken(com.palantir.atlasdb.timelock.api.ConjureLockToken) ConjureLockResponse(com.palantir.atlasdb.timelock.api.ConjureLockResponse) Test(org.junit.Test)

Example 3 with ConjureLockToken

use of com.palantir.atlasdb.timelock.api.ConjureLockToken in project atlasdb by palantir.

the class MultiNodePaxosTimeLockServerIntegrationTest method invalidateDoesNotAffectLocksInOtherNamespaces.

@Test
public void invalidateDoesNotAffectLocksInOtherNamespaces() {
    ConjureLockResponse lockResponse = client.conjureTimelockService().lock(AUTH_HEADER, client.namespace(), ConjureLockRequest.builder().requestId(UUID.randomUUID()).addAllLockDescriptors(ImmutableList.of(ConjureLockDescriptor.of(Bytes.from(PtBytes.toBytes("apple"))))).acquireTimeoutMs(1_000).clientDescription("tester").build());
    Optional<ConjureLockToken> token = lockResponse.accept(ToConjureLockTokenVisitor.INSTANCE);
    invalidateClientResources("anotherNamespace");
    Set<ConjureLockToken> refreshedTokens = client.conjureTimelockService().refreshLocks(AUTH_HEADER, client.namespace(), ConjureRefreshLocksRequest.builder().tokens(token.get()).build()).getRefreshedTokens();
    assertThat(refreshedTokens).as("should still have the lock, because invalidation was in a different namespace").containsExactly(token.get());
}
Also used : ConjureLockToken(com.palantir.atlasdb.timelock.api.ConjureLockToken) ConjureLockResponse(com.palantir.atlasdb.timelock.api.ConjureLockResponse) Test(org.junit.Test)

Example 4 with ConjureLockToken

use of com.palantir.atlasdb.timelock.api.ConjureLockToken in project atlasdb by palantir.

the class MultiNodePaxosTimeLockServerIntegrationTest method multipleLockRequestsWithTheSameIdAreGranted.

@Test
public void multipleLockRequestsWithTheSameIdAreGranted() {
    ConjureLockRequest conjureLockRequest = ConjureLockRequests.toConjure(LockRequest.of(LOCKS, DEFAULT_LOCK_TIMEOUT_MS));
    Optional<ConjureLockToken> token1 = client.namespacedConjureTimelockService().lock(conjureLockRequest).accept(ToConjureLockTokenVisitor.INSTANCE);
    Optional<ConjureLockToken> token2 = Optional.empty();
    try {
        token2 = client.namespacedConjureTimelockService().lock(conjureLockRequest).accept(ToConjureLockTokenVisitor.INSTANCE);
        assertThat(token1).isPresent();
        assertThat(token1).isEqualTo(token2);
    } finally {
        Set<ConjureLockToken> tokens = Stream.of(token1, token2).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toSet());
        client.namespacedConjureTimelockService().unlock(ConjureUnlockRequest.of(tokens));
    }
}
Also used : Optional(java.util.Optional) ConjureLockRequest(com.palantir.atlasdb.timelock.api.ConjureLockRequest) ConjureLockToken(com.palantir.atlasdb.timelock.api.ConjureLockToken) Test(org.junit.Test)

Aggregations

ConjureLockToken (com.palantir.atlasdb.timelock.api.ConjureLockToken)4 Test (org.junit.Test)4 ConjureLockResponse (com.palantir.atlasdb.timelock.api.ConjureLockResponse)2 ConjureLockRequest (com.palantir.atlasdb.timelock.api.ConjureLockRequest)1 LockToken (com.palantir.lock.v2.LockToken)1 Optional (java.util.Optional)1