Search in sources :

Example 1 with ConjureLockResponse

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()));
}
Also used : ConjureLockResponse(com.palantir.atlasdb.timelock.api.ConjureLockResponse) Test(org.junit.Test)

Example 2 with ConjureLockResponse

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;
}
Also used : ConjureLockResponse(com.palantir.atlasdb.timelock.api.ConjureLockResponse)

Example 3 with ConjureLockResponse

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();
}
Also used : ConjureLockToken(com.palantir.atlasdb.timelock.api.ConjureLockToken) ConjureLockResponse(com.palantir.atlasdb.timelock.api.ConjureLockResponse) Test(org.junit.Test)

Example 4 with ConjureLockResponse

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());
}
Also used : ConjureLockToken(com.palantir.atlasdb.timelock.api.ConjureLockToken) ConjureLockResponse(com.palantir.atlasdb.timelock.api.ConjureLockResponse) Test(org.junit.Test)

Example 5 with ConjureLockResponse

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))));
}
Also used : ConjureLockRequest(com.palantir.atlasdb.timelock.api.ConjureLockRequest) ConjureLockToken(com.palantir.atlasdb.timelock.api.ConjureLockToken) LockToken(com.palantir.lock.v2.LockToken) ConjureLockResponse(com.palantir.atlasdb.timelock.api.ConjureLockResponse) Test(org.junit.Test)

Aggregations

ConjureLockResponse (com.palantir.atlasdb.timelock.api.ConjureLockResponse)5 Test (org.junit.Test)4 ConjureLockToken (com.palantir.atlasdb.timelock.api.ConjureLockToken)3 ConjureLockRequest (com.palantir.atlasdb.timelock.api.ConjureLockRequest)1 LockToken (com.palantir.lock.v2.LockToken)1