use of com.palantir.lock.v2.Lease in project atlasdb by palantir.
the class MultiClientConjureTimelockResourceTest method createAsyncTimeLockServiceForClient.
private AsyncTimelockService createAsyncTimeLockServiceForClient(String client) {
AsyncTimelockService timelockService = mock(AsyncTimelockService.class);
LeadershipId leadershipId = namespaceToLeaderMap.computeIfAbsent(client, _u -> LeadershipId.random());
LeaderTime leaderTime = LeaderTime.of(leadershipId, NanoTime.createForTests(1L));
when(timelockService.leaderTime()).thenReturn(Futures.immediateFuture(leaderTime));
when(timelockService.startTransactionsWithWatches(any())).thenReturn(Futures.immediateFuture(ConjureStartTransactionsResponse.builder().immutableTimestamp(lockImmutableTimestampResponse).lease(Lease.of(leaderTime, Duration.ofSeconds(977))).timestamps(partitionedTimestamps).lockWatchUpdate(lockWatchStateUpdate).build()));
when(timelockService.getCommitTimestamps(anyInt(), any())).thenReturn(Futures.immediateFuture(getCommitTimestampResponse(client)));
return timelockService;
}
use of com.palantir.lock.v2.Lease in project atlasdb by palantir.
the class LeasedLockTokenTest method ignoreRefreshIfNewLeaseGoesBackInTime.
@Test
public void ignoreRefreshIfNewLeaseGoesBackInTime() {
Lease oldLease = getLease();
advance(Duration.ofNanos(123));
LeasedLockToken token = LeasedLockToken.of(LOCK_TOKEN, getLease());
assertExpiresExactlyAfter(token, LEASE_TIMEOUT);
token.updateLease(oldLease);
assertExpiresExactlyAfter(token, LEASE_TIMEOUT);
}
use of com.palantir.lock.v2.Lease in project atlasdb by palantir.
the class LeasedLockTokenTest method throwIfRefreshedWithDifferentLeaderId.
@Test
public void throwIfRefreshedWithDifferentLeaderId() {
LeasedLockToken token = LeasedLockToken.of(LOCK_TOKEN, getLease());
Lease otherLease = Lease.of(LeaderTime.of(OTHER_LEADER_ID, currentTime), LEASE_TIMEOUT);
assertThatThrownBy(() -> token.updateLease(otherLease)).hasMessageStartingWith("Lock leases can only be refreshed by lease owners.");
}
use of com.palantir.lock.v2.Lease in project atlasdb by palantir.
the class LockLeaseServiceTest method startTransactionsResponseHasCorrectLeasedLock.
@Test
public void startTransactionsResponseHasCorrectLeasedLock() {
Lease lease = getLease();
when(timelock.startTransactions(any())).thenReturn(startTransactionsResponseWith(LOCK_TOKEN, lease));
StartTransactionResponseV4 clientResponse = lockLeaseService.startTransactions(2);
verify(timelock).startTransactions(any());
LeasedLockToken leasedLock = (LeasedLockToken) clientResponse.immutableTimestamp().getLock();
assertThat(leasedLock.serverToken()).isEqualTo(LOCK_TOKEN);
assertThat(leasedLock.getLease()).isEqualTo(lease);
}
use of com.palantir.lock.v2.Lease in project atlasdb by palantir.
the class LockLeaseService method startTransactions.
StartTransactionResponseV4 startTransactions(int batchSize) {
ConjureStartTransactionsRequest request = ConjureStartTransactionsRequest.builder().requestorId(clientId).requestId(UUID.randomUUID()).numTransactions(batchSize).lastKnownVersion(Optional.empty()).build();
ConjureStartTransactionsResponse conjureResponse = delegate.startTransactions(request);
StartTransactionResponseV4 response = StartTransactionResponseV4.of(conjureResponse.getImmutableTimestamp(), conjureResponse.getTimestamps(), conjureResponse.getLease());
Lease lease = response.lease();
LeasedLockToken leasedLockToken = LeasedLockToken.of(ConjureLockToken.of(response.immutableTimestamp().getLock().getRequestId()), lease);
long immutableTs = response.immutableTimestamp().getImmutableTimestamp();
return StartTransactionResponseV4.of(LockImmutableTimestampResponse.of(immutableTs, leasedLockToken), response.timestamps(), lease);
}
Aggregations