Search in sources :

Example 1 with TransactionSerializableConflictException

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

the class AbstractSerializableTransactionTest method testColumnRangeReadWriteConflictOnNewCell.

@Test
public void testColumnRangeReadWriteConflictOnNewCell() {
    byte[] row = PtBytes.toBytes("row1");
    writeColumns();
    Transaction t1 = startTransaction();
    Map<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> columnRange = t1.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1));
    // Serializable transaction records only the first column as read.
    Map.Entry<Cell, byte[]> read = BatchingVisitables.getFirst(Iterables.getOnlyElement(columnRange.values()));
    assertEquals(Cell.create(row, PtBytes.toBytes("col0")), read.getKey());
    // Write to avoid the read only path.
    put(t1, "row1_1", "col0", "v0");
    Transaction t2 = startTransaction();
    // Write on the start of the range.
    put(t2, "row1", "col", "v");
    t2.commit();
    try {
        t1.commit();
        fail();
    } catch (TransactionSerializableConflictException e) {
    // expected
    }
}
Also used : BatchingVisitable(com.palantir.common.base.BatchingVisitable) Transaction(com.palantir.atlasdb.transaction.api.Transaction) TransactionSerializableConflictException(com.palantir.atlasdb.transaction.api.TransactionSerializableConflictException) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableMap(com.google.common.collect.ImmutableMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 2 with TransactionSerializableConflictException

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

the class AbstractSerializableTransactionTest method testCellReadWriteFailure2.

@Test
public void testCellReadWriteFailure2() {
    String initialValue = "100";
    Transaction t0 = startTransaction();
    put(t0, "row1", "col1", initialValue);
    put(t0, "row2", "col1", initialValue);
    t0.commit();
    Transaction t1 = startTransaction();
    BatchingVisitables.copyToList(t1.getRange(TEST_TABLE, RangeRequest.builder().build()));
    put(t1, "row22", "col1", initialValue);
    Transaction t2 = startTransaction();
    put(t2, "row2", "col1", "101");
    t2.commit();
    try {
        t1.commit();
        fail();
    } catch (TransactionSerializableConflictException e) {
    // this is expectecd to throw because it is a write skew
    }
}
Also used : Transaction(com.palantir.atlasdb.transaction.api.Transaction) TransactionSerializableConflictException(com.palantir.atlasdb.transaction.api.TransactionSerializableConflictException) Test(org.junit.Test)

Example 3 with TransactionSerializableConflictException

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

the class AbstractSerializableTransactionTest method testLargerCycleWithReadOnly.

@Test
public void testLargerCycleWithReadOnly() {
    String initialValue = "100";
    String newValue = "101";
    String newValue2 = "102";
    Transaction t0 = startTransaction();
    put(t0, "row1", "col1", initialValue);
    put(t0, "row2", "col1", initialValue);
    t0.commit();
    Transaction t1 = startTransaction();
    put(t1, "row1", "col1", newValue);
    Transaction t2 = startTransaction();
    String row1Get = get(t2, "row1", "col1");
    assertEquals(initialValue, row1Get);
    put(t2, "row2", "col1", row1Get);
    t1.commit();
    Transaction t3 = startTransaction();
    put(t3, "row1", "col1", newValue2);
    t3.commit();
    Transaction readOnly = startTransaction();
    assertEquals(newValue2, get(readOnly, "row1", "col1"));
    assertEquals(initialValue, get(readOnly, "row2", "col1"));
    try {
        t2.commit();
        fail();
    } catch (TransactionSerializableConflictException e) {
    // this is expectecd to throw because it is a write skew
    }
}
Also used : Transaction(com.palantir.atlasdb.transaction.api.Transaction) TransactionSerializableConflictException(com.palantir.atlasdb.transaction.api.TransactionSerializableConflictException) Test(org.junit.Test)

Example 4 with TransactionSerializableConflictException

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

the class AbstractSerializableTransactionTest method testCellReadWriteFailure.

@Test
public void testCellReadWriteFailure() {
    String initialValue = "100";
    Transaction t0 = startTransaction();
    put(t0, "row1", "col1", initialValue);
    put(t0, "row2", "col1", initialValue);
    t0.commit();
    Transaction t1 = startTransaction();
    BatchingVisitables.copyToList(t1.getRange(TEST_TABLE, RangeRequest.builder().build()));
    put(t1, "row22", "col1", initialValue);
    Transaction t2 = startTransaction();
    put(t2, "row3", "col1", initialValue);
    t2.commit();
    try {
        t1.commit();
        fail();
    } catch (TransactionSerializableConflictException e) {
    // this is expectecd to throw because it is a write skew
    }
}
Also used : Transaction(com.palantir.atlasdb.transaction.api.Transaction) TransactionSerializableConflictException(com.palantir.atlasdb.transaction.api.TransactionSerializableConflictException) Test(org.junit.Test)

Example 5 with TransactionSerializableConflictException

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

the class AbstractSerializableTransactionTest method testColumnRangeReadWriteConflict.

@Test
public void testColumnRangeReadWriteConflict() {
    byte[] row = PtBytes.toBytes("row1");
    writeColumns();
    Transaction t1 = startTransaction();
    Map<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> columnRange = t1.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1));
    // Serializable transaction records only the first column as read.
    Map.Entry<Cell, byte[]> read = BatchingVisitables.getFirst(Iterables.getOnlyElement(columnRange.values()));
    assertEquals(Cell.create(row, PtBytes.toBytes("col0")), read.getKey());
    // Write to avoid the read only path.
    put(t1, "row1_1", "col0", "v0");
    Transaction t2 = startTransaction();
    put(t2, "row1", "col0", "v0_0");
    t2.commit();
    try {
        t1.commit();
        fail();
    } catch (TransactionSerializableConflictException e) {
    // expected
    }
}
Also used : BatchingVisitable(com.palantir.common.base.BatchingVisitable) Transaction(com.palantir.atlasdb.transaction.api.Transaction) TransactionSerializableConflictException(com.palantir.atlasdb.transaction.api.TransactionSerializableConflictException) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableMap(com.google.common.collect.ImmutableMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Aggregations

Transaction (com.palantir.atlasdb.transaction.api.Transaction)13 TransactionSerializableConflictException (com.palantir.atlasdb.transaction.api.TransactionSerializableConflictException)13 Test (org.junit.Test)13 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)3 Cell (com.palantir.atlasdb.keyvalue.api.Cell)3 BatchingVisitable (com.palantir.common.base.BatchingVisitable)3 Map (java.util.Map)3