Search in sources :

Example 81 with TObject

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);
}
Also used : TObject(com.cinchapi.concourse.thrift.TObject) Random(com.cinchapi.concourse.util.Random) Benchmark(com.cinchapi.common.profile.Benchmark) StoreTest(com.cinchapi.concourse.server.storage.StoreTest) Test(org.junit.Test)

Example 82 with TObject

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());
        }
    }
}
Also used : Iterables(com.google.common.collect.Iterables) Store(com.cinchapi.concourse.server.storage.Store) TestData(com.cinchapi.concourse.util.TestData) Write(com.cinchapi.concourse.server.storage.temp.Write) Random(com.cinchapi.concourse.util.Random) Reflection(com.cinchapi.common.reflect.Reflection) Lists(com.google.common.collect.Lists) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TObject(com.cinchapi.concourse.thrift.TObject) Convert(com.cinchapi.concourse.util.Convert) StoreTest(com.cinchapi.concourse.server.storage.StoreTest) Benchmark(com.cinchapi.common.profile.Benchmark) ExecutorService(java.util.concurrent.ExecutorService) Time(com.cinchapi.concourse.time.Time) ImmutableSet(com.google.common.collect.ImmutableSet) Iterator(java.util.Iterator) FileSystem(com.cinchapi.concourse.server.io.FileSystem) Set(java.util.Set) MoreObjects(com.google.common.base.MoreObjects) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) File(java.io.File) Executors(java.util.concurrent.Executors) Sets(com.google.common.collect.Sets) Segment(com.cinchapi.concourse.server.storage.db.kernel.Segment) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) Operator(com.cinchapi.concourse.thrift.Operator) Identifier(com.cinchapi.concourse.server.model.Identifier) Paths(java.nio.file.Paths) Assert(org.junit.Assert) Text(com.cinchapi.concourse.server.model.Text) Write(com.cinchapi.concourse.server.storage.temp.Write) TObject(com.cinchapi.concourse.thrift.TObject) StoreTest(com.cinchapi.concourse.server.storage.StoreTest) Test(org.junit.Test)

Example 83 with TObject

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TObject(com.cinchapi.concourse.thrift.TObject) Map(java.util.Map) Test(org.junit.Test)

Example 84 with TObject

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));
}
Also used : TObject(com.cinchapi.concourse.thrift.TObject) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest) Test(org.junit.Test)

Example 85 with TObject

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;
    }
}
Also used : TObject(com.cinchapi.concourse.thrift.TObject) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest) Test(org.junit.Test)

Aggregations

TObject (com.cinchapi.concourse.thrift.TObject)242 Test (org.junit.Test)100 ComplexTObject (com.cinchapi.concourse.thrift.ComplexTObject)98 Set (java.util.Set)98 AtomicSupport (com.cinchapi.concourse.server.storage.AtomicSupport)96 TranslateClientExceptions (com.cinchapi.concourse.server.aop.TranslateClientExceptions)91 VerifyAccessToken (com.cinchapi.concourse.server.aop.VerifyAccessToken)91 VerifyReadPermission (com.cinchapi.concourse.server.aop.VerifyReadPermission)88 Map (java.util.Map)76 AbstractSyntaxTree (com.cinchapi.ccl.syntax.AbstractSyntaxTree)72 SortableTable (com.cinchapi.concourse.data.sort.SortableTable)71 Store (com.cinchapi.concourse.server.storage.Store)66 Order (com.cinchapi.concourse.lang.sort.Order)63 SortableColumn (com.cinchapi.concourse.data.sort.SortableColumn)61 SortableSet (com.cinchapi.concourse.data.sort.SortableSet)60 ByteBuffer (java.nio.ByteBuffer)60 Operator (com.cinchapi.concourse.thrift.Operator)59 Entry (java.util.Map.Entry)59 Convert (com.cinchapi.concourse.util.Convert)57 Sets (com.google.common.collect.Sets)57