Search in sources :

Example 1 with CorpusRecord

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();
    }
}
Also used : Write(com.cinchapi.concourse.server.storage.temp.Write) TObject(com.cinchapi.concourse.thrift.TObject) Text(com.cinchapi.concourse.server.model.Text) IndexRecord(com.cinchapi.concourse.server.storage.db.IndexRecord) TableRecord(com.cinchapi.concourse.server.storage.db.TableRecord) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Identifier(com.cinchapi.concourse.server.model.Identifier) CorpusRecord(com.cinchapi.concourse.server.storage.db.CorpusRecord) AwaitableExecutorService(com.cinchapi.concourse.server.concurrent.AwaitableExecutorService) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest) Test(org.junit.Test)

Example 2 with CorpusRecord

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));
}
Also used : Identifier(com.cinchapi.concourse.server.model.Identifier) CorpusRecord(com.cinchapi.concourse.server.storage.db.CorpusRecord) Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text) Test(org.junit.Test)

Aggregations

Identifier (com.cinchapi.concourse.server.model.Identifier)2 Text (com.cinchapi.concourse.server.model.Text)2 CorpusRecord (com.cinchapi.concourse.server.storage.db.CorpusRecord)2 Test (org.junit.Test)2 AwaitableExecutorService (com.cinchapi.concourse.server.concurrent.AwaitableExecutorService)1 Value (com.cinchapi.concourse.server.model.Value)1 IndexRecord (com.cinchapi.concourse.server.storage.db.IndexRecord)1 TableRecord (com.cinchapi.concourse.server.storage.db.TableRecord)1 Write (com.cinchapi.concourse.server.storage.temp.Write)1 ConcourseBaseTest (com.cinchapi.concourse.test.ConcourseBaseTest)1 TObject (com.cinchapi.concourse.thrift.TObject)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1