Search in sources :

Example 1 with MultiClientConjureTimelockService

use of com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService in project atlasdb by palantir.

the class MultiNodePaxosTimeLockServerIntegrationTest method assertSanityAndGetLeaderTimes.

private LeaderTimes assertSanityAndGetLeaderTimes(TestableTimelockServer leader, Set<Namespace> expectedNamespaces) {
    MultiClientConjureTimelockService multiClientConjureTimelockService = leader.multiClientService();
    LeaderTimes leaderTimes = multiClientConjureTimelockService.leaderTimes(AUTH_HEADER, expectedNamespaces);
    Set<Namespace> namespaces = leaderTimes.getLeaderTimes().keySet();
    assertThat(namespaces).hasSameElementsAs(expectedNamespaces);
    return leaderTimes;
}
Also used : MultiClientConjureTimelockService(com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService) LeaderTimes(com.palantir.atlasdb.timelock.api.LeaderTimes) Namespace(com.palantir.atlasdb.timelock.api.Namespace)

Example 2 with MultiClientConjureTimelockService

use of com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService in project atlasdb by palantir.

the class MultiNodePaxosTimeLockServerIntegrationTest method sanityCheckMultiClientGetCommitTimestampsAgainstConjureTimelockService.

@Test
public void sanityCheckMultiClientGetCommitTimestampsAgainstConjureTimelockService() {
    TestableTimelockServer leader = cluster.currentLeaderFor(client.namespace());
    // Multi client batched TimeLock endpoints do not support multi-leader mode on TimeLock
    Assume.assumeFalse(leader.isMultiLeader());
    MultiClientConjureTimelockService multiClientService = leader.multiClientService();
    Set<String> expectedNamespaces = ImmutableSet.of("alta", "mp");
    Map<Namespace, GetCommitTimestampsResponse> multiClientResponses = multiClientService.getCommitTimestampsForClients(AUTH_HEADER, defaultGetCommitTimestampsRequests(expectedNamespaces));
    assertSanityOfNamespacesServed(expectedNamespaces, multiClientResponses);
    // 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
    multiClientResponses.forEach((namespace, responseFromBatchedEndpoint) -> {
        GetCommitTimestampsResponse conjureGetCommitTimestampResponse = leader.client(namespace.get()).namespacedConjureTimelockService().getCommitTimestamps(defaultCommitTimestampRequest());
        assertThat(conjureGetCommitTimestampResponse.getLockWatchUpdate().logId()).isEqualTo(responseFromBatchedEndpoint.getLockWatchUpdate().logId());
        assertThat(conjureGetCommitTimestampResponse.getInclusiveLower()).as("timestamps should contiguously increase per namespace if there are no elections.").isEqualTo(responseFromBatchedEndpoint.getInclusiveUpper() + 1);
    });
}
Also used : MultiClientConjureTimelockService(com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService) Namespace(com.palantir.atlasdb.timelock.api.Namespace) GetCommitTimestampsResponse(com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse) Test(org.junit.Test)

Example 3 with MultiClientConjureTimelockService

use of com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService in project atlasdb by palantir.

the class MultiNodePaxosTimeLockServerIntegrationTest method assertSanityAndStartTransactions.

private Map<Namespace, ConjureStartTransactionsResponse> assertSanityAndStartTransactions(TestableTimelockServer leader, List<String> expectedNamespaces) {
    MultiClientConjureTimelockService multiClientConjureTimelockService = leader.multiClientService();
    int numTransactions = 5;
    Map<Namespace, ConjureStartTransactionsRequest> namespaceToRequestMap = defaultStartTransactionsRequests(expectedNamespaces, numTransactions);
    Map<Namespace, ConjureStartTransactionsResponse> startedTransactions = multiClientConjureTimelockService.startTransactionsForClients(AUTH_HEADER, namespaceToRequestMap);
    Set<String> namespaces = startedTransactions.keySet().stream().map(Namespace::get).collect(Collectors.toSet());
    assertThat(namespaces).hasSameElementsAs(expectedNamespaces);
    assertThat(startedTransactions.values().stream().map(ConjureStartTransactionsResponse::getTimestamps).mapToLong(partitionedTimestamps -> partitionedTimestamps.stream().count()).sum()).isEqualTo(namespaces.size() * numTransactions);
    return startedTransactions;
}
Also used : MethodSorters(org.junit.runners.MethodSorters) LeadershipId(com.palantir.lock.v2.LeadershipId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) AuthHeader(com.palantir.tokens.auth.AuthHeader) ConjureLockDescriptor(com.palantir.atlasdb.timelock.api.ConjureLockDescriptor) MultiLeaderPaxosSuite(com.palantir.atlasdb.timelock.suite.MultiLeaderPaxosSuite) LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) Bytes(com.palantir.conjure.java.lib.Bytes) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) ConjureStartTransactionsRequest(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest) LeaderTime(com.palantir.lock.v2.LeaderTime) ConjureLockRequest(com.palantir.atlasdb.timelock.api.ConjureLockRequest) Duration(java.time.Duration) Map(java.util.Map) GetCommitTimestampsResponse(com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse) SuccessfulLockResponse(com.palantir.atlasdb.timelock.api.SuccessfulLockResponse) ConjureLockResponse(com.palantir.atlasdb.timelock.api.ConjureLockResponse) ClassRule(org.junit.ClassRule) Parameterized(org.junit.runners.Parameterized) LockDescriptor(com.palantir.lock.LockDescriptor) ConjureLockToken(com.palantir.atlasdb.timelock.api.ConjureLockToken) ImmutableSet(com.google.common.collect.ImmutableSet) KeyedStream(com.palantir.common.streams.KeyedStream) ConjureLockRequests(com.palantir.lock.client.ConjureLockRequests) Set(java.util.Set) ConjureUnlockRequest(com.palantir.atlasdb.timelock.api.ConjureUnlockRequest) UUID(java.util.UUID) ConjureLockRefreshToken(com.palantir.lock.ConjureLockRefreshToken) LockMode(com.palantir.lock.LockMode) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) Stream(java.util.stream.Stream) ClientOptionsConstants(com.palantir.atlasdb.http.v2.ClientOptionsConstants) PartitionedTimestamps(com.palantir.lock.v2.PartitionedTimestamps) Optional(java.util.Optional) ConjureLockV1Request(com.palantir.lock.ConjureLockV1Request) FixMethodOrder(org.junit.FixMethodOrder) WaitForLocksRequest(com.palantir.lock.v2.WaitForLocksRequest) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) MultiClientConjureTimelockService(com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService) ExceptionMatchers(com.palantir.atlasdb.timelock.util.ExceptionMatchers) Iterables(com.google.common.collect.Iterables) HeldLocksToken(com.palantir.lock.HeldLocksToken) RunWith(org.junit.runner.RunWith) GetCommitTimestampsRequest(com.palantir.atlasdb.timelock.api.GetCommitTimestampsRequest) UnsuccessfulLockResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulLockResponse) SimpleHeldLocksToken(com.palantir.lock.SimpleHeldLocksToken) LockRefreshToken(com.palantir.lock.LockRefreshToken) PtBytes(com.palantir.atlasdb.encoding.PtBytes) HashSet(java.util.HashSet) ConjureSimpleHeldLocksToken(com.palantir.lock.ConjureSimpleHeldLocksToken) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) WaitForLocksResponse(com.palantir.lock.v2.WaitForLocksResponse) Assume(org.junit.Assume) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Before(org.junit.Before) LockResponse(com.palantir.lock.v2.LockResponse) LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test) ConjureRefreshLocksRequest(com.palantir.atlasdb.timelock.api.ConjureRefreshLocksRequest) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Ints(com.google.common.primitives.Ints) ExecutionException(java.util.concurrent.ExecutionException) LockRequest(com.palantir.lock.v2.LockRequest) LockClient(com.palantir.lock.LockClient) StringLockDescriptor(com.palantir.lock.StringLockDescriptor) LeaderTimes(com.palantir.atlasdb.timelock.api.LeaderTimes) ParameterInjector(com.palantir.atlasdb.timelock.util.ParameterInjector) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) MultiClientConjureTimelockService(com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService) ConjureStartTransactionsRequest(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest) Namespace(com.palantir.atlasdb.timelock.api.Namespace)

Example 4 with MultiClientConjureTimelockService

use of com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService in project atlasdb by palantir.

the class MultiNodePaxosTimeLockServerIntegrationTest method sanityCheckMultiClientGetCommitTimestamps.

@Test
public void sanityCheckMultiClientGetCommitTimestamps() {
    TestableTimelockServer leader = cluster.currentLeaderFor(client.namespace());
    // Multi client batched TimeLock endpoints do not support multi-leader mode on TimeLock
    Assume.assumeFalse(leader.isMultiLeader());
    MultiClientConjureTimelockService service = leader.multiClientService();
    Set<String> expectedNamespaces = ImmutableSet.of("cli-1", "cli-2");
    Map<Namespace, GetCommitTimestampsResponse> multiClientResponses = service.getCommitTimestampsForClients(AUTH_HEADER, defaultGetCommitTimestampsRequests(expectedNamespaces));
    assertSanityOfNamespacesServed(expectedNamespaces, multiClientResponses);
    Set<UUID> leadershipIds = multiClientResponses.values().stream().map(GetCommitTimestampsResponse::getLockWatchUpdate).map(LockWatchStateUpdate::logId).collect(Collectors.toSet());
    assertThat(leadershipIds).hasSameSizeAs(expectedNamespaces);
}
Also used : MultiClientConjureTimelockService(com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService) UUID(java.util.UUID) Namespace(com.palantir.atlasdb.timelock.api.Namespace) GetCommitTimestampsResponse(com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse) Test(org.junit.Test)

Example 5 with MultiClientConjureTimelockService

use of com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService in project atlasdb by palantir.

the class MultiNodePaxosTimeLockServerIntegrationTest method sanityCheckMultiClientStartTransactionsAgainstConjureTimelockService.

@Test
public void sanityCheckMultiClientStartTransactionsAgainstConjureTimelockService() {
    TestableTimelockServer leader = cluster.currentLeaderFor(client.namespace());
    // Multi client batched TimeLock endpoints do not support multi-leader mode on TimeLock
    Assume.assumeFalse(leader.isMultiLeader());
    MultiClientConjureTimelockService multiClientConjureTimelockService = leader.multiClientService();
    List<String> expectedNamespaces = ImmutableList.of("alpha", "beta");
    int numTransactions = 7;
    Map<Namespace, ConjureStartTransactionsRequest> namespaceToRequestMap = defaultStartTransactionsRequests(expectedNamespaces, numTransactions);
    Map<Namespace, ConjureStartTransactionsResponse> startedTransactions = multiClientConjureTimelockService.startTransactionsForClients(AUTH_HEADER, namespaceToRequestMap);
    // Whether we hit the multi client endpoint or conjureTimelockService endpoint, for a namespace, the underlying
    // service to process the request is the same
    startedTransactions.forEach((namespace, responseFromBatchedEndpoint) -> {
        ConjureStartTransactionsResponse responseFromLegacyEndpoint = leader.client(namespace.get()).namespacedConjureTimelockService().startTransactions(namespaceToRequestMap.get(namespace));
        assertThat(responseFromLegacyEndpoint.getLockWatchUpdate().logId()).isEqualTo(responseFromBatchedEndpoint.getLockWatchUpdate().logId());
        PartitionedTimestamps batchedEndpointTimestamps = responseFromBatchedEndpoint.getTimestamps();
        long lastTimestamp = batchedEndpointTimestamps.stream().max().orElseThrow(SafeIllegalStateException::new);
        assertThat(responseFromLegacyEndpoint.getTimestamps().start()).isGreaterThan(lastTimestamp);
    });
}
Also used : MultiClientConjureTimelockService(com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService) ConjureStartTransactionsRequest(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest) PartitionedTimestamps(com.palantir.lock.v2.PartitionedTimestamps) Namespace(com.palantir.atlasdb.timelock.api.Namespace) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) Test(org.junit.Test)

Aggregations

MultiClientConjureTimelockService (com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService)5 Namespace (com.palantir.atlasdb.timelock.api.Namespace)5 Test (org.junit.Test)4 GetCommitTimestampsResponse (com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse)3 ConjureStartTransactionsRequest (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest)2 ConjureStartTransactionsResponse (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse)2 LeaderTimes (com.palantir.atlasdb.timelock.api.LeaderTimes)2 PartitionedTimestamps (com.palantir.lock.v2.PartitionedTimestamps)2 SafeIllegalStateException (com.palantir.logsafe.exceptions.SafeIllegalStateException)2 UUID (java.util.UUID)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 Iterables (com.google.common.collect.Iterables)1 Sets (com.google.common.collect.Sets)1 Ints (com.google.common.primitives.Ints)1 PtBytes (com.palantir.atlasdb.encoding.PtBytes)1 ClientOptionsConstants (com.palantir.atlasdb.http.v2.ClientOptionsConstants)1 ConjureLockDescriptor (com.palantir.atlasdb.timelock.api.ConjureLockDescriptor)1 ConjureLockRequest (com.palantir.atlasdb.timelock.api.ConjureLockRequest)1