use of com.palantir.lock.v2.LeaderTime in project atlasdb by palantir.
the class HeldLocksCollectionTest method emptyRefreshResponse.
@Test
public void emptyRefreshResponse() {
LockToken t1 = LockToken.of(UUID.randomUUID());
LockToken t2 = LockToken.of(UUID.randomUUID());
Leased<Set<LockToken>> refreshResult = heldLocksCollection.refresh(ImmutableSet.of(t1, t2));
assertThat(refreshResult.value()).isEmpty();
assertThat(refreshResult.lease().leaderTime().currentTime()).isLessThanOrEqualTo(time.get());
}
use of com.palantir.lock.v2.LeaderTime in project atlasdb by palantir.
the class HeldLocksCollectionTest method leaseShouldStartBeforeRefreshTime.
@Test
public void leaseShouldStartBeforeRefreshTime() {
LockToken t1 = lockSync(REQUEST_ID);
LockToken t2 = lockSync(REQUEST_ID_2);
Set<LockToken> tokens = ImmutableSet.of(t1, t2);
Leased<Set<LockToken>> refreshResult = heldLocksCollection.refresh(tokens);
NanoTime t1RefreshTime = heldLocksCollection.heldLocksById.get(t1.getRequestId()).get().lastRefreshTime();
NanoTime t2RefreshTime = heldLocksCollection.heldLocksById.get(t2.getRequestId()).get().lastRefreshTime();
NanoTime minRefreshTime = t1RefreshTime.isBefore(t2RefreshTime) ? t1RefreshTime : t2RefreshTime;
assertThat(refreshResult.lease().leaderTime().currentTime()).isLessThan(minRefreshTime);
}
use of com.palantir.lock.v2.LeaderTime in project atlasdb by palantir.
the class LockLeaseService method refreshLockLeases.
Set<LockToken> refreshLockLeases(Set<LockToken> uncastedTokens) {
if (uncastedTokens.isEmpty()) {
return uncastedTokens;
}
LeaderTime leaderTime = leaderTimeGetter.leaderTime();
Set<LeasedLockToken> allTokens = leasedTokens(uncastedTokens);
Set<LeasedLockToken> validByLease = allTokens.stream().filter(token -> token.isValid(leaderTime)).collect(Collectors.toSet());
Set<LeasedLockToken> toRefresh = Sets.difference(allTokens, validByLease);
Set<LeasedLockToken> refreshedTokens = refreshTokens(toRefresh);
return Sets.union(refreshedTokens, validByLease);
}
use of com.palantir.lock.v2.LeaderTime in project atlasdb by palantir.
the class MultiNodePaxosTimeLockServerIntegrationTest method leaderIdChangesAcrossFailovers.
@Test
public void leaderIdChangesAcrossFailovers() {
Set<LeaderTime> leaderTimes = new HashSet<>();
leaderTimes.add(client.namespacedConjureTimelockService().leaderTime());
for (int i = 0; i < 3; i++) {
cluster.failoverToNewLeader(client.namespace());
LeaderTime leaderTime = client.namespacedConjureTimelockService().leaderTime();
leaderTimes.forEach(previousLeaderTime -> assertThat(previousLeaderTime.isComparableWith(leaderTime)).isFalse());
leaderTimes.add(leaderTime);
}
}
use of com.palantir.lock.v2.LeaderTime in project atlasdb by palantir.
the class MultiNodePaxosTimeLockServerIntegrationTest method invalidateChangesLeaderIdentifier.
@Test
public void invalidateChangesLeaderIdentifier() {
LeaderTime timeBeforeInvalidation = client.conjureTimelockService().leaderTime(AUTH_HEADER, client.namespace());
invalidateMainClientResources();
LeaderTime timeAfterInvalidation = client.conjureTimelockService().leaderTime(AUTH_HEADER, client.namespace());
assertThat(timeBeforeInvalidation.id()).isNotEqualTo(timeAfterInvalidation.id());
}
Aggregations