Search in sources :

Example 6 with TransactionSerializableConflictException

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

the class AbstractSerializableTransactionTest method testClassicWriteSkew.

@Test
public void testClassicWriteSkew() {
    Transaction t0 = startTransaction();
    put(t0, "row1", "col1", "100");
    put(t0, "row2", "col1", "100");
    t0.commit();
    Transaction t1 = startTransaction();
    Transaction t2 = startTransaction();
    withdrawMoney(t1, true, false);
    withdrawMoney(t2, false, false);
    t1.commit();
    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 7 with TransactionSerializableConflictException

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

the class AbstractSerializableTransactionTest method testColumnRangeReadWriteEmptyRange.

@Test
public void testColumnRangeReadWriteEmptyRange() {
    byte[] row = PtBytes.toBytes("row1");
    Transaction t1 = startTransaction();
    Map<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> columnRange = t1.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.toBytes("col"), PtBytes.toBytes("col0"), 1));
    assertNull(BatchingVisitables.getFirst(Iterables.getOnlyElement(columnRange.values())));
    // Write to avoid the read only path.
    put(t1, "row1_1", "col0", "v0");
    Transaction t2 = startTransaction();
    put(t2, "row1", "col", "v0");
    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 8 with TransactionSerializableConflictException

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

the class AbstractSerializableTransactionTest method testPhantomReadFail2.

@Test
public void testPhantomReadFail2() {
    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 9 with TransactionSerializableConflictException

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

the class AbstractSerializableTransactionTest method testClassicWriteSkew2Cell.

@Test
public void testClassicWriteSkew2Cell() {
    Transaction t0 = startTransaction();
    put(t0, "row1", "col1", "100");
    put(t0, "row2", "col1", "100");
    t0.commit();
    Transaction t1 = startTransaction();
    Transaction t2 = startTransaction();
    withdrawMoney(t1, true, true);
    withdrawMoney(t2, false, true);
    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 10 with TransactionSerializableConflictException

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

the class AbstractSerializableTransactionTest method testPhantomReadFail.

@Test
public void testPhantomReadFail() {
    String initialValue = "100";
    Transaction t0 = startTransaction();
    put(t0, "row1", "col1", initialValue);
    put(t0, "row2", "col1", initialValue);
    t0.commit();
    Transaction t1 = startTransaction();
    RowResult<byte[]> first = BatchingVisitables.getFirst(t1.getRange(TEST_TABLE, RangeRequest.builder().build()));
    put(t1, "row22", "col1", initialValue);
    Transaction t2 = startTransaction();
    put(t2, "row0", "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)

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