use of com.palantir.lock.v2.LockToken in project atlasdb by palantir.
the class LegacyTimelockServiceTest method unlockReturnsSubsetThatWereUnlocked.
@Test
public void unlockReturnsSubsetThatWereUnlocked() {
LockToken tokenA = randomLockToken();
LockToken tokenB = randomLockToken();
when(lockService.unlock(toLegacyToken(tokenA))).thenReturn(true);
when(lockService.unlock(toLegacyToken(tokenB))).thenReturn(false);
Set<LockToken> expected = ImmutableSet.of(tokenA);
assertEquals(expected, timelock.unlock(ImmutableSet.of(tokenA, tokenB)));
}
use of com.palantir.lock.v2.LockToken in project atlasdb by palantir.
the class LockTokenConverterTest method assertConversionFromAndToLegacyPreservesId.
private void assertConversionFromAndToLegacyPreservesId(LockRefreshToken lockRefreshToken) {
LockToken tokenV2 = LockTokenConverter.toTokenV2(lockRefreshToken);
LockRefreshToken reconverted = LockTokenConverter.toLegacyToken(tokenV2);
assertThat(reconverted).isEqualTo(lockRefreshToken);
}
use of com.palantir.lock.v2.LockToken in project atlasdb by palantir.
the class AsyncTimelockServiceImpl method lockImmutableTimestamp.
@Override
public LockImmutableTimestampResponse lockImmutableTimestamp(LockImmutableTimestampRequest request) {
long timestamp = timestampService.getFreshTimestamp();
// this will always return synchronously
LockToken token = lockService.lockImmutableTimestamp(request.getRequestId(), timestamp).get();
long immutableTs = lockService.getImmutableTimestamp().orElse(timestamp);
return LockImmutableTimestampResponse.of(immutableTs, token);
}
use of com.palantir.lock.v2.LockToken in project atlasdb by palantir.
the class AsyncTimelockServiceIntegrationTest method waitForLocksRequestCanTimeOut.
@Test
public void waitForLocksRequestCanTimeOut() {
if (isUsingSyncAdapter(cluster)) {
// legacy API does not support timeouts on this endpoint
return;
}
LockToken token = cluster.lock(requestFor(LOCK_A)).getToken();
WaitForLocksResponse response = cluster.waitForLocks(waitRequestFor(SHORT_TIMEOUT, LOCK_A));
assertThat(response.wasSuccessful()).isFalse();
cluster.unlock(token);
}
use of com.palantir.lock.v2.LockToken in project atlasdb by palantir.
the class AsyncTimelockServiceIntegrationTest method lockRequestsAreIdempotent.
@Test
public void lockRequestsAreIdempotent() {
if (isUsingSyncAdapter(cluster)) {
// legacy API does not support idempotence
return;
}
LockToken token = cluster.lock(requestFor(LOCK_A)).getToken();
LockRequest request = requestFor(LOCK_A);
CompletableFuture<LockResponse> response = cluster.lockAsync(request);
CompletableFuture<LockResponse> duplicateResponse = cluster.lockAsync(request);
cluster.unlock(token);
assertThat(response.join()).isEqualTo(duplicateResponse.join());
cluster.unlock(response.join().getToken());
}
Aggregations