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);
}
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();
}
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());
}
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));
}
}
Aggregations