use of com.cinchapi.concourse.server.storage.db.TableRecord in project concourse by cinchapi.
the class TableChunkTest method testInsertLocatorWithTrailingWhiteSpace.
@Test
public void testInsertLocatorWithTrailingWhiteSpace() {
Identifier locator = Identifier.of(1);
Text key = Text.wrap("Youtube Embed Link ");
Value value = Value.wrap(Convert.javaToThrift("http://youtube.com"));
chunk.insert(locator, key, value, Time.now(), Action.ADD);
TableRecord record = TableRecord.createPartial(locator, key);
chunk.transfer(file);
chunk = load(file, filter, chunk.manifest());
chunk.seek(Composite.create(locator, key), record);
Assert.assertTrue(record.get(key).contains(value));
}
use of com.cinchapi.concourse.server.storage.db.TableRecord in project concourse by cinchapi.
the class SegmentTest method testConcurrency.
@Test
public void testConcurrency() throws InterruptedException {
AtomicBoolean succeeded = new AtomicBoolean(true);
AwaitableExecutorService executor = new AwaitableExecutorService(Executors.newCachedThreadPool());
try {
for (int i = 0; i < 1000; ++i) {
AtomicBoolean done = new AtomicBoolean(false);
long record = i;
String key = Long.toString(record);
TObject value = Convert.javaToThrift(Long.toString(record));
Write write = Write.add(key, value, record);
Identifier pk = Identifier.of(record);
Text text = Text.wrap(key);
Thread reader = new Thread(() -> {
while (!done.get()) {
TableRecord tr = TableRecord.create(pk);
IndexRecord ir = IndexRecord.create(text);
CorpusRecord cr = CorpusRecord.create(text);
segment.table().seek(Composite.create(pk), tr);
segment.index().seek(Composite.create(text), ir);
segment.corpus().seek(Composite.create(text), cr);
if (!done.get() && tr.isEmpty() != ir.isEmpty()) {
if (!tr.isEmpty() && ir.isEmpty()) {
// Later read is empty
succeeded.set(false);
System.out.println(AnyStrings.format("table empty = {} and index empty = {} for {}", tr.isEmpty(), ir.isEmpty(), record));
}
}
if (!done.get() && ir.isEmpty() != cr.isEmpty()) {
if (!ir.isEmpty() && cr.isEmpty()) {
// Later read is empty
succeeded.set(false);
System.out.println(AnyStrings.format("index empty = {} and corpus empty = {} for {}", tr.isEmpty(), cr.isEmpty(), record));
}
}
}
TableRecord tr = TableRecord.create(pk);
IndexRecord ir = IndexRecord.create(text);
CorpusRecord cr = CorpusRecord.create(text);
segment.table().seek(Composite.create(pk), tr);
segment.index().seek(Composite.create(text), ir);
segment.corpus().seek(Composite.create(text), cr);
if (tr.isEmpty()) {
succeeded.set(false);
System.out.println("After write finished, table still empty for " + record);
}
if (ir.isEmpty()) {
succeeded.set(false);
System.out.println("After write finished, index still empty for " + record);
}
if (cr.isEmpty()) {
succeeded.set(false);
System.out.println("After write finished, corpus still empty for " + record);
}
});
Thread writer = new Thread(() -> {
try {
segment.acquire(write, executor);
done.set(true);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
reader.start();
writer.start();
writer.join();
reader.join();
}
Assert.assertTrue(succeeded.get());
} finally {
executor.shutdown();
}
}
Aggregations