use of com.palantir.atlasdb.autobatch.BatchElement in project atlasdb by palantir.
the class WriteBatchingTransactionServiceTest method repeatedProcessBatchOnlyMakesOneCallWithDuplicatesIfSuccessful.
@Test
public void repeatedProcessBatchOnlyMakesOneCallWithDuplicatesIfSuccessful() {
KeyAlreadyExistsException exception = new KeyAlreadyExistsException("boo", ImmutableList.of(ENCODING_STRATEGY.encodeStartTimestampAsCell(5L)));
doNothing().doThrow(exception).when(mockTransactionService).putUnlessExistsMultiple(anyMap());
int numRequests = 100;
List<BatchElement<WriteBatchingTransactionService.TimestampPair, Void>> batchedRequest = IntStream.range(0, numRequests).mapToObj(unused -> TestTransactionBatchElement.of(5L, 9L)).collect(Collectors.toList());
WriteBatchingTransactionService.processBatch(mockTransactionService, batchedRequest);
AtomicInteger successCount = new AtomicInteger();
AtomicInteger failureCount = new AtomicInteger();
getResultsTrackingOutcomes(batchedRequest, successCount, failureCount);
verify(mockTransactionService, times(1)).putUnlessExistsMultiple(anyMap());
verify(mockTransactionService, atLeastOnce()).getCellEncodingStrategy();
// XXX Technically invalid, but valid for a mock transaction service.
assertThat(successCount).hasValue(1);
assertThat(failureCount).hasValue(numRequests - 1);
}
use of com.palantir.atlasdb.autobatch.BatchElement in project atlasdb by palantir.
the class WriteBatchingTransactionServiceTest method throwsExceptionsCorrectlyOnDuplicatedElementsInBatch.
@Test
public void throwsExceptionsCorrectlyOnDuplicatedElementsInBatch() throws InterruptedException {
EncodingTransactionService encodingTransactionService = SimpleTransactionService.createV1(new InMemoryKeyValueService(true));
int numRequests = 100;
List<BatchElement<WriteBatchingTransactionService.TimestampPair, Void>> batchedRequest = IntStream.range(0, numRequests).mapToObj(unused -> TestTransactionBatchElement.of(1L, 5L)).collect(Collectors.toList());
WriteBatchingTransactionService.processBatch(encodingTransactionService, batchedRequest);
AtomicInteger successCounter = new AtomicInteger();
AtomicInteger exceptionCounter = new AtomicInteger();
for (BatchElement<WriteBatchingTransactionService.TimestampPair, Void> batchElement : batchedRequest) {
try {
batchElement.result().get();
successCounter.incrementAndGet();
} catch (ExecutionException ex) {
assertThat(ex).hasCauseInstanceOf(KeyAlreadyExistsException.class).satisfies(executionException -> {
KeyAlreadyExistsException keyAlreadyExistsException = (KeyAlreadyExistsException) executionException.getCause();
assertThat(keyAlreadyExistsException.getExistingKeys()).containsExactly(encodingTransactionService.getCellEncodingStrategy().encodeStartTimestampAsCell(1L));
});
exceptionCounter.incrementAndGet();
}
}
// XXX Not something reasonable to assume in production (since the one successful call might actually
// return fail while succeeding on the KVS), but acceptable for In Memory KVS.
assertThat(successCounter).hasValue(1);
assertThat(exceptionCounter).hasValue(numRequests - 1);
}
Aggregations