Search in sources :

Example 1 with AtomicIntegerArray

use of java.util.concurrent.atomic.AtomicIntegerArray in project uavstack by uavorg.

the class AtomicIntegerArrayCodec method deserialze.

@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
    if (parser.getLexer().token() == JSONToken.NULL) {
        parser.getLexer().nextToken(JSONToken.COMMA);
        return null;
    }
    JSONArray array = new JSONArray();
    parser.parseArray(array);
    AtomicIntegerArray atomicArray = new AtomicIntegerArray(array.size());
    for (int i = 0; i < array.size(); ++i) {
        atomicArray.set(i, array.getInteger(i));
    }
    return (T) atomicArray;
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) JSONArray(com.alibaba.fastjson.JSONArray)

Example 2 with AtomicIntegerArray

use of java.util.concurrent.atomic.AtomicIntegerArray in project uavstack by uavorg.

the class AtomicIntegerArrayCodec method write.

public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
    SerializeWriter out = serializer.getWriter();
    if (object == null) {
        if (out.isEnabled(SerializerFeature.WriteNullListAsEmpty)) {
            out.write("[]");
        } else {
            out.writeNull();
        }
        return;
    }
    AtomicIntegerArray array = (AtomicIntegerArray) object;
    int len = array.length();
    out.append('[');
    for (int i = 0; i < len; ++i) {
        int val = array.get(i);
        if (i != 0) {
            out.write(',');
        }
        out.writeInt(val);
    }
    out.append(']');
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray)

Example 3 with AtomicIntegerArray

use of java.util.concurrent.atomic.AtomicIntegerArray in project CorfuDB by CorfuDB.

the class TXConflictScenariosTest method concurrentAbortTest.

public void concurrentAbortTest(boolean testInterleaved) throws Exception {
    final int numThreads = PARAMETERS.CONCURRENCY_SOME;
    final int numRecords = PARAMETERS.NUM_ITERATIONS_VERY_LOW;
    numTasks = numThreads * numRecords;
    long startTime = System.currentTimeMillis();
    commitStatus = new AtomicIntegerArray(numTasks);
    getAbortTestSM();
    // invoke the execution engine
    if (testInterleaved)
        scheduleInterleaved(numThreads, numTasks);
    else
        scheduleThreaded(numThreads, numTasks);
    int aborts = 0;
    for (int i = 0; i < numTasks; i++) if (commitStatus.get(i) != COMMITVALUE)
        aborts++;
    // print stats..
    calculateRequestsPerSecond("TPS", numRecords * numThreads, startTime);
    calculateAbortRate(aborts, numRecords * numThreads);
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray)

Example 4 with AtomicIntegerArray

use of java.util.concurrent.atomic.AtomicIntegerArray 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)

Example 5 with AtomicIntegerArray

use of java.util.concurrent.atomic.AtomicIntegerArray in project CorfuDB by CorfuDB.

the class AbstractTransactionContextTest method setupCounters.

/**
     * build an array of shared counters for the test
     */
void setupCounters() {
    numTasks = PARAMETERS.NUM_ITERATIONS_MODERATE;
    sharedCounters = new ArrayList<>();
    for (int i = 0; i < numTasks; i++) sharedCounters.add(i, instantiateCorfuObject(CorfuSharedCounter.class, "test" + i));
    // initialize all shared counters
    for (int i = 0; i < numTasks; i++) sharedCounters.get(i).setValue(INITIAL);
    commitStatus = new AtomicIntegerArray(numTasks);
    snapStatus = new AtomicIntegerArray(numTasks);
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray)

Aggregations

AtomicIntegerArray (java.util.concurrent.atomic.AtomicIntegerArray)75 Test (org.junit.Test)29 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 List (java.util.List)5 AtomicLongArray (java.util.concurrent.atomic.AtomicLongArray)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 ArrayList (java.util.ArrayList)3 Random (java.util.Random)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 CacheException (javax.cache.CacheException)3 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)3 IgniteEx (org.apache.ignite.internal.IgniteEx)3 GridRandom (org.apache.ignite.internal.util.GridRandom)3 CAX (org.apache.ignite.internal.util.typedef.CAX)3 AtomicIntegerArrayAssertBaseTest (org.assertj.core.api.AtomicIntegerArrayAssertBaseTest)3 JSONArray (com.alibaba.fastjson.JSONArray)2