Search in sources :

Example 6 with Transaction

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);
}
Also used : Transaction(com.palantir.atlasdb.transaction.api.Transaction) TransactionConflictException(com.palantir.atlasdb.transaction.api.TransactionConflictException) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 7 with Transaction

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
    }
}
Also used : Transaction(com.palantir.atlasdb.transaction.api.Transaction) TransactionConflictException(com.palantir.atlasdb.transaction.api.TransactionConflictException) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 8 with Transaction

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());
}
Also used : StreamTestStreamStore(com.palantir.atlasdb.schema.stream.generated.StreamTestStreamStore) Transaction(com.palantir.atlasdb.transaction.api.Transaction) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DeletingStreamStore(com.palantir.atlasdb.schema.stream.generated.DeletingStreamStore) Test(org.junit.Test)

Example 9 with Transaction

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);
}
Also used : RangeRequests(com.palantir.atlasdb.keyvalue.api.RangeRequests) Arrays(java.util.Arrays) AtlasDbDependencyException(com.palantir.common.exception.AtlasDbDependencyException) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) Throwables(com.palantir.common.base.Throwables) ClosableIterator(com.palantir.common.base.ClosableIterator) Random(java.util.Random) MapEntries(com.palantir.common.collect.MapEntries) BatchingVisitable(com.palantir.common.base.BatchingVisitable) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Assert.fail(org.junit.Assert.fail) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) TransactionReadSentinelBehavior(com.palantir.atlasdb.transaction.api.TransactionReadSentinelBehavior) TableDefinition(com.palantir.atlasdb.table.description.TableDefinition) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) TransactionConflictException(com.palantir.atlasdb.transaction.api.TransactionConflictException) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IterableView(com.palantir.common.collect.IterableView) ValueType(com.palantir.atlasdb.table.description.ValueType) Transaction(com.palantir.atlasdb.transaction.api.Transaction) Assert.assertFalse(org.junit.Assert.assertFalse) NoOpCleaner(com.palantir.atlasdb.cleaner.NoOpCleaner) Iterables(com.google.common.collect.Iterables) ConflictHandler(com.palantir.atlasdb.transaction.api.ConflictHandler) FutureTask(java.util.concurrent.FutureTask) Multimap(com.google.common.collect.Multimap) Iterators(com.google.common.collect.Iterators) PtBytes(com.palantir.atlasdb.encoding.PtBytes) Multimaps(com.google.common.collect.Multimaps) AtlasDbConstraintCheckingMode(com.palantir.atlasdb.transaction.api.AtlasDbConstraintCheckingMode) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) LegacyTimelockService(com.palantir.lock.impl.LegacyTimelockService) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) AbortingVisitors(com.palantir.common.base.AbortingVisitors) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) BatchingVisitables(com.palantir.common.base.BatchingVisitables) ExecutorService(java.util.concurrent.ExecutorService) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) TableMetadataPersistence(com.palantir.atlasdb.protos.generated.TableMetadataPersistence) UnsignedBytes(com.google.common.primitives.UnsignedBytes) Value(com.palantir.atlasdb.keyvalue.api.Value) BaseEncoding(com.google.common.io.BaseEncoding) Assert.assertTrue(org.junit.Assert.assertTrue) TimestampCache(com.palantir.atlasdb.cache.TimestampCache) Test(org.junit.Test) TokenBackedBasicResultsPage(com.palantir.util.paging.TokenBackedBasicResultsPage) Maps(com.google.common.collect.Maps) Pair(com.palantir.util.Pair) ExecutionException(java.util.concurrent.ExecutionException) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) Assert.assertNull(org.junit.Assert.assertNull) Ordering(com.google.common.collect.Ordering) TransactionTask(com.palantir.atlasdb.transaction.api.TransactionTask) MultiTableSweepQueueWriter(com.palantir.atlasdb.sweep.queue.MultiTableSweepQueueWriter) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) BatchingVisitable(com.palantir.common.base.BatchingVisitable) Transaction(com.palantir.atlasdb.transaction.api.Transaction) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Test(org.junit.Test)

Example 10 with Transaction

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);
}
Also used : Transaction(com.palantir.atlasdb.transaction.api.Transaction) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Test(org.junit.Test)

Aggregations

Transaction (com.palantir.atlasdb.transaction.api.Transaction)60 Test (org.junit.Test)51 Cell (com.palantir.atlasdb.keyvalue.api.Cell)26 Map (java.util.Map)18 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)14 TransactionSerializableConflictException (com.palantir.atlasdb.transaction.api.TransactionSerializableConflictException)14 BatchingVisitable (com.palantir.common.base.BatchingVisitable)14 ImmutableMap (com.google.common.collect.ImmutableMap)13 TransactionConflictException (com.palantir.atlasdb.transaction.api.TransactionConflictException)13 List (java.util.List)13 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)12 PtBytes (com.palantir.atlasdb.encoding.PtBytes)10 ColumnSelection (com.palantir.atlasdb.keyvalue.api.ColumnSelection)10 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)10 ExecutionException (java.util.concurrent.ExecutionException)9 ExecutorService (java.util.concurrent.ExecutorService)9 Collectors (java.util.stream.Collectors)9 ImmutableSet (com.google.common.collect.ImmutableSet)8 Multimap (com.google.common.collect.Multimap)8 Multimaps (com.google.common.collect.Multimaps)8