Search in sources :

Example 1 with LeaderTime

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);
}
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 LeaderTime

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

Example 3 with LeaderTime

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

Example 4 with LeaderTime

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);
}
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 5 with LeaderTime

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

Aggregations

LeaderTime (com.palantir.lock.v2.LeaderTime)8 Test (org.junit.Test)8 LeaderTimes (com.palantir.atlasdb.timelock.api.LeaderTimes)3 Namespace (com.palantir.atlasdb.timelock.api.Namespace)3 LockToken (com.palantir.lock.v2.LockToken)3 Set (java.util.Set)3 UUID (java.util.UUID)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 LeadershipId (com.palantir.lock.v2.LeadershipId)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Sets (com.google.common.collect.Sets)1 AsyncTimelockService (com.palantir.atlasdb.timelock.AsyncTimelockService)1 ConjureLockToken (com.palantir.atlasdb.timelock.api.ConjureLockToken)1 ConjureRefreshLocksRequest (com.palantir.atlasdb.timelock.api.ConjureRefreshLocksRequest)1 ConjureRefreshLocksResponse (com.palantir.atlasdb.timelock.api.ConjureRefreshLocksResponse)1 ConjureStartTransactionsRequest (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest)1 ConjureStartTransactionsResponse (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse)1 ConjureUnlockRequest (com.palantir.atlasdb.timelock.api.ConjureUnlockRequest)1 GetCommitTimestampsRequest (com.palantir.atlasdb.timelock.api.GetCommitTimestampsRequest)1 GetCommitTimestampsResponse (com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse)1