Search in sources :

Example 26 with ClientConfig

use of com.questdb.net.ha.config.ClientConfig in project questdb by bluestreak01.

the class SSLTest method testNonAuthClientTrustMissing.

@Test
public void testNonAuthClientTrustMissing() throws Exception {
    try (JournalWriter<Quote> remote = getFactory().writer(Quote.class, "remote")) {
        JournalServer server = new JournalServer(new ServerConfig() {

            {
                setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(500));
                getSslConfig().setSecure(true);
                try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) {
                    getSslConfig().setKeyStore(is, "changeit");
                }
                setEnableMultiCast(false);
                setHeartbeatFrequency(50);
            }
        }, getFactory());
        try {
            final AtomicInteger serverErrorCount = new AtomicInteger();
            final CountDownLatch terminated = new CountDownLatch(1);
            JournalClient client = new JournalClient(new ClientConfig("localhost") {

                {
                    getSslConfig().setSecure(true);
                }
            }, getFactory(), null, evt -> {
                switch(evt) {
                    case JournalClientEvents.EVT_SERVER_ERROR:
                        serverErrorCount.incrementAndGet();
                        break;
                    case JournalClientEvents.EVT_TERMINATED:
                        terminated.countDown();
                        break;
                    default:
                        break;
                }
            });
            server.publish(remote);
            server.start();
            client.subscribe(Quote.class, "remote", "local");
            client.subscribe(Quote.class, "remote", "local");
            client.start();
            Assert.assertTrue(terminated.await(5, TimeUnit.SECONDS));
            // Assert.assertEquals(0, server.getConnectedClients());
            Assert.assertFalse(client.isRunning());
            Assert.assertEquals(1, serverErrorCount.get());
            client.halt();
        } finally {
            server.halt();
        }
    }
}
Also used : Quote(com.questdb.model.Quote) ServerConfig(com.questdb.net.ha.config.ServerConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InputStream(java.io.InputStream) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConfig(com.questdb.net.ha.config.ClientConfig)

Example 27 with ClientConfig

use of com.questdb.net.ha.config.ClientConfig in project questdb by bluestreak01.

the class ClusterConsumerMain method main.

public static void main(String[] args) throws Exception {
    final JournalConfiguration configuration = new JournalConfigurationBuilder() {

        {
            $(Price.class).$ts();
        }
    }.build(args[0]);
    final Factory factory = new Factory(configuration, 1000, 1, 0);
    final JournalClient client = new JournalClient(new ClientConfig("127.0.0.1:7080,127.0.0.1:7090") {

        {
            getReconnectPolicy().setRetryCount(6);
            getReconnectPolicy().setSleepBetweenRetriesMillis(1);
            getReconnectPolicy().setLoginRetryCount(2);
        }
    }, factory);
    final Journal<Price> reader = factory.reader(new JournalKey<>(Price.class, "price-copy", PartitionBy.NONE, 1000000000));
    reader.setSequentialAccess(true);
    client.subscribe(Price.class, null, "price-copy", 1000000000, 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++;
            }
            if (t == 0) {
                System.out.println("no data received");
            } else {
                System.out.println("took: " + (System.currentTimeMillis() - 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) ClientConfig(com.questdb.net.ha.config.ClientConfig)

Aggregations

ClientConfig (com.questdb.net.ha.config.ClientConfig)27 Quote (com.questdb.model.Quote)21 AbstractTest (com.questdb.test.tools.AbstractTest)17 CountDownLatch (java.util.concurrent.CountDownLatch)17 Test (org.junit.Test)16 ServerConfig (com.questdb.net.ha.config.ServerConfig)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 JournalConfigurationBuilder (com.questdb.store.factory.configuration.JournalConfigurationBuilder)8 ServerNode (com.questdb.net.ha.config.ServerNode)7 InputStream (java.io.InputStream)7 JournalListener (com.questdb.store.JournalListener)6 JournalException (com.questdb.std.ex.JournalException)5 JournalWriter (com.questdb.store.JournalWriter)4 Ignore (org.junit.Ignore)4 Factory (com.questdb.store.factory.Factory)3 JournalConfiguration (com.questdb.store.factory.configuration.JournalConfiguration)3 CyclicBarrier (java.util.concurrent.CyclicBarrier)3 Price (org.questdb.examples.support.Price)3 Log (com.questdb.log.Log)2 LogFactory (com.questdb.log.LogFactory)2