use of com.cinchapi.concourse.thrift.TObject in project concourse by cinchapi.
the class DatabaseTest method testGatherVsSelectBenchmark.
@Test
public void testGatherVsSelectBenchmark() {
java.util.Random rand = new java.util.Random();
Database store = (Database) this.store;
List<Long> records = Lists.newArrayList();
for (int i = 0; i < TestData.getScaleCount() * 100; ++i) {
records.add(Time.now());
}
List<String> keys = Lists.newArrayList();
for (int i = 0; i < TestData.getScaleCount() * 10; ++i) {
keys.add(Random.getSimpleString());
}
for (int i = 0; i < TestData.getScaleCount(); ++i) {
String key = keys.get(rand.nextInt(keys.size()));
long record = records.get(rand.nextInt(records.size()));
TObject value = Convert.javaToThrift(Random.getObject());
add(key, value, record);
if (rand.nextInt() % 6 == 0) {
remove(key, value, record);
}
}
Database $store = store;
Benchmark select = new Benchmark(TimeUnit.MILLISECONDS) {
@Override
public void action() {
for (long record : records) {
for (String key : keys) {
$store.select(key, record);
}
}
}
};
Benchmark gather = new Benchmark(TimeUnit.MILLISECONDS) {
@Override
public void action() {
for (long record : records) {
for (String key : keys) {
$store.gather(key, record);
}
}
}
};
double selectTime = select.run(1);
double gatherTime = gather.run(1);
System.out.println("Select took " + selectTime + " ms and gather took " + gatherTime + " ms");
Assert.assertTrue(gatherTime <= selectTime);
}
use of com.cinchapi.concourse.thrift.TObject in project concourse by cinchapi.
the class DatabaseTest method testSearchIndexMultipleEnvironmentsConcurrently.
@Test
public void testSearchIndexMultipleEnvironmentsConcurrently() {
List<Database> dbs = Lists.newArrayList();
for (int i = 0; i < 10; ++i) {
Database db = getStore();
db.start();
dbs.add(db);
}
String key = "test";
String query = "son i";
TObject value = Convert.javaToThrift("Jeff Nelson is the CEO");
int count = 100;
Set<Long> expected = Sets.newLinkedHashSet();
Consumer<Database> func = db -> {
for (int i = 0; i < count; ++i) {
expected.add((long) i);
Write write = Write.add("test", value, i);
db.accept(write);
}
};
for (Database db : dbs) {
func.accept(db);
}
for (Database db : dbs) {
Set<Long> actual = db.search(key, query);
Assert.assertTrue(!actual.isEmpty());
Assert.assertEquals(expected, actual);
}
for (Database db : dbs) {
db.stop();
if (!current.contentEquals(db.getBackingStore())) {
FileSystem.deleteDirectory(db.getBackingStore());
}
}
}
use of com.cinchapi.concourse.thrift.TObject in project concourse by cinchapi.
the class EngineTest method reproCON_239BrowseRecord.
@Test
public void reproCON_239BrowseRecord() throws InterruptedException {
final Engine engine = (Engine) store;
int count = TestData.getScaleCount();
for (int i = 0; i < count; i++) {
engine.add(Long.toString(Time.now()), Convert.javaToThrift(i), 1);
}
final AtomicBoolean done = new AtomicBoolean(false);
final AtomicBoolean go = new AtomicBoolean(false);
Thread write = new Thread(new Runnable() {
@Override
public void run() {
while (!go.get()) {
// ensure read goes first
continue;
}
while (!done.get()) {
if (!done.get()) {
engine.add(Long.toString(Time.now()), Convert.javaToThrift("a"), 1);
}
}
}
});
final AtomicBoolean succeeded = new AtomicBoolean(true);
Thread read = new Thread(new Runnable() {
@Override
public void run() {
go.set(true);
Map<String, Set<TObject>> data = engine.select(1);
done.set(true);
Map<String, Set<TObject>> data1 = engine.select(1);
Variables.register("data_size", data.size());
Variables.register("data1_size", data1.size());
succeeded.set(data.size() == data1.size() || data.size() == data1.size() - 1);
}
});
read.start();
write.start();
read.join();
write.join();
Assert.assertTrue(succeeded.get());
}
use of com.cinchapi.concourse.thrift.TObject in project concourse by cinchapi.
the class StoreTest method testFetchAfterAddMultiWithTime.
@Test
public void testFetchAfterAddMultiWithTime() {
String key = TestData.getSimpleString();
long record = TestData.getLong();
Set<TObject> values = getValues();
for (TObject value : values) {
add(key, value, record);
}
long timestamp = Time.now();
Set<TObject> otherValues = Sets.newHashSet();
for (TObject value : getValues()) {
while (values.contains(value) || otherValues.contains(value)) {
value = TestData.getTObject();
}
otherValues.add(value);
add(key, value, record);
}
Assert.assertEquals(values, store.select(key, record, timestamp));
}
use of com.cinchapi.concourse.thrift.TObject in project concourse by cinchapi.
the class StoreTest method testBrowseRecordIsSorted.
@Test
public void testBrowseRecordIsSorted() {
Multimap<String, TObject> data = Variables.register("data", HashMultimap.<String, TObject>create());
long record = TestData.getLong();
for (String key : getKeys()) {
for (int i = 0; i < TestData.getScaleCount() % 4; i++) {
TObject value = TestData.getTObject();
if (!data.containsEntry(key, value)) {
data.put(key, value);
add(key, value, record);
}
}
}
Map<String, Set<TObject>> result = Variables.register("data", store.select(record));
String previous = null;
for (String current : result.keySet()) {
if (previous != null) {
Variables.register("previous", previous);
Variables.register("current", current);
Assert.assertTrue(previous.compareToIgnoreCase(current) < 0);
}
previous = current;
}
}
Aggregations