Search in sources :

Example 1 with CorfuSharedCounter

use of org.corfudb.runtime.object.CorfuSharedCounter in project CorfuDB by CorfuDB.

the class TXConflictScenariosTest method testNoWriteConflictSimple.

void testNoWriteConflictSimple() throws Exception {
    final CorfuSharedCounter sharedCounter1 = instantiateCorfuObject(CorfuSharedCounter.class, "test" + 1);
    final CorfuSharedCounter sharedCounter2 = instantiateCorfuObject(CorfuSharedCounter.class, "test" + 2);
    commitStatus = new AtomicIntegerArray(2);
    t(1, this::TXBegin);
    t(2, this::TXBegin);
    t(1, () -> {
        sharedCounter1.setValue(OVERWRITE_ONCE);
    });
    t(2, () -> {
        sharedCounter2.setValue(OVERWRITE_ONCE);
    });
    t(1, () -> sharedCounter1.getValue());
    t(2, () -> sharedCounter2.getValue());
    t(1, () -> sharedCounter2.getValue());
    t(2, () -> sharedCounter1.getValue());
    t(1, () -> {
        sharedCounter1.setValue(OVERWRITE_TWICE);
    });
    t(2, () -> {
        sharedCounter2.setValue(OVERWRITE_TWICE);
    });
    t(1, () -> sharedCounter1.getValue());
    t(1, () -> sharedCounter2.getValue());
    t(2, () -> sharedCounter2.getValue());
    t(2, () -> sharedCounter1.getValue());
    t(1, () -> {
        try {
            TXEnd();
            commitStatus.set(0, COMMITVALUE);
        } catch (TransactionAbortedException tae) {
        // do nothing
        }
    });
    t(2, () -> {
        try {
            TXEnd();
            commitStatus.set(1, COMMITVALUE);
        } catch (TransactionAbortedException tae) {
        // do nothing
        }
    });
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) CorfuSharedCounter(org.corfudb.runtime.object.CorfuSharedCounter) TransactionAbortedException(org.corfudb.runtime.exceptions.TransactionAbortedException)

Aggregations

AtomicIntegerArray (java.util.concurrent.atomic.AtomicIntegerArray)1 TransactionAbortedException (org.corfudb.runtime.exceptions.TransactionAbortedException)1 CorfuSharedCounter (org.corfudb.runtime.object.CorfuSharedCounter)1