Search in sources :

Example 41 with Transaction

use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.

the class AbstractTransactionTest method testReadMyDeletesColumnRangePagingTransaction.

@Test
public void testReadMyDeletesColumnRangePagingTransaction() {
    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);
        if (i % 2 == 0) {
            writes.put(Cell.create(row, PtBytes.toBytes("col" + i)), PtBytes.toBytes("v" + i));
        }
    }
    t.commit();
    t = startTransaction();
    for (int i = 0; i < totalPuts; i++) {
        if (i % 2 == 1) {
            delete(t, "row1", "col" + i);
        }
    }
    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);
}
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 42 with Transaction

use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.

the class AbstractTransactionTest method testEmptyColumnRangePagingTransaction.

@Test
public void testEmptyColumnRangePagingTransaction() {
    byte[] row = PtBytes.toBytes("row1");
    Transaction 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.of();
    verifyMatchingResult(expected, row, columnRange);
    put(t, "row1", "col1", "v1");
    t.commit();
    t = startTransaction();
    delete(t, "row1", "col1");
    columnRange = t.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1));
    verifyMatchingResult(expected, row, columnRange);
    t.commit();
    t = startTransaction();
    columnRange = t.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1));
    verifyMatchingResult(expected, row, columnRange);
}
Also used : BatchingVisitable(com.palantir.common.base.BatchingVisitable) Transaction(com.palantir.atlasdb.transaction.api.Transaction) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 43 with Transaction

use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.

the class AbstractTransactionTest method testGetRanges.

@Test
public void testGetRanges() {
    Transaction t = startTransaction();
    byte[] row1Bytes = PtBytes.toBytes("row1");
    Cell row1Key = Cell.create(row1Bytes, PtBytes.toBytes("col"));
    byte[] row1Value = PtBytes.toBytes("value1");
    byte[] row2Bytes = PtBytes.toBytes("row2");
    Cell row2Key = Cell.create(row2Bytes, PtBytes.toBytes("col"));
    byte[] row2Value = PtBytes.toBytes("value2");
    t.put(TEST_TABLE, ImmutableMap.of(row1Key, row1Value, row2Key, row2Value));
    t.commit();
    t = startTransaction();
    List<RangeRequest> ranges = ImmutableList.of(RangeRequest.builder().prefixRange(row1Bytes).build(), RangeRequest.builder().prefixRange(row2Bytes).build());
    verifyAllGetRangesImplsNumRanges(t, ranges, ImmutableList.of("value1", "value2"));
}
Also used : Transaction(com.palantir.atlasdb.transaction.api.Transaction) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 44 with Transaction

use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.

the class AbstractTransactionTest method testWriteWriteConflict.

@Test
public void testWriteWriteConflict() {
    Transaction t1 = startTransaction();
    Transaction t2 = startTransaction();
    put(t1, "row1", "col1", "v1");
    put(t2, "row1", "col1", "v2");
    t1.commit();
    try {
        t2.commit();
        fail("Expected write-write conflict.");
    } catch (TransactionConflictException e) {
    // expected
    }
}
Also used : Transaction(com.palantir.atlasdb.transaction.api.Transaction) TransactionConflictException(com.palantir.atlasdb.transaction.api.TransactionConflictException) Test(org.junit.Test)

Example 45 with Transaction

use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.

the class AbstractTransactionTest method testGetRangesPaging.

@Test
public void testGetRangesPaging() {
    Transaction t = startTransaction();
    byte[] row0Bytes = PtBytes.toBytes("row0");
    byte[] row00Bytes = PtBytes.toBytes("row00");
    byte[] colBytes = PtBytes.toBytes("col");
    Cell k1 = Cell.create(row00Bytes, colBytes);
    byte[] row1Bytes = PtBytes.toBytes("row1");
    Cell k2 = Cell.create(row1Bytes, colBytes);
    byte[] v = PtBytes.toBytes("v");
    t.put(TEST_TABLE, ImmutableMap.of(Cell.create(row0Bytes, colBytes), v));
    t.put(TEST_TABLE, ImmutableMap.of(k1, v));
    t.put(TEST_TABLE, ImmutableMap.of(k2, v));
    t.commit();
    t = startTransaction();
    t.delete(TEST_TABLE, ImmutableSet.of(k1));
    t.commit();
    t = startTransaction();
    byte[] rangeEnd = RangeRequests.nextLexicographicName(row00Bytes);
    List<RangeRequest> ranges = ImmutableList.of(RangeRequest.builder().prefixRange(row0Bytes).endRowExclusive(rangeEnd).batchHint(1).build());
    verifyAllGetRangesImplsNumRanges(t, ranges, ImmutableList.of("v"));
}
Also used : Transaction(com.palantir.atlasdb.transaction.api.Transaction) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Cell(com.palantir.atlasdb.keyvalue.api.Cell) 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