use of com.palantir.lock.v2.LeaderTime in project atlasdb by palantir.
the class MultiClientConjureTimelockResourceTest method canGetLeaderTimesForMultipleClients.
@Test
public void canGetLeaderTimesForMultipleClients() {
Namespace client1 = Namespace.of("client1");
Namespace client2 = Namespace.of("client2");
Set<Namespace> namespaces = ImmutableSet.of(client1, client2);
LeaderTimes leaderTimesResponse = Futures.getUnchecked(resource.leaderTimes(AUTH_HEADER, namespaces));
Map<Namespace, LeaderTime> leaderTimes = leaderTimesResponse.getLeaderTimes();
// leaderTimes for namespaces are computed by their respective underlying AsyncTimelockService instances
leaderTimes.forEach((namespace, leaderTime) -> {
assertThat(leaderTime.id()).isEqualTo(namespaceToLeaderMap.get(namespace.get()));
});
// there should be as many leaders as there are distinct clients
Set<UUID> leaders = leaderTimes.values().stream().map(LeaderTime::id).map(LeadershipId::id).collect(Collectors.toSet());
assertThat(leaders).hasSameSizeAs(namespaces);
}
use of com.palantir.lock.v2.LeaderTime 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.LeaderTime in project atlasdb by palantir.
the class LeasedLockTokenTest method assertExpiresExactlyAfter.
private void assertExpiresExactlyAfter(LeasedLockToken token, Duration duration) {
LeadershipId tokenLeaderId = token.getLease().leaderTime().id();
assertThat(token.isValid(LeaderTime.of(tokenLeaderId, currentTime.plus(duration.minus(Duration.ofNanos(1)))))).isTrue();
assertThat(token.isValid(LeaderTime.of(tokenLeaderId, currentTime.plus(duration)))).isFalse();
}
use of com.palantir.lock.v2.LeaderTime in project atlasdb by palantir.
the class MultiNodePaxosTimeLockServerIntegrationTest method sanityCheckMultiClientLeaderTime.
@Test
public void sanityCheckMultiClientLeaderTime() {
TestableTimelockServer leader = cluster.currentLeaderFor(client.namespace());
// Multi client batched TimeLock endpoints do not support multi-leader mode on TimeLock
Assume.assumeFalse(leader.isMultiLeader());
Set<Namespace> expectedNamespaces = ImmutableSet.of(Namespace.of("client1"), Namespace.of("client2"));
LeaderTimes leaderTimes = assertSanityAndGetLeaderTimes(leader, expectedNamespaces);
// leaderTimes for namespaces are computed by their respective underlying AsyncTimelockService instances
Set<UUID> leadershipIds = leaderTimes.getLeaderTimes().values().stream().map(LeaderTime::id).map(LeadershipId::id).collect(Collectors.toSet());
assertThat(leadershipIds).hasSameSizeAs(expectedNamespaces);
}
use of com.palantir.lock.v2.LeaderTime in project atlasdb by palantir.
the class MultiNodePaxosTimeLockServerIntegrationTest method sanityCheckMultiClientLeaderTimeAgainstConjureTimelockService.
@Test
public void sanityCheckMultiClientLeaderTimeAgainstConjureTimelockService() {
TestableTimelockServer leader = cluster.currentLeaderFor(client.namespace());
// Multi client batched TimeLock endpoints do not support multi-leader mode on TimeLock
Assume.assumeFalse(leader.isMultiLeader());
Set<Namespace> expectedNamespaces = ImmutableSet.of(Namespace.of("alpha"), Namespace.of("beta"));
LeaderTimes leaderTimes = assertSanityAndGetLeaderTimes(leader, expectedNamespaces);
// Whether we hit the multi client endpoint or conjureTimelockService endpoint(services one client in one
// call), for a namespace, the underlying service to process the request is the same
leaderTimes.getLeaderTimes().forEach((namespace, leaderTime) -> {
LeaderTime conjureTimelockServiceLeaderTime = leader.client(namespace.get()).namespacedConjureTimelockService().leaderTime();
assertThat(conjureTimelockServiceLeaderTime.id()).isEqualTo(leaderTime.id());
});
}
Aggregations