Search in sources :

Example 11 with JournalConfigurationBuilder

use of com.questdb.store.factory.configuration.JournalConfigurationBuilder in project questdb by bluestreak01.

the class IntegrationTest method testSubscribeIncompatibleWriter.

@Test
@SuppressWarnings("unchecked")
public void testSubscribeIncompatibleWriter() throws Exception {
    int size = 10000;
    try (JournalWriter<Quote> origin = getFactory().writer(Quote.class, "origin")) {
        TestUtils.generateQuoteData(origin, size);
        try (JournalWriter<Quote> remote = getFactory().writer(Quote.class, "remote")) {
            server.publish(remote);
            server.start();
            try {
                remote.append(origin.query().all().asResultSet().subset(0, 1000));
                remote.commit();
                try (JournalWriter writer = getFactory().writer(new JournalConfigurationBuilder().$("local").$int("x").$())) {
                    final CountDownLatch terminated = new CountDownLatch(1);
                    final AtomicInteger serverErrors = new AtomicInteger();
                    JournalClient client = new JournalClient(new ClientConfig("localhost"), getFactory(), null, evt -> {
                        if (evt == JournalClientEvents.EVT_TERMINATED) {
                            terminated.countDown();
                        }
                        if (evt == JournalClientEvents.EVT_SERVER_DIED) {
                            serverErrors.incrementAndGet();
                        }
                    });
                    client.start();
                    final CountDownLatch incompatible = new CountDownLatch(1);
                    try {
                        client.subscribe(new JournalKey<>("remote"), writer, new JournalListener() {

                            @Override
                            public void onCommit() {
                            }

                            @Override
                            public void onEvent(int event) {
                                if (event == JournalEvents.EVT_JNL_INCOMPATIBLE) {
                                    incompatible.countDown();
                                }
                            }
                        });
                        Assert.assertTrue(incompatible.await(500, TimeUnit.SECONDS));
                        remote.append(origin.query().all().asResultSet().subset(1000, 2000));
                        remote.commit();
                    } finally {
                        client.halt();
                    }
                    Assert.assertTrue(terminated.await(5, TimeUnit.SECONDS));
                    Assert.assertEquals(0, serverErrors.get());
                }
            } finally {
                server.halt();
            }
        }
    }
}
Also used : Quote(com.questdb.model.Quote) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConfig(com.questdb.net.ha.config.ClientConfig) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 12 with JournalConfigurationBuilder

use of com.questdb.store.factory.configuration.JournalConfigurationBuilder in project questdb by bluestreak01.

the class JournalTest method testOpenJournalWithWrongPartitionType.

@Test
public void testOpenJournalWithWrongPartitionType() throws Exception {
    try (JournalWriter<Quote> w = getFactory().writer(new JournalKey<>(Quote.class, "quote", PartitionBy.NONE))) {
        TestUtils.generateQuoteData(w, 1000);
    }
    try {
        getFactory().writer(new JournalKey<>(Quote.class, "quote", PartitionBy.MONTH));
        Assert.fail("Exception expected");
    } catch (JournalException e) {
    // expect exception
    }
    try (Factory f2 = new Factory(new JournalConfigurationBuilder() {

        {
            $(Quote.class).$sym("mode");
        }
    }.build(factoryContainer.getConfiguration().getJournalBase()))) {
        f2.writer(new JournalKey<>(Quote.class, "quote"));
        Assert.fail("Exception expected");
    } catch (JournalException e) {
    // expect exception
    }
}
Also used : Quote(com.questdb.model.Quote) JournalException(com.questdb.std.ex.JournalException) Factory(com.questdb.store.factory.Factory) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 13 with JournalConfigurationBuilder

use of com.questdb.store.factory.configuration.JournalConfigurationBuilder in project questdb by bluestreak01.

the class AppendObjectPartitioned method main.

/**
 * Appends 1 million quotes into journal partitioned by day. Journal can only be partitioned on values of timestamp column.
 *
 * @param args factory directory
 * @throws JournalException in case of any problems with the journal.
 */
public static void main(String[] args) throws JournalException {
    if (args.length != 1) {
        System.out.println("Usage: " + AppendObjectPartitioned.class.getName() + " <path>");
        System.exit(1);
    }
    String journalLocation = args[0];
    try (Factory factory = new Factory(new JournalConfigurationBuilder() {

        {
            $(Quote.class, "quote-by-day").partitionBy(PartitionBy.DAY).$ts();
        }
    }.build(journalLocation), 1000, 1, 0)) {
        Files.delete(new File(factory.getConfiguration().getJournalBase(), "quote-by-day"));
        // you can change it in runtime and also, optionally put journal in alternative location
        try (JournalWriter<Quote> writer = factory.writer(Quote.class)) {
            final int count = 1000000;
            final String[] symbols = { "AGK.L", "BP.L", "TLW.L", "ABF.L", "LLOY.L", "BT-A.L", "WTB.L", "RRS.L", "ADM.L", "GKN.L", "HSBA.L" };
            final Rnd r = new Rnd();
            // reuse same same instance of Quote class to keep GC under control
            final Quote q = new Quote();
            long t = System.nanoTime();
            for (int i = 0; i < count; i++) {
                // prepare object for new set of data
                q.clear();
                // generate some data
                q.setSym(symbols[Math.abs(r.nextInt() % (symbols.length - 1))]);
                q.setAsk(Math.abs(r.nextDouble()));
                q.setBid(Math.abs(r.nextDouble()));
                q.setAskSize(Math.abs(r.nextInt() % 10000));
                q.setBidSize(Math.abs(r.nextInt() % 10000));
                q.setEx("LXE");
                q.setMode("Fast trading");
                q.setTimestamp(System.currentTimeMillis() + (i * 100));
                writer.append(q);
            }
            // commit is necessary
            writer.commit();
            System.out.println("Journal size: " + writer.size());
            System.out.println("Generated " + count + " objects in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t) + "ms.");
        }
    }
}
Also used : Quote(org.questdb.examples.support.Quote) Factory(com.questdb.store.factory.Factory) Rnd(com.questdb.std.Rnd) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder) File(java.io.File)

Example 14 with JournalConfigurationBuilder

use of com.questdb.store.factory.configuration.JournalConfigurationBuilder in project questdb by bluestreak01.

the class AppendObjectTimeSeries method main.

/**
 * Appends 1 million quotes to journal. Timestamp values are in chronological order.
 */
public static void main(String[] args) throws JournalException {
    if (args.length != 1) {
        System.out.println("Usage: " + AppendObjectTimeSeries.class.getName() + " <path>");
        System.exit(1);
    }
    String journalLocation = args[0];
    JournalConfiguration configuration = new JournalConfigurationBuilder() {

        {
            $(Quote.class, "quote").$ts();
        }
    }.build(journalLocation);
    try (Factory factory = new Factory(configuration, 1000, 1, 0)) {
        // delete existing quote journal
        Files.delete(new File(configuration.getJournalBase(), "quote"));
        try (JournalWriter<Quote> writer = factory.writer(Quote.class)) {
            final int count = 1000000;
            final String[] symbols = { "AGK.L", "BP.L", "TLW.L", "ABF.L", "LLOY.L", "BT-A.L", "WTB.L", "RRS.L", "ADM.L", "GKN.L", "HSBA.L" };
            final Random r = new Random(System.currentTimeMillis());
            // reuse same same instance of Quote class to keep GC under control
            final Quote q = new Quote();
            long t = System.nanoTime();
            for (int i = 0; i < count; i++) {
                // prepare object for new set of data
                q.clear();
                // generate some data
                q.setSym(symbols[Math.abs(r.nextInt() % (symbols.length - 1))]);
                q.setAsk(Math.abs(r.nextDouble()));
                q.setBid(Math.abs(r.nextDouble()));
                q.setAskSize(Math.abs(r.nextInt() % 10000));
                q.setBidSize(Math.abs(r.nextInt() % 10000));
                q.setEx("LXE");
                q.setMode("Fast trading");
                q.setTimestamp(System.currentTimeMillis());
                writer.append(q);
            }
            // commit is necessary
            writer.commit();
            System.out.println("Journal size: " + writer.size());
            System.out.println("Generated " + count + " objects in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t) + "ms.");
        }
    }
}
Also used : Quote(org.questdb.examples.support.Quote) JournalConfiguration(com.questdb.store.factory.configuration.JournalConfiguration) Random(java.util.Random) Factory(com.questdb.store.factory.Factory) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder) File(java.io.File)

Example 15 with JournalConfigurationBuilder

use of com.questdb.store.factory.configuration.JournalConfigurationBuilder in project questdb by bluestreak01.

the class AuthReplicationServerMain method start.

public void start() throws Exception {
    JournalConfiguration configuration = new JournalConfigurationBuilder().build(location);
    Factory factory = new Factory(configuration, 1000, 2, 0);
    JournalServer server = new JournalServer(factory, (token, requestedKeys) -> "MY SECRET".equals(new String(token, "UTF8")));
    JournalWriter<Price> writer = factory.writer(Price.class);
    server.publish(writer);
    server.start();
    System.out.print("Publishing: ");
    for (int i = 0; i < 10; i++) {
        publishPrice(writer, i < 3 ? 1000000 : 100);
        Thread.sleep(TimeUnit.SECONDS.toMillis(2));
        System.out.print('.');
    }
    System.out.println(" [Done]");
}
Also used : JournalConfiguration(com.questdb.store.factory.configuration.JournalConfiguration) Price(org.questdb.examples.support.Price) JournalServer(com.questdb.net.ha.JournalServer) Factory(com.questdb.store.factory.Factory) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder)

Aggregations

JournalConfigurationBuilder (com.questdb.store.factory.configuration.JournalConfigurationBuilder)16 Factory (com.questdb.store.factory.Factory)13 JournalConfiguration (com.questdb.store.factory.configuration.JournalConfiguration)10 Price (org.questdb.examples.support.Price)7 ClientConfig (com.questdb.net.ha.config.ClientConfig)6 Quote (com.questdb.model.Quote)4 JournalClient (com.questdb.net.ha.JournalClient)4 JournalListener (com.questdb.store.JournalListener)4 AbstractTest (com.questdb.test.tools.AbstractTest)4 Test (org.junit.Test)4 File (java.io.File)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Quote (org.questdb.examples.support.Quote)3 JournalServer (com.questdb.net.ha.JournalServer)2 JournalWriter (com.questdb.store.JournalWriter)2 Random (java.util.Random)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ClusterController (com.questdb.net.ha.ClusterController)1 ServerConfig (com.questdb.net.ha.config.ServerConfig)1 ServerNode (com.questdb.net.ha.config.ServerNode)1