Search in sources :

Example 26 with ConjureStartTransactionsResponse

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

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

the class MultiNodePaxosTimeLockServerIntegrationTest method startTransactionHandlesInvalidatesCorrectly.

@Test
public void startTransactionHandlesInvalidatesCorrectly() {
    ConjureStartTransactionsResponse responseBeforeInvalidation = client.namespacedConjureTimelockService().startTransactions(ConjureStartTransactionsRequest.builder().numTransactions(10).requestId(UUID.randomUUID()).requestorId(UUID.randomUUID()).build());
    invalidateMainClientResources();
    ConjureStartTransactionsResponse responseAfterInvalidation = client.namespacedConjureTimelockService().startTransactions(ConjureStartTransactionsRequest.builder().numTransactions(10).requestId(UUID.randomUUID()).requestorId(UUID.randomUUID()).build());
    assertThat(responseBeforeInvalidation.getTimestamps().stream().max().orElseThrow()).as("timestamps must strictly increase").isLessThan(responseAfterInvalidation.getTimestamps().stream().min().orElseThrow());
    assertThat(responseBeforeInvalidation.getLockWatchUpdate().logId()).as("lock watch log IDs must change following an invalidation").isNotEqualTo(responseAfterInvalidation.getLockWatchUpdate().logId());
}
Also used : ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) Test(org.junit.Test)

Example 28 with ConjureStartTransactionsResponse

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

the class MultiNodePaxosTimeLockServerIntegrationTest method multiClientStartTransactionsReturnsCorrectStartTimestamps.

@Test
public void multiClientStartTransactionsReturnsCorrectStartTimestamps() {
    TestableTimelockServer leader = cluster.currentLeaderFor(client.namespace());
    // Multi client batched TimeLock endpoints do not support multi-leader mode on TimeLock
    Assume.assumeFalse(leader.isMultiLeader());
    Namespace delta = Namespace.of("delta");
    Namespace gamma = Namespace.of("gamma");
    NamespacedClients deltaClient = leader.client(delta.get()).throughWireMockProxy();
    NamespacedClients gammaClient = leader.client(gamma.get()).throughWireMockProxy();
    List<String> expectedNamespaces = ImmutableList.of(delta.get(), gamma.get());
    int deltaFastForwardedTimestamp = 155_200_000;
    int gammaFastForwardedTimestamp = 988_000_000;
    deltaClient.timestampManagementService().fastForwardTimestamp(deltaFastForwardedTimestamp);
    gammaClient.timestampManagementService().fastForwardTimestamp(gammaFastForwardedTimestamp);
    Map<Namespace, ConjureStartTransactionsResponse> startedTransactions = assertSanityAndStartTransactions(leader, expectedNamespaces);
    assertThat(startedTransactions.get(delta).getTimestamps().start()).isGreaterThanOrEqualTo(deltaFastForwardedTimestamp).isLessThan(gammaFastForwardedTimestamp);
    assertThat(startedTransactions.get(gamma).getTimestamps().start()).isGreaterThanOrEqualTo(gammaFastForwardedTimestamp);
}
Also used : ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 29 with ConjureStartTransactionsResponse

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

ConjureStartTransactionsResponse (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse)29 Test (org.junit.Test)22 ImmutableList (com.google.common.collect.ImmutableList)12 List (java.util.List)12 Namespace (com.palantir.atlasdb.timelock.api.Namespace)9 StartIdentifiedAtlasDbTransactionResponse (com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse)9 ArrayList (java.util.ArrayList)9 BatchElement (com.palantir.atlasdb.autobatch.BatchElement)6 Cell (com.palantir.atlasdb.keyvalue.api.Cell)6 ConjureStartTransactionsRequest (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest)6 Transaction (com.palantir.atlasdb.transaction.api.Transaction)6 LockImmutableTimestampResponse (com.palantir.lock.v2.LockImmutableTimestampResponse)6 Optional (java.util.Optional)6 UUID (java.util.UUID)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 Iterables (com.google.common.collect.Iterables)5 Futures (com.google.common.util.concurrent.Futures)5 TimelockService (com.palantir.lock.v2.TimelockService)5