Search in sources :

Example 71 with Rnd

use of com.questdb.std.Rnd in project questdb by bluestreak01.

the class HugeTableTest method testLargeSymbolTable.

@Test
public void testLargeSymbolTable() throws Exception {
    try (JournalWriter<Name> w = getFactory().writer(Name.class, "name")) {
        Name name = new Name();
        Rnd rnd = new Rnd();
        long t = 0;
        for (int i = -500000; i < 2000000; i++) {
            if (i == 0) {
                t = System.nanoTime();
            }
            name.name = rnd.nextString(10);
            w.append(name);
        }
        w.commit();
        LOG.info().$("Appended 2M symbols in ").$(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t)).$("ms").$();
    }
}
Also used : Rnd(com.questdb.std.Rnd) Test(org.junit.Test)

Example 72 with Rnd

use of com.questdb.std.Rnd in project questdb by bluestreak01.

the class JournalTest method testTxTumbleDrier.

@Test
public void testTxTumbleDrier() throws Exception {
    int SIZE = 1000000;
    try (JournalWriter<Quote> origin = getFactory().writer(Quote.class, "origin", SIZE / 12)) {
        try (JournalWriter<Quote> w = getFactory().writer(Quote.class, "q", SIZE / 12)) {
            TestUtils.generateQuoteData(origin, SIZE, DateFormatUtils.parseDateTime("2014-01-30T00:11:00.000Z"), 100000);
            origin.commit();
            ResultSet<Quote> originRs = origin.query().all().asResultSet();
            int blockSize = 5130;
            Rnd rnd = new Rnd(System.currentTimeMillis(), System.nanoTime());
            try {
                for (int i = 0; i < originRs.size(); ) {
                    int d = Math.min(i + blockSize, originRs.size());
                    ResultSet<Quote> rs = originRs.subset(i, d);
                    w.append(rs);
                    if (rnd.nextBoolean()) {
                        w.commit();
                        i += blockSize;
                    } else {
                        w.rollback();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            Assert.assertFalse(w.isTxActive());
            TestUtils.assertDataEquals(origin, w);
        }
    }
}
Also used : Quote(com.questdb.model.Quote) Rnd(com.questdb.std.Rnd) JournalException(com.questdb.std.ex.JournalException) NumericException(com.questdb.common.NumericException) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 73 with Rnd

use of com.questdb.std.Rnd in project questdb by bluestreak01.

the class JournalTest method testAppendBreak.

@Test
public void testAppendBreak() throws Exception {
    Rnd random = new Rnd(System.nanoTime(), System.currentTimeMillis());
    try (JournalWriter<TestEntity> w = getFactory().writer(TestEntity.class)) {
        try {
            w.append(new TestEntity().setSym("ABC").setDStr("test1"));
            w.append(new TestEntity().setSym("ABC").setDStr(random.nextString(100)));
            w.append(new TestEntity().setSym("ABC").setDStr(random.nextString(70000)).setTimestamp(-1));
        } catch (Exception e) {
        // OK
        } finally {
            w.commit();
        }
        w.append(new TestEntity().setSym("ABC").setDStr(random.nextString(300)));
        Assert.assertEquals(3, w.query().all().withKeys("ABC").asResultSet().size());
        Assert.assertEquals(1, w.query().head().withKeys("ABC").asResultSet().size());
    }
}
Also used : TestEntity(com.questdb.model.TestEntity) Rnd(com.questdb.std.Rnd) JournalException(com.questdb.std.ex.JournalException) NumericException(com.questdb.common.NumericException) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 74 with Rnd

use of com.questdb.std.Rnd in project questdb by bluestreak01.

the class UnstructuredFileTest method testIntArrays.

@Test
public void testIntArrays() throws Exception {
    Rnd rnd = new Rnd();
    UnstructuredFile hb = new UnstructuredFile(temp.newFile(), 16, JournalMode.APPEND);
    int[] vals = new int[100];
    long pos = hb.getPos();
    for (int i = 0; i < 10000; i++) {
        for (int k = 0; k < vals.length; k++) {
            vals[k] = rnd.nextInt();
        }
        hb.put(vals);
    }
    rnd.reset();
    hb.setPos(pos);
    for (int i = 0; i < 10000; i++) {
        hb.get(vals);
        for (int k = 0; k < vals.length; k++) {
            Assert.assertEquals(rnd.nextInt(), vals[k]);
        }
    }
}
Also used : Rnd(com.questdb.std.Rnd) Test(org.junit.Test)

Example 75 with Rnd

use of com.questdb.std.Rnd in project questdb by bluestreak01.

the class UnstructuredFileTest method testLongArrays.

@Test
public void testLongArrays() throws Exception {
    Rnd rnd = new Rnd();
    UnstructuredFile hb = new UnstructuredFile(temp.newFile(), 16, JournalMode.APPEND);
    long[] vals = new long[100];
    long pos = hb.getPos();
    for (int i = 0; i < 10000; i++) {
        for (int k = 0; k < vals.length; k++) {
            vals[k] = rnd.nextLong();
        }
        hb.put(vals);
    }
    rnd.reset();
    hb.setPos(pos);
    for (int i = 0; i < 10000; i++) {
        hb.get(vals);
        for (int k = 0; k < vals.length; k++) {
            Assert.assertEquals(rnd.nextLong(), vals[k]);
        }
    }
}
Also used : Rnd(com.questdb.std.Rnd) Test(org.junit.Test)

Aggregations

Rnd (com.questdb.std.Rnd)82 Test (org.junit.Test)50 JournalEntryWriter (com.questdb.store.JournalEntryWriter)43 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)43 JournalWriter (com.questdb.store.JournalWriter)42 AbstractTest (com.questdb.test.tools.AbstractTest)30 BeforeClass (org.junit.BeforeClass)8 Path (com.questdb.std.str.Path)7 JournalException (com.questdb.std.ex.JournalException)6 StringSink (com.questdb.std.str.StringSink)5 ObjList (com.questdb.std.ObjList)4 Factory (com.questdb.store.factory.Factory)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 NumericException (com.questdb.common.NumericException)3 Record (com.questdb.common.Record)3 RecordCursor (com.questdb.common.RecordCursor)3 Quote (com.questdb.model.Quote)3 ObjHashSet (com.questdb.std.ObjHashSet)3 File (java.io.File)3 BootstrapEnv (com.questdb.BootstrapEnv)2