Search in sources :

Example 1 with LeadershipId

use of com.palantir.lock.v2.LeadershipId 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);
}
Also used : LeaderTime(com.palantir.lock.v2.LeaderTime) LeaderTimes(com.palantir.atlasdb.timelock.api.LeaderTimes) UUID(java.util.UUID) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 2 with LeadershipId

use of com.palantir.lock.v2.LeadershipId 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;
}
Also used : LeaderTime(com.palantir.lock.v2.LeaderTime) AsyncTimelockService(com.palantir.atlasdb.timelock.AsyncTimelockService) LeadershipId(com.palantir.lock.v2.LeadershipId)

Example 3 with LeadershipId

use of com.palantir.lock.v2.LeadershipId 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();
}
Also used : LeadershipId(com.palantir.lock.v2.LeadershipId)

Example 4 with LeadershipId

use of com.palantir.lock.v2.LeadershipId 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);
}
Also used : LeaderTime(com.palantir.lock.v2.LeaderTime) LeaderTimes(com.palantir.atlasdb.timelock.api.LeaderTimes) UUID(java.util.UUID) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Aggregations

LeaderTime (com.palantir.lock.v2.LeaderTime)3 LeaderTimes (com.palantir.atlasdb.timelock.api.LeaderTimes)2 Namespace (com.palantir.atlasdb.timelock.api.Namespace)2 LeadershipId (com.palantir.lock.v2.LeadershipId)2 UUID (java.util.UUID)2 Test (org.junit.Test)2 AsyncTimelockService (com.palantir.atlasdb.timelock.AsyncTimelockService)1