Search in sources :

Example 1 with Quote

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

the class ReconnectTest method testServerRestart.

@Test
@Ignore
public void testServerRestart() throws Exception {
    final int size = 10000;
    try (JournalWriter<Quote> remote = getFactory().writer(Quote.class, "remote", 2 * size)) {
        // start server #1
        JournalServer server = newServer();
        server.publish(remote);
        server.start();
        final CountDownLatch connectedLatch = new CountDownLatch(1);
        JournalClient client = new JournalClient(new ClientConfig("localhost") {

            {
                getReconnectPolicy().setLoginRetryCount(3);
                getReconnectPolicy().setRetryCount(5);
                getReconnectPolicy().setSleepBetweenRetriesMillis(TimeUnit.SECONDS.toMillis(1));
            }
        }, getFactory(), null, evt -> {
            if (evt == JournalClientEvents.EVT_CONNECTED) {
                connectedLatch.countDown();
            }
        });
        // subscribe client, waiting for complete set of data
        // when data arrives client triggers latch
        final CountDownLatch latch = new CountDownLatch(1);
        // create empty "local"
        getFactory().writer(Quote.class, "local").close();
        try (final Journal<Quote> local = getFactory().reader(Quote.class, "local")) {
            client.subscribe(Quote.class, "remote", "local", 2 * size, new JournalListener() {

                @Override
                public void onCommit() {
                    try {
                        if (local.refresh() && local.size() == 2 * size) {
                            latch.countDown();
                        }
                    } catch (JournalException e) {
                        throw new JournalRuntimeException(e);
                    }
                }

                @Override
                public void onEvent(int event) {
                }
            });
            client.start();
            Assert.assertTrue(connectedLatch.await(5, TimeUnit.SECONDS));
            // generate first batch
            TestUtils.generateQuoteData(remote, size, System.currentTimeMillis(), 1);
            remote.commit();
            // stop server
            server.halt();
            // start server #2
            server = newServer();
            server.publish(remote);
            server.start();
            // generate second batch
            TestUtils.generateQuoteData(remote, size, System.currentTimeMillis() + 2 * size, 1);
            remote.commit();
            // wait for client to get full set
            latch.await();
            // stop client and server
            client.halt();
            server.halt();
            // assert client state
            TestUtils.assertDataEquals(remote, local);
        }
    }
}
Also used : Quote(com.questdb.model.Quote) JournalException(com.questdb.std.ex.JournalException) JournalListener(com.questdb.store.JournalListener) JournalRuntimeException(com.questdb.common.JournalRuntimeException) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConfig(com.questdb.net.ha.config.ClientConfig) Ignore(org.junit.Ignore) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 2 with Quote

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

the class SSLTest method testClientAuth.

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

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

                {
                    getSslConfig().setSecure(true);
                    try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) {
                        getSslConfig().setKeyStore(is, "changeit");
                    }
                    try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) {
                        getSslConfig().setTrustStore(is, "changeit");
                    }
                }
            }, getFactory());
            server.publish(remote);
            server.start();
            client.subscribe(Quote.class, "remote", "local");
            client.start();
            TestUtils.generateQuoteData(remote, size);
            Thread.sleep(1000);
            client.halt();
            try (Journal<Quote> local = getFactory().reader(Quote.class, "local")) {
                TestUtils.assertDataEquals(remote, local);
            }
        } finally {
            server.halt();
        }
    }
}
Also used : Quote(com.questdb.model.Quote) ServerConfig(com.questdb.net.ha.config.ServerConfig) InputStream(java.io.InputStream) ClientConfig(com.questdb.net.ha.config.ClientConfig)

Example 3 with Quote

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

the class SSLTest method testSingleKeySSL.

@Test
public void testSingleKeySSL() throws Exception {
    int size = 1000;
    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 {
            JournalClient client = new JournalClient(new ClientConfig("localhost") {

                {
                    setTcpNoDelay(false);
                    try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) {
                        getSslConfig().setTrustStore(is, "changeit");
                    }
                    getSslConfig().setSecure(true);
                }
            }, getFactory());
            server.publish(remote);
            server.start();
            client.subscribe(Quote.class, "remote", "local");
            client.start();
            TestUtils.generateQuoteData(remote, size);
            Thread.sleep(500);
            client.halt();
            try (Journal<Quote> local = getFactory().reader(Quote.class, "local")) {
                TestUtils.assertDataEquals(remote, local);
            }
        } finally {
            server.halt();
        }
    }
}
Also used : Quote(com.questdb.model.Quote) ServerConfig(com.questdb.net.ha.config.ServerConfig) InputStream(java.io.InputStream) ClientConfig(com.questdb.net.ha.config.ClientConfig)

Example 4 with Quote

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

the class SSLTest method testServerTrustMissing.

@Test
public void testServerTrustMissing() 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);
                getSslConfig().setRequireClientAuth(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);
                    try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) {
                        getSslConfig().setTrustStore(is, "changeit");
                    }
                    try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) {
                        getSslConfig().setKeyStore(is, "changeit");
                    }
                }
            }, 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.start();
            Assert.assertTrue(terminated.await(5, TimeUnit.SECONDS));
            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 5 with Quote

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

the class SSLTest method testNoCertTrustAllSSL.

@Test
public void testNoCertTrustAllSSL() throws Exception {
    int size = 2000;
    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 {
            JournalClient client = new JournalClient(new ClientConfig("localhost") {

                {
                    getSslConfig().setSecure(true);
                    getSslConfig().setTrustAll(true);
                }
            }, getFactory());
            server.publish(remote);
            server.start();
            client.subscribe(Quote.class, "remote", "local");
            client.start();
            TestUtils.generateQuoteData(remote, size);
            Thread.sleep(1000);
            client.halt();
        } finally {
            server.halt();
        }
        try (Journal<Quote> local = getFactory().reader(Quote.class, "local")) {
            TestUtils.assertDataEquals(remote, local);
        }
    }
}
Also used : Quote(com.questdb.model.Quote) ServerConfig(com.questdb.net.ha.config.ServerConfig) InputStream(java.io.InputStream) ClientConfig(com.questdb.net.ha.config.ClientConfig)

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