Search in sources :

Example 61 with Quote

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

the class IteratorTest method testMerge.

@Test
public void testMerge() throws Exception {
    populateQuotes();
    ObjList<Journal<Quote>> journals = new ObjList<Journal<Quote>>() {

        {
            add(getFactory().reader(Quote.class, "quote-0"));
            add(getFactory().reader(Quote.class, "quote-1"));
            add(getFactory().reader(Quote.class, "quote-2"));
            add(getFactory().reader(Quote.class, "quote-3"));
            add(getFactory().reader(Quote.class, "quote-4"));
        }
    };
    try {
        List<JournalIterator<Quote>> list = new ArrayList<>();
        for (int i = 0; i < journals.size(); i++) {
            list.add(JournalIterators.bufferedIterator(journals.get(i)));
        }
        long ts = 0;
        for (Quote q : MergingIterator.merge(list, comparator)) {
            Assert.assertTrue(ts <= q.getTimestamp());
            ts = q.getTimestamp();
        }
    } finally {
        for (int i = 0, n = journals.size(); i < n; i++) {
            journals.getQuick(i).close();
        }
    }
}
Also used : Quote(com.questdb.model.Quote) ObjList(com.questdb.std.ObjList) ArrayList(java.util.ArrayList) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 62 with Quote

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

the class IteratorTest method testIncrementIterator.

@Test
@SuppressWarnings("unused")
public void testIncrementIterator() throws Exception {
    // create empty
    getFactory().writer(Quote.class).close();
    try (Journal<Quote> r = getFactory().reader(Quote.class)) {
        try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
            try (JournalWriter<Quote> origin = getFactory().writer(Quote.class, "origin")) {
                TestUtils.generateQuoteData(origin, 10000);
                int count = 0;
                for (Quote q : JournalIterators.incrementIterator(r)) {
                    count++;
                }
                Assert.assertEquals(0, count);
                w.append(origin.query().all().asResultSet().subset(0, 5000));
                w.commit();
                for (Quote q : JournalIterators.incrementIterator(r)) {
                    count++;
                }
                Assert.assertEquals(5000, count);
                w.append(origin.query().all().asResultSet().subset(5000, 10000));
                w.commit();
                count = 0;
                for (Quote q : JournalIterators.incrementIterator(r)) {
                    count++;
                }
                Assert.assertEquals(5000, count);
            }
        }
    }
}
Also used : Quote(com.questdb.model.Quote) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 63 with Quote

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

the class IteratorTest method testBufferedIncrementIterator.

@Test
@SuppressWarnings("unused")
public void testBufferedIncrementIterator() throws Exception {
    getFactory().writer(Quote.class).close();
    try (Journal<Quote> r = getFactory().reader(Quote.class)) {
        try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
            try (JournalWriter<Quote> origin = getFactory().writer(Quote.class, "origin")) {
                TestUtils.generateQuoteData(origin, 10000);
                int count = 0;
                for (Quote q : JournalIterators.incrementBufferedIterator(r)) {
                    count++;
                }
                Assert.assertEquals(0, count);
                w.append(origin.query().all().asResultSet().subset(0, 5000));
                w.commit();
                for (Quote q : JournalIterators.incrementBufferedIterator(r)) {
                    count++;
                }
                Assert.assertEquals(5000, count);
                w.append(origin.query().all().asResultSet().subset(5000, 10000));
                w.commit();
                count = 0;
                for (Quote q : JournalIterators.incrementBufferedIterator(r)) {
                    count++;
                }
                Assert.assertEquals(5000, count);
            }
        }
    }
}
Also used : Quote(com.questdb.model.Quote) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 64 with Quote

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

the class IteratorTest method testEmptyPartitionFollowedByNonEmpty.

@Test
public void testEmptyPartitionFollowedByNonEmpty() throws Exception {
    try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
        w.getAppendPartition(DateFormatUtils.parseDateTime("2012-01-10T10:00:00.000Z"));
        w.append(new Quote().setSym("TST").setTimestamp(DateFormatUtils.parseDateTime("2012-02-10T10:00:00.000Z")));
        Assert.assertTrue(w.iterator().hasNext());
    }
}
Also used : Quote(com.questdb.model.Quote) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 65 with Quote

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

the class JournalMetadataTest method testMetadataWrite.

@Test
public void testMetadataWrite() throws Exception {
    JournalMetadataBuilder<Quote> b = new JournalMetadataBuilder<>(Quote.class);
    UnstructuredFile hb = new UnstructuredFile(temp.newFile(), 10, JournalMode.APPEND);
    JournalMetadata m = b.build();
    m.write(hb);
    JournalMetadata metadata = new JournalMetadata(hb, null);
    hb.close();
    Assert.assertTrue(m.isCompatible(metadata, false));
}
Also used : Quote(com.questdb.model.Quote) JournalMetadata(com.questdb.store.factory.configuration.JournalMetadata) JournalMetadataBuilder(com.questdb.store.factory.configuration.JournalMetadataBuilder) 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