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);
}
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);
}
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);
}
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));
}
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);
}
Aggregations