Search in sources :

Example 1 with ConjureLockRequest

use of com.palantir.atlasdb.timelock.api.ConjureLockRequest 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)

Example 2 with ConjureLockRequest

use of com.palantir.atlasdb.timelock.api.ConjureLockRequest 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

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