use of com.cinchapi.concourse.server.storage.db.CorpusRecord 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();
}
}
use of com.cinchapi.concourse.server.storage.db.CorpusRecord in project concourse by cinchapi.
the class CorpusChunkTest method testReproCON_4.
@Test
public void testReproCON_4() {
// TODO file this in jira
Text key = Variables.register("key", Text.wrap("strings"));
Identifier record = Variables.register("record", getRecord());
Value value = Variables.register("value", Value.wrap(Convert.javaToThrift("aaihwopxetdxrumqlbjwgdsjgs tan rczlfjhyhlwhsr aqzpmquui mmmynpklmctgnonaaafagpjgv augolkz")));
((CorpusChunk) chunk).insert(key, value, record, Time.now(), Action.ADD);
Text term = Variables.register("term", Text.wrap("aa"));
Variables.register("chunkDump", chunk.dump());
CorpusRecord searchRecord = CorpusRecord.createPartial(key, term);
((CorpusChunk) chunk).seek(Composite.create(key, term), searchRecord);
Assert.assertTrue(searchRecord.get(term).stream().map(Position::getIdentifier).collect(Collectors.toCollection(LinkedHashSet::new)).contains(record));
}
Aggregations