Search in sources :

Example 6 with ConjureStartTransactionsRequest

use of com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest 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 7 with ConjureStartTransactionsRequest

use of com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest 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

ConjureStartTransactionsRequest (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest)7 ConjureStartTransactionsResponse (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse)5 Namespace (com.palantir.atlasdb.timelock.api.Namespace)3 Test (org.junit.Test)3 ImmutableList (com.google.common.collect.ImmutableList)2 MultiClientConjureTimelockService (com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService)2 LockResponse (com.palantir.lock.v2.LockResponse)2 LockToken (com.palantir.lock.v2.LockToken)2 PartitionedTimestamps (com.palantir.lock.v2.PartitionedTimestamps)2 WaitForLocksRequest (com.palantir.lock.v2.WaitForLocksRequest)2 SafeIllegalStateException (com.palantir.logsafe.exceptions.SafeIllegalStateException)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 UUID (java.util.UUID)2 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