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