Search in sources :

Example 6 with JournalConfigurationBuilder

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

the class SimpleReplicationClientMain method main.

public static void main(String[] args) throws Exception {
    JournalConfiguration configuration = new JournalConfigurationBuilder().build(args[0]);
    Factory factory = new Factory(configuration, 1000, 1, 0);
    final JournalClient client = new JournalClient(factory);
    final Journal<Price> reader = factory.reader(Price.class, "price-copy");
    reader.setSequentialAccess(true);
    client.subscribe(Price.class, null, "price-copy", new JournalListener() {

        @Override
        public void onCommit() {
            int count = 0;
            long t = 0;
            for (Price p : JournalIterators.incrementBufferedIterator(reader)) {
                if (count == 0) {
                    t = p.getNanos();
                }
                count++;
            }
            System.out.println("took: " + (System.nanoTime() - t) + ", count=" + count);
        }

        @Override
        public void onEvent(int event) {
            System.out.println("There was an error");
        }
    });
    client.start();
    System.out.println("Client started");
}
Also used : JournalClient(com.questdb.net.ha.JournalClient) JournalConfiguration(com.questdb.store.factory.configuration.JournalConfiguration) Price(org.questdb.examples.support.Price) JournalListener(com.questdb.store.JournalListener) Factory(com.questdb.store.factory.Factory) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder)

Example 7 with JournalConfigurationBuilder

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

the class SimpleReplicationServerMain method start.

public void start() throws Exception {
    JournalConfiguration configuration = new JournalConfigurationBuilder().build(location);
    Factory factory = new Factory(configuration, 1000, 1, 0);
    JournalServer server = new JournalServer(factory);
    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)

Example 8 with JournalConfigurationBuilder

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

the class SslReplicationClientMain method main.

public static void main(String[] args) throws Exception {
    JournalConfiguration configuration = new JournalConfigurationBuilder().build(args[0]);
    Factory factory = new Factory(configuration, 1000, 1, 0);
    final JournalClient client = new JournalClient(new ClientConfig() {

        {
            getSslConfig().setSecure(true);
            try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) {
                getSslConfig().setTrustStore(is, "changeit");
            }
        }
    }, factory);
    final Journal<Price> reader = factory.reader(Price.class, "price-copy");
    reader.setSequentialAccess(true);
    client.subscribe(Price.class, null, "price-copy", new JournalListener() {

        @Override
        public void onCommit() {
            int count = 0;
            long t = 0;
            for (Price p : JournalIterators.incrementBufferedIterator(reader)) {
                if (count == 0) {
                    t = p.getNanos();
                }
                count++;
            }
            System.out.println("took: " + (System.nanoTime() - t) + ", count=" + count);
        }

        @Override
        public void onEvent(int event) {
            System.out.println("There was an error");
        }
    });
    client.start();
    System.out.println("Client started");
}
Also used : JournalClient(com.questdb.net.ha.JournalClient) JournalConfiguration(com.questdb.store.factory.configuration.JournalConfiguration) Price(org.questdb.examples.support.Price) InputStream(java.io.InputStream) JournalListener(com.questdb.store.JournalListener) Factory(com.questdb.store.factory.Factory) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder) ClientConfig(com.questdb.net.ha.config.ClientConfig)

Example 9 with JournalConfigurationBuilder

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

the class IntegrationTest method testResubscribeAfterBadSubscription.

@Test
public void testResubscribeAfterBadSubscription() throws Exception {
    // check that bad subscription doesn't cause dupe check to go haywire
    int size = 1000;
    try (JournalWriter<Quote> origin = getFactory().writer(Quote.class, "origin")) {
        TestUtils.generateQuoteData(origin, size);
        server.publish(origin);
        server.start();
        try {
            getFactory().writer(new JournalConfigurationBuilder().$("local").$int("x").$()).close();
            final CountDownLatch terminated = new CountDownLatch(1);
            final AtomicInteger serverDied = new AtomicInteger();
            JournalClient client = new JournalClient(new ClientConfig("localhost"), getFactory(), null, evt -> {
                switch(evt) {
                    case JournalClientEvents.EVT_TERMINATED:
                        terminated.countDown();
                        break;
                    case JournalClientEvents.EVT_SERVER_DIED:
                        serverDied.incrementAndGet();
                        break;
                    default:
                        break;
                }
            });
            client.start();
            try {
                final CountDownLatch incompatible = new CountDownLatch(1);
                client.subscribe(Quote.class, "origin", "local", 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));
                // delete incompatible journal
                getFactory().delete("local");
                // subscribe again and have client create compatible journal from server's metadata
                final AtomicInteger errorCount = new AtomicInteger();
                final CountDownLatch commit = new CountDownLatch(1);
                client.subscribe(Quote.class, "origin", "local", new JournalListener() {

                    @Override
                    public void onCommit() {
                        commit.countDown();
                    }

                    @Override
                    public void onEvent(int event) {
                        if (event != JournalEvents.EVT_JNL_SUBSCRIBED) {
                            errorCount.incrementAndGet();
                        }
                    }
                });
                Assert.assertTrue(commit.await(30, TimeUnit.SECONDS));
                Assert.assertEquals(0, errorCount.get());
            } finally {
                client.halt();
            }
            Assert.assertTrue(terminated.await(5, TimeUnit.SECONDS));
            Assert.assertEquals(0, serverDied.get());
            try (Journal r = getFactory().reader("local")) {
                Assert.assertEquals(size, r.size());
            }
        } 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 10 with JournalConfigurationBuilder

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

the class IntegrationTest method testSubscribeIncompatible.

@Test
public void testSubscribeIncompatible() 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();
                getFactory().writer(new JournalConfigurationBuilder().$("local").$int("x").$()).close();
                final CountDownLatch terminated = new CountDownLatch(1);
                JournalClient client = new JournalClient(new ClientConfig("localhost"), getFactory(), null, evt -> {
                    if (evt == JournalClientEvents.EVT_TERMINATED) {
                        terminated.countDown();
                    }
                });
                client.start();
                final CountDownLatch incompatible = new CountDownLatch(1);
                try {
                    client.subscribe(Quote.class, "remote", "local", 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));
            } finally {
                server.halt();
            }
        }
    }
}
Also used : Quote(com.questdb.model.Quote) 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)

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