Search in sources :

Example 76 with TObject

use of com.cinchapi.concourse.thrift.TObject in project concourse by cinchapi.

the class BufferedStoreTest method generateTestData.

/**
 * <p>
 * Return a random sequence of Data that should be added to the
 * BufferedStore in order. The ordered sequence simulates data being added
 * and removed for a controlled list of keys, values and records. The
 * returned list will either be net neutral (meaning all positive data is
 * offset by negative data) or it will be net positive (meaning there is
 * some positive data that is not offset by negative data). <strong>It
 * should never be net negative</strong>
 * </p>
 * <p>
 * The caller can determine how many times a piece of data appears in the
 * list (and therefore whether it is net neutral (even number) or net
 * positive (odd number) using the {@link #count(List, Data)}.
 * </p>
 *
 * @return the data
 */
private List<Data> generateTestData() {
    // Setup iterators
    Iterator<String> keys = Iterators.cycle(POSSIBLE_KEYS);
    Iterator<TObject> values = Iterators.cycle(POSSIBLE_VALUES);
    Iterator<Long> records = Iterators.cycle(POSSIBLE_RECORDS);
    // Get initial positive and negative data so we can guarantee that every
    // remove offsets an add
    int numNegData = TestData.getScaleCount();
    List<Data> posData = Lists.newArrayList();
    List<Data> negData = Lists.newArrayList();
    for (int i = 0; i < numNegData; i++) {
        Data pos = Data.positive(keys.next(), values.next(), records.next());
        Data neg = Data.negative(pos);
        posData.add(pos);
        negData.add(neg);
    }
    // Get more positive data, no greater than the number of available keys
    // (the smallest list) so that we can guarantee that we don't have any
    // adds that aren't offset
    int numAddlPosData = TestData.getScaleCount() % POSSIBLE_KEYS.size();
    for (int i = 0; i < numAddlPosData; i++) {
        Data pos = Data.positive(keys.next(), values.next(), records.next());
        posData.add(pos);
    }
    // Create the order in which the data will be written
    List<Data> order = Lists.newArrayList();
    boolean lastWasNeg = true;
    while (posData.size() > 0 || negData.size() > 0) {
        if (lastWasNeg && posData.size() > 0) {
            int index = TestData.getScaleCount() % posData.size();
            if (Numbers.isEven(count(order, posData.get(index)))) {
                order.add(posData.get(index));
                posData.remove(index);
            }
            lastWasNeg = false;
        } else {
            if (negData.size() > 0) {
                int index = TestData.getScaleCount() % negData.size();
                if (Numbers.isOdd(count(order, negData.get(index)))) {
                    order.add(negData.get(index));
                    negData.remove(index);
                }
                lastWasNeg = true;
            }
        }
    }
    return Variables.register("order", order);
}
Also used : TObject(com.cinchapi.concourse.thrift.TObject) TestData(com.cinchapi.concourse.util.TestData)

Example 77 with TObject

use of com.cinchapi.concourse.thrift.TObject in project concourse by cinchapi.

the class EngineAtomicOperationTest method testNoPhantomReadWithTimestampInTheFutureUsingVerify.

@Test(expected = AtomicStateException.class)
public void testNoPhantomReadWithTimestampInTheFutureUsingVerify() {
    long aheadOfTime = Time.now() + (long) 10e9;
    String key = Variables.register("key", TestData.getSimpleString());
    TObject value = Variables.register("value", TestData.getTObject());
    long record = Variables.register("record", TestData.getLong());
    AtomicOperation atomicOp = (AtomicOperation) store;
    atomicOp.verify(key, value, record, aheadOfTime);
    destination.accept(Write.add(key, value, record));
    atomicOp.verify(key, value, record, aheadOfTime);
}
Also used : TObject(com.cinchapi.concourse.thrift.TObject) Test(org.junit.Test)

Example 78 with TObject

use of com.cinchapi.concourse.thrift.TObject in project concourse by cinchapi.

the class EngineAtomicOperationTest method testNoPhantomReadWithTimestampInTheFutureUsingSelectWithKey.

@Test(expected = AtomicStateException.class)
public void testNoPhantomReadWithTimestampInTheFutureUsingSelectWithKey() {
    long aheadOfTime = Time.now() + (long) 10e9;
    String key = Variables.register("key", TestData.getSimpleString());
    TObject value = Variables.register("value", TestData.getTObject());
    long record = Variables.register("record", TestData.getLong());
    AtomicOperation atomicOp = (AtomicOperation) store;
    atomicOp.select(key, record, aheadOfTime);
    destination.accept(Write.add(key, value, record));
    atomicOp.select(key, record, aheadOfTime);
}
Also used : TObject(com.cinchapi.concourse.thrift.TObject) Test(org.junit.Test)

Example 79 with TObject

use of com.cinchapi.concourse.thrift.TObject in project concourse by cinchapi.

the class DatabaseTest method testDatabaseAppendsToCachedSecondaryRecords.

@Test
public void testDatabaseAppendsToCachedSecondaryRecords() {
    Database db = (Database) store;
    String key = TestData.getString();
    TObject value = TestData.getTObject();
    int count = TestData.getScaleCount();
    for (int i = 0; i < count; i++) {
        db.accept(Write.add(key, value, i));
    }
    db.find(key, Operator.EQUALS, value);
    int increase = TestData.getScaleCount();
    db.accept(Write.add(key, value, count * increase));
    Assert.assertTrue(db.find(key, Operator.EQUALS, value).contains((long) count * increase));
}
Also used : TObject(com.cinchapi.concourse.thrift.TObject) StoreTest(com.cinchapi.concourse.server.storage.StoreTest) Test(org.junit.Test)

Example 80 with TObject

use of com.cinchapi.concourse.thrift.TObject in project concourse by cinchapi.

the class DatabaseTest method testBackgroundManifestLoadConcurrency.

@Test
public void testBackgroundManifestLoadConcurrency() throws InterruptedException {
    Database db = (Database) store;
    List<Write> writes = Lists.newArrayList();
    for (int i = 0; i < TestData.getScaleCount() * 3; ++i) {
        String key = TestData.getSimpleString();
        TObject value = TestData.getTObject();
        long record = (Math.abs(TestData.getInt()) % 10) + 1;
        add(key, value, record);
        if (Math.abs(TestData.getInt()) % 3 == 0) {
            writes.add(Write.add(key, value, record));
        }
        if (Math.abs(TestData.getInt()) % 3 == 0) {
            db.sync();
        }
    }
    db.stop();
    db.start();
    ExecutorService executor = Executors.newFixedThreadPool(5);
    Iterator<Write> it = writes.iterator();
    while (it.hasNext()) {
        Write write = it.next();
        executor.execute(() -> {
            Assert.assertTrue(db.verify(write.getKey().toString(), write.getValue().getTObject(), write.getRecord().longValue()));
        });
    }
    executor.shutdown();
    executor.awaitTermination(1, TimeUnit.MINUTES);
}
Also used : Write(com.cinchapi.concourse.server.storage.temp.Write) TObject(com.cinchapi.concourse.thrift.TObject) ExecutorService(java.util.concurrent.ExecutorService) StoreTest(com.cinchapi.concourse.server.storage.StoreTest) Test(org.junit.Test)

Aggregations

TObject (com.cinchapi.concourse.thrift.TObject)242 Test (org.junit.Test)100 ComplexTObject (com.cinchapi.concourse.thrift.ComplexTObject)98 Set (java.util.Set)98 AtomicSupport (com.cinchapi.concourse.server.storage.AtomicSupport)96 TranslateClientExceptions (com.cinchapi.concourse.server.aop.TranslateClientExceptions)91 VerifyAccessToken (com.cinchapi.concourse.server.aop.VerifyAccessToken)91 VerifyReadPermission (com.cinchapi.concourse.server.aop.VerifyReadPermission)88 Map (java.util.Map)76 AbstractSyntaxTree (com.cinchapi.ccl.syntax.AbstractSyntaxTree)72 SortableTable (com.cinchapi.concourse.data.sort.SortableTable)71 Store (com.cinchapi.concourse.server.storage.Store)66 Order (com.cinchapi.concourse.lang.sort.Order)63 SortableColumn (com.cinchapi.concourse.data.sort.SortableColumn)61 SortableSet (com.cinchapi.concourse.data.sort.SortableSet)60 ByteBuffer (java.nio.ByteBuffer)60 Operator (com.cinchapi.concourse.thrift.Operator)59 Entry (java.util.Map.Entry)59 Convert (com.cinchapi.concourse.util.Convert)57 Sets (com.google.common.collect.Sets)57