use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class SnapshotTransactionTest method noWritesAddedToSweepQueueOnConflict.
@Test
public void noWritesAddedToSweepQueueOnConflict() {
Cell cell = Cell.create("foo".getBytes(), "bar".getBytes());
byte[] value = new byte[1];
Transaction t1 = txManager.createNewTransaction();
Transaction t2 = txManager.createNewTransaction();
t1.put(TABLE, ImmutableMap.of(cell, value));
t2.put(TABLE, ImmutableMap.of(cell, new byte[1]));
t1.commit();
verify(sweepQueue).enqueue(any(), any());
try {
t2.commit();
fail();
} catch (TransactionConflictException e) {
// expected
}
verifyNoMoreInteractions(sweepQueue);
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class SnapshotTransactionTest method testWriteWriteConflictsDeletedThrow.
@Test
public void testWriteWriteConflictsDeletedThrow() {
overrideConflictHandlerForTable(TABLE, ConflictHandler.RETRY_ON_WRITE_WRITE);
final Cell cell = Cell.create(PtBytes.toBytes("row1"), PtBytes.toBytes("column1"));
Transaction t1 = txManager.createNewTransaction();
Transaction t2 = txManager.createNewTransaction();
t1.delete(TABLE, ImmutableSet.of(cell));
t2.delete(TABLE, ImmutableSet.of(cell));
t1.commit();
try {
t2.commit();
fail();
} catch (TransactionConflictException e) {
// good
}
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class StreamTest method testStreamMetadataConflictWriteFirst.
@Test
public void testStreamMetadataConflictWriteFirst() throws Exception {
long streamId = timestampService.getFreshTimestamp();
runConflictingTasksConcurrently(streamId, new TwoConflictingTasks() {
@Override
public void startFirstAndFail(Transaction tx, long streamId) {
DeletingStreamStore deletingStreamStore = new DeletingStreamStore(StreamTestStreamStore.of(txManager, StreamTestTableFactory.of()));
deletingStreamStore.deleteStreams(tx, ImmutableSet.of(streamId));
}
@Override
public void startSecondAndFinish(Transaction tx, long streamId) {
StreamTestStreamStore ss = StreamTestStreamStore.of(txManager, StreamTestTableFactory.of());
ss.storeStreams(tx, ImmutableMap.of(streamId, new ByteArrayInputStream(new byte[1])));
}
});
Optional<InputStream> stream = getStream(streamId);
assertTrue(stream.isPresent());
assertNotNull(stream.get());
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class AbstractTransactionTest method testColumnRangePagingTransaction.
@Test
public void testColumnRangePagingTransaction() {
Transaction t = startTransaction();
int totalPuts = 101;
byte[] row = PtBytes.toBytes("row1");
// Record expected results using byte ordering
ImmutableSortedMap.Builder<Cell, byte[]> writes = ImmutableSortedMap.orderedBy(Ordering.from(UnsignedBytes.lexicographicalComparator()).onResultOf(key -> key.getColumnName()));
for (int i = 0; i < totalPuts; i++) {
put(t, "row1", "col" + i, "v" + i);
writes.put(Cell.create(row, PtBytes.toBytes("col" + i)), PtBytes.toBytes("v" + i));
}
t.commit();
t = startTransaction();
Map<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> columnRange = t.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1));
List<Map.Entry<Cell, byte[]>> expected = ImmutableList.copyOf(writes.build().entrySet());
verifyMatchingResult(expected, row, columnRange);
columnRange = t.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.toBytes("col"), PtBytes.EMPTY_BYTE_ARRAY, 1));
verifyMatchingResult(expected, row, columnRange);
columnRange = t.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.toBytes("col"), PtBytes.EMPTY_BYTE_ARRAY, 101));
verifyMatchingResult(expected, row, columnRange);
columnRange = t.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, RangeRequests.nextLexicographicName(expected.get(expected.size() - 1).getKey().getColumnName()), 1));
verifyMatchingResult(expected, row, columnRange);
columnRange = t.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, expected.get(expected.size() - 1).getKey().getColumnName(), 1));
verifyMatchingResult(ImmutableList.copyOf(Iterables.limit(expected, 100)), row, columnRange);
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class AbstractTransactionTest method testRangesTransaction.
@Test
public void testRangesTransaction() {
Transaction t = startTransaction();
put(t, "row1", "col1", "v1");
t.commit();
RangeRequest allRange = RangeRequest.builder().batchHint(3).build();
t = startTransaction();
verifyAllGetRangesImplsRangeSizes(t, allRange, 1);
}
Aggregations