use of com.palantir.atlasdb.timelock.api.ConjureLockResponse in project atlasdb by palantir.
the class AtlasDbDialogueServiceProviderTest method lockRequestsBlockingLongerThanShortReadTimeoutAllowed.
@Test
public void lockRequestsBlockingLongerThanShortReadTimeoutAllowed() {
int lockBlockingMillis = Ints.checkedCast(ClientOptionsConstants.SHORT_READ_TIMEOUT.toJavaDuration().plusSeconds(1).toMillis());
server.stubFor(LOCK_MAPPING.willReturn(aResponse().withFixedDelay(lockBlockingMillis).withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody("{\"type\":\"unsuccessful\",\"unsuccessful\":{}}")));
ConjureLockResponse lockResponse = conjureTimelockService.lock(AuthHeader.valueOf("Bearer unused"), CLIENT, ConjureLockRequest.builder().acquireTimeoutMs(// Doesn't really matter: point is server takes a long time to return
0).clientDescription("I am a client").lockDescriptors(ConjureLockDescriptor.of(Bytes.from(PtBytes.toBytes("lock/lock")))).requestId(UUID.randomUUID()).build());
assertThat(lockResponse).isEqualTo(ConjureLockResponse.unsuccessful(UnsuccessfulLockResponse.of()));
}
use of com.palantir.atlasdb.timelock.api.ConjureLockResponse in project atlasdb by palantir.
the class LockDiagnosticConjureTimelockService method lock.
@Override
public ConjureLockResponse lock(AuthHeader authHeader, String namespace, ConjureLockRequest request) {
request.getClientDescription().flatMap(LockDiagnosticConjureTimelockService::tryParseStartTimestamp).ifPresent(startTimestamp -> lockDiagnosticCollector.collect(startTimestamp, request.getRequestId(), request.getLockDescriptors()));
ConjureLockResponse response = conjureDelegate.lock(authHeader, namespace, request);
localLockTracker.logLockResponse(request.getLockDescriptors(), response);
return response;
}
use of com.palantir.atlasdb.timelock.api.ConjureLockResponse 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.ConjureLockResponse 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.ConjureLockResponse in project atlasdb by palantir.
the class AsyncTimelockServiceIntegrationTest method lockRequestsToRpcClientAreIdempotent.
@Test
public void lockRequestsToRpcClientAreIdempotent() {
LockToken token = namespace.lock(requestFor(LOCK_A)).getToken();
ConjureLockRequest secondRequest = requestFor(CONJURE_LOCK_A);
CompletableFuture<ConjureLockResponse> responseFuture = lockWithRpcClientAsync(secondRequest);
CompletableFuture<ConjureLockResponse> duplicateResponseFuture = lockWithRpcClientAsync(secondRequest);
namespace.unlock(token);
ConjureLockResponse response = responseFuture.join();
ConjureLockResponse duplicateResponse = duplicateResponseFuture.join();
assertThat(response).isEqualTo(duplicateResponse);
namespace.namespacedConjureTimelockService().unlock(ConjureUnlockRequest.of(ImmutableSet.of(getToken(response))));
}
Aggregations