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());
});
}
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());
}
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());
}
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);
}
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));
}
Aggregations