Search in sources :

Example 1 with StartIdentifiedAtlasDbTransactionResponse

use of com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse in project atlasdb by palantir.

the class MultiClientTransactionStarterTest method assertCompletedWithCorrectNumberOfTransactions.

private void assertCompletedWithCorrectNumberOfTransactions(List<BatchElement<NamespaceAndRequestParams, List<StartIdentifiedAtlasDbTransactionResponse>>> requestsForClients) {
    requestsForClients.forEach(batchElement -> {
        DisruptorFuture<List<StartIdentifiedAtlasDbTransactionResponse>> resultFuture = batchElement.result();
        NamespaceAndRequestParams requestParams = batchElement.argument();
        assertThat(resultFuture.isDone()).isTrue();
        List<StartIdentifiedAtlasDbTransactionResponse> responseList = Futures.getUnchecked(resultFuture);
        assertThat(responseList).hasSize(requestParams.params().numTransactions());
    });
}
Also used : StartIdentifiedAtlasDbTransactionResponse(com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse) NamespaceAndRequestParams(com.palantir.lock.client.MultiClientTransactionStarter.NamespaceAndRequestParams) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Example 2 with StartIdentifiedAtlasDbTransactionResponse

use of com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse in project atlasdb by palantir.

the class MultiClientTransactionStarterTest method servesRequestsAsSoonAsResponseIsReceived.

@Test
public void servesRequestsAsSoonAsResponseIsReceived() {
    Namespace namespace = Namespace.of("Test" + UUID.randomUUID());
    UUID requestorId = UUID.randomUUID();
    BatchElement<NamespaceAndRequestParams, List<StartIdentifiedAtlasDbTransactionResponse>> requestToBeServed = batchElementForNamespace(namespace, 1);
    BatchElement<NamespaceAndRequestParams, List<StartIdentifiedAtlasDbTransactionResponse>> requestNotToBeServed = batchElementForNamespace(namespace, PARTITIONED_TIMESTAMPS_LIMIT_PER_SERVER_CALL * 5);
    ImmutableList<BatchElement<NamespaceAndRequestParams, List<StartIdentifiedAtlasDbTransactionResponse>>> requests = ImmutableList.of(requestToBeServed, requestNotToBeServed);
    Map<Namespace, ConjureStartTransactionsResponse> responseMap = startTransactionsResponse(requests, requestorId);
    when(timelockService.startTransactions(any())).thenReturn(responseMap).thenThrow(EXCEPTION);
    assertThatThrownBy(() -> processBatch(timelockService, requestorId, requests)).isEqualTo(EXCEPTION);
    // assert first request is served even if server throws on next request
    assertSanityOfRequestBatch(ImmutableList.of(requestToBeServed), ImmutableMap.of(namespace, ImmutableList.of(responseMap.get(namespace))));
    assertThat(requestNotToBeServed.result().isDone()).isFalse();
    LockCleanupService relevantLockCleanupService = LOCK_CLEANUP_SERVICE_MAP.get(namespace);
    verify(relevantLockCleanupService).refreshLockLeases(any());
    verify(relevantLockCleanupService).unlock(any());
    /*
         * For one space, all requests are accumulated, and we attempt to fetch as many respones as possible from the
         * server. Concretely, the queue here contains 25 demands for a response. The first one succeeds, but the
         * next four fail (and each batch size is five), and thus we get four calls to clean up.
         */
    verify(NAMESPACE_CACHE_MAP.get(namespace), times(4)).removeTransactionStateFromCache(anyLong());
}
Also used : StartIdentifiedAtlasDbTransactionResponse(com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) NamespaceAndRequestParams(com.palantir.lock.client.MultiClientTransactionStarter.NamespaceAndRequestParams) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) BatchElement(com.palantir.atlasdb.autobatch.BatchElement) UUID(java.util.UUID) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 3 with StartIdentifiedAtlasDbTransactionResponse

use of com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse in project atlasdb by palantir.

the class MultiClientTransactionStarterTest method shouldNotFreeResourcesIfRequestIsServed.

@Test
public void shouldNotFreeResourcesIfRequestIsServed() {
    Namespace alpha = Namespace.of("alpha" + UUID.randomUUID());
    Namespace beta = Namespace.of("beta" + UUID.randomUUID());
    BatchElement<NamespaceAndRequestParams, List<StartIdentifiedAtlasDbTransactionResponse>> requestForAlpha = batchElementForNamespace(alpha, PARTITIONED_TIMESTAMPS_LIMIT_PER_SERVER_CALL - 1);
    BatchElement<NamespaceAndRequestParams, List<StartIdentifiedAtlasDbTransactionResponse>> requestForBeta = batchElementForNamespace(beta, PARTITIONED_TIMESTAMPS_LIMIT_PER_SERVER_CALL * 5);
    UUID requestorId = UUID.randomUUID();
    List<BatchElement<NamespaceAndRequestParams, List<StartIdentifiedAtlasDbTransactionResponse>>> requests = ImmutableList.of(requestForAlpha, requestForBeta);
    Map<Namespace, ConjureStartTransactionsResponse> responseMap = startTransactionsResponse(requests, requestorId);
    when(timelockService.startTransactions(any())).thenReturn(responseMap).thenThrow(EXCEPTION);
    assertThatThrownBy(() -> processBatch(timelockService, requestorId, requests)).isEqualTo(EXCEPTION);
    // assert requests made by client alpha are served
    assertSanityOfRequestBatch(ImmutableList.of(requestForAlpha), ImmutableMap.of(alpha, ImmutableList.of(responseMap.get(alpha))));
    verify(LOCK_CLEANUP_SERVICE_MAP.get(alpha), never()).unlock(any());
    verify(LOCK_CLEANUP_SERVICE_MAP.get(beta)).refreshLockLeases(any());
    verify(LOCK_CLEANUP_SERVICE_MAP.get(beta)).unlock(any());
    verify(NAMESPACE_CACHE_MAP.get(alpha), never()).removeTransactionStateFromCache(anyLong());
    // The size of each batch is 5 here, and thus for a single batch we need to clean up five times
    verify(NAMESPACE_CACHE_MAP.get(beta), times(5)).removeTransactionStateFromCache(anyLong());
}
Also used : StartIdentifiedAtlasDbTransactionResponse(com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) NamespaceAndRequestParams(com.palantir.lock.client.MultiClientTransactionStarter.NamespaceAndRequestParams) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) BatchElement(com.palantir.atlasdb.autobatch.BatchElement) UUID(java.util.UUID) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 4 with StartIdentifiedAtlasDbTransactionResponse

use of com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse in project atlasdb by palantir.

the class TransactionStarterTest method shouldDeriveStartTransactionResponseFromBatchedResponse_nonTrivialBatchSize.

@Test
public void shouldDeriveStartTransactionResponseFromBatchedResponse_nonTrivialBatchSize() {
    ConjureStartTransactionsResponse batchResponse = StartTransactionsTestUtils.getStartTransactionResponse(40, 10);
    when(lockLeaseService.startTransactionsWithWatches(version, 10)).thenReturn(batchResponse);
    ImmutableList<Integer> sizes = ImmutableList.of(2, 3, 4, 1);
    List<List<StartIdentifiedAtlasDbTransactionResponse>> responses = requestBatches(sizes);
    Streams.forEachPair(responses.stream(), sizes.stream(), (response, size) -> assertThat(response).hasSize(size).allSatisfy(startTxnResponse -> assertDerivableFromBatchedResponse(startTxnResponse, batchResponse)));
    assertThat(flattenResponses(responses)).satisfies(StartTransactionsTestUtils::assertThatStartTransactionResponsesAreUnique);
}
Also used : IntStream(java.util.stream.IntStream) Iterables(com.google.common.collect.Iterables) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Mockito.spy(org.mockito.Mockito.spy) BatchElement(com.palantir.atlasdb.autobatch.BatchElement) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) Lists(com.google.common.collect.Lists) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) After(org.junit.After) LockWatchCache(com.palantir.lock.watch.LockWatchCache) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) DisruptorAutobatcher(com.palantir.atlasdb.autobatch.DisruptorAutobatcher) Before(org.junit.Before) ImmutableSet(com.google.common.collect.ImmutableSet) LockWatchVersion(com.palantir.lock.watch.LockWatchVersion) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Streams(com.google.common.collect.Streams) Mockito.verify(org.mockito.Mockito.verify) Collectors.toList(java.util.stream.Collectors.toList) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) StartIdentifiedAtlasDbTransactionResponse(com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse) LockWatchCacheImpl(com.palantir.lock.watch.LockWatchCacheImpl) Optional(java.util.Optional) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Test(org.junit.Test)

Example 5 with StartIdentifiedAtlasDbTransactionResponse

use of com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse in project atlasdb by palantir.

the class TransactionStarterTest method shouldDeriveStartTransactionResponseBatchFromBatchedResponse_multipleTransactions.

@Test
public void shouldDeriveStartTransactionResponseBatchFromBatchedResponse_multipleTransactions() {
    ConjureStartTransactionsResponse batchResponse = StartTransactionsTestUtils.getStartTransactionResponse(12, 5);
    when(lockLeaseService.startTransactionsWithWatches(version, 5)).thenReturn(batchResponse);
    List<StartIdentifiedAtlasDbTransactionResponse> responses = transactionStarter.startIdentifiedAtlasDbTransactionBatch(5);
    assertThat(responses).satisfies(StartTransactionsTestUtils::assertThatStartTransactionResponsesAreUnique).hasSize(5).allSatisfy(startTxnResponse -> assertDerivableFromBatchedResponse(startTxnResponse, batchResponse));
}
Also used : StartIdentifiedAtlasDbTransactionResponse(com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) Test(org.junit.Test)

Aggregations

StartIdentifiedAtlasDbTransactionResponse (com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse)14 ConjureStartTransactionsResponse (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse)10 Test (org.junit.Test)10 ImmutableList (com.google.common.collect.ImmutableList)9 List (java.util.List)9 BatchElement (com.palantir.atlasdb.autobatch.BatchElement)7 ArrayList (java.util.ArrayList)6 Namespace (com.palantir.atlasdb.timelock.api.Namespace)5 NamespaceAndRequestParams (com.palantir.lock.client.MultiClientTransactionStarter.NamespaceAndRequestParams)5 UUID (java.util.UUID)5 LockToken (com.palantir.lock.v2.LockToken)4 LockWatchCache (com.palantir.lock.watch.LockWatchCache)4 Collectors (java.util.stream.Collectors)4 DisruptorAutobatcher (com.palantir.atlasdb.autobatch.DisruptorAutobatcher)3 Preconditions (com.palantir.logsafe.Preconditions)3 Duration (java.time.Duration)3 Optional (java.util.Optional)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Iterables (com.google.common.collect.Iterables)2