Search in sources :

Example 1 with TableRecord

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

Example 2 with TableRecord

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

Aggregations

Identifier (com.cinchapi.concourse.server.model.Identifier)2 Text (com.cinchapi.concourse.server.model.Text)2 TableRecord (com.cinchapi.concourse.server.storage.db.TableRecord)2 Test (org.junit.Test)2 AwaitableExecutorService (com.cinchapi.concourse.server.concurrent.AwaitableExecutorService)1 Value (com.cinchapi.concourse.server.model.Value)1 CorpusRecord (com.cinchapi.concourse.server.storage.db.CorpusRecord)1 IndexRecord (com.cinchapi.concourse.server.storage.db.IndexRecord)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