Search in sources :

Example 31 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class JournalRecoveryTest method testLagRecovery.

@Test
public void testLagRecovery() throws Exception {
    try (JournalWriter<Quote> origin = getFactory().writer(Quote.class, "origin")) {
        TestUtils.generateQuoteData(origin, 100000, new Interval("2013-01-01T00:00:00.000Z", "2013-05-30T12:55:00.000Z"));
        try (Journal<Quote> r = getFactory().reader(Quote.class, "origin")) {
            Assert.assertEquals(100000, r.size());
        }
        long ts;
        try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
            w.disableCommitOnClose();
            w.append(origin.query().all().asResultSet().subset(0, 15000));
            w.mergeAppend(origin.query().all().asResultSet().subset(15000, 17000));
            w.commit();
            ts = w.getMaxTimestamp();
            w.mergeAppend(origin.query().all().asResultSet().subset(16000, 27000));
            w.mergeAppend(origin.query().all().asResultSet().subset(23000, 37000));
            Assert.assertTrue(ts < w.getMaxTimestamp());
            Assert.assertEquals(37672, w.size());
        }
        // make sure journal is closed in pool
        getFactory().lock(Quote.class.getName());
        getFactory().unlock(Quote.class.getName());
        try (Journal<Quote> w = getFactory().reader(Quote.class)) {
            Assert.assertEquals(ts, w.getMaxTimestamp());
            Assert.assertEquals(17000, w.size());
        }
        try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
            Assert.assertEquals(ts, w.getMaxTimestamp());
            Assert.assertEquals(17000, w.size());
        }
    }
}
Also used : Quote(com.questdb.model.Quote) Interval(com.questdb.std.time.Interval) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 32 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class JournalRecoveryTest method testRecovery.

@Test
public void testRecovery() throws Exception {
    long ts;
    try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
        w.disableCommitOnClose();
        Assert.assertFalse(w.isCommitOnClose());
        TestUtils.generateQuoteData(w, 10000, new Interval("2013-01-01T00:00:00.000Z", "2013-02-28T12:55:00.000Z"));
        ts = w.getMaxTimestamp();
        TestUtils.generateQuoteData(w, 10000, new Interval("2013-03-01T00:00:00.000Z", "2013-05-30T12:55:00.000Z"), false);
        Assert.assertTrue(w.getMaxTimestamp() > ts);
    }
    // make sure journal is closed in pool
    getFactory().lock(Quote.class.getName());
    getFactory().unlock(Quote.class.getName());
    try (Journal<Quote> w = getFactory().reader(Quote.class)) {
        Assert.assertEquals(ts, w.getMaxTimestamp());
        Assert.assertEquals(10000, w.size());
    }
    try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
        w.disableCommitOnClose();
        Assert.assertEquals(ts, w.getMaxTimestamp());
        Assert.assertEquals(10000, w.size());
    }
}
Also used : Quote(com.questdb.model.Quote) Interval(com.questdb.std.time.Interval) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 33 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class JournalRefreshTest method testReadConsistency.

@Test
public void testReadConsistency() throws JournalException {
    Quote q1 = new Quote().setSym("ABC").setEx("LN");
    Quote q2 = new Quote().setSym("EFG").setEx("SK");
    rw.append(q1);
    rw.close();
    rw = getFactory().writer(Quote.class);
    try (Journal<Quote> r = getFactory().reader(Quote.class)) {
        for (Quote v : r) {
            Assert.assertEquals(q1, v);
        }
        rw.append(q2);
        for (Quote v : r) {
            Assert.assertEquals(q1, v);
        }
    }
}
Also used : Quote(com.questdb.model.Quote) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 34 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class JournalTest method testSingleWriterModel.

@Test
public void testSingleWriterModel() throws Exception {
    try (JournalWriter<Quote> writer = getFactory().writer(Quote.class)) {
        Assert.assertTrue(writer != null);
        final CountDownLatch finished = new CountDownLatch(1);
        final AtomicInteger errors = new AtomicInteger();
        new Thread(() -> {
            try {
                getFactory().writer(Quote.class);
                errors.incrementAndGet();
            } catch (JournalException e) {
            // ignore
            }
            finished.countDown();
        }).start();
        Assert.assertTrue(finished.await(1, TimeUnit.SECONDS));
        Assert.assertEquals(0, errors.get());
        // check if we can open a reader
        try (Journal<Quote> r = getFactory().reader(Quote.class)) {
            Assert.assertTrue(r != null);
        }
        // check if we can open writer in alt location
        try (JournalWriter w = getFactory().writer(Quote.class, "test-Quote")) {
            Assert.assertTrue(w != null);
        }
    }
}
Also used : Quote(com.questdb.model.Quote) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JournalException(com.questdb.std.ex.JournalException) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 35 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class JournalTest method testOfflinePartition.

@Test
public void testOfflinePartition() throws Exception {
    int SIZE = 50000;
    File location;
    final String name = "origin";
    try (JournalWriter<Quote> origin = getFactory().writer(Quote.class, name, SIZE)) {
        TestUtils.generateQuoteData(origin, SIZE, DateFormatUtils.parseDateTime("2014-01-30T00:11:00.000Z"), 100000);
        origin.commit();
        location = new File(origin.getLocation(), "2014-03");
    }
    getFactory().lock(name);
    try {
        Files.deleteOrException(location);
    } finally {
        getFactory().unlock(name);
    }
    try (JournalWriter<Quote> origin = getFactory().writer(Quote.class, name)) {
        Assert.assertEquals(25914, origin.size());
        TestUtils.generateQuoteData(origin, 3000, DateFormatUtils.parseDateTime("2014-03-30T00:11:00.000Z"), 10000);
        Assert.assertEquals(28914, origin.size());
        origin.rollback();
        Assert.assertEquals(25914, origin.size());
    }
}
Also used : Quote(com.questdb.model.Quote) File(java.io.File) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Aggregations

Quote (com.questdb.model.Quote)80 Test (org.junit.Test)64 AbstractTest (com.questdb.test.tools.AbstractTest)63 ClientConfig (com.questdb.net.ha.config.ClientConfig)20 CountDownLatch (java.util.concurrent.CountDownLatch)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 JournalException (com.questdb.std.ex.JournalException)11 ServerConfig (com.questdb.net.ha.config.ServerConfig)10 ArrayList (java.util.ArrayList)9 Interval (com.questdb.std.time.Interval)8 InputStream (java.io.InputStream)6 JournalConfigurationBuilder (com.questdb.store.factory.configuration.JournalConfigurationBuilder)5 File (java.io.File)5 JournalListener (com.questdb.store.JournalListener)4 ServerNode (com.questdb.net.ha.config.ServerNode)3 RecordSource (com.questdb.ql.RecordSource)3 Rnd (com.questdb.std.Rnd)3 StringSink (com.questdb.std.str.StringSink)3 Ignore (org.junit.Ignore)3 NumericException (com.questdb.common.NumericException)2