Search in sources :

Example 21 with ClientConfig

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

the class IntegrationTest method testOutOfSyncClient.

/**
 * Create two journal that are in sync.
 * Disconnect synchronisation and advance client by two transaction and server by one
 * Server will offer rollback by proving txn of its latest transaction.
 * Client will have same txn but different pin, because it was advancing out of sync with server.
 * Client should produce and error by reporting unknown txn from server.
 */
@Test
public void testOutOfSyncClient() throws Exception {
    int size = 10000;
    try (JournalWriter<Quote> remote = getFactory().writer(Quote.class, "remote", 2 * size)) {
        server.publish(remote);
        server.start();
        try {
            final CountDownLatch commitLatch1 = new CountDownLatch(1);
            client.subscribe(Quote.class, "remote", "local", 2 * size, new JournalListener() {

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

                @Override
                public void onEvent(int event) {
                }
            });
            client.start();
            TestUtils.generateQuoteData(remote, size);
            Assert.assertTrue(commitLatch1.await(5, TimeUnit.SECONDS));
            client.halt();
            try (Journal<Quote> local = getFactory().reader(Quote.class, "local")) {
                TestUtils.assertDataEquals(remote, local);
            }
            TestUtils.generateQuoteData(remote, 10000, remote.getMaxTimestamp());
            remote.commit();
            try (JournalWriter<Quote> localW = getFactory().writer(Quote.class, "local")) {
                TestUtils.generateQuoteData(localW, 10000, localW.getMaxTimestamp());
                localW.commit();
                TestUtils.generateQuoteData(localW, 10000, localW.getMaxTimestamp());
                localW.commit();
            }
            final CountDownLatch errorCountDown = new CountDownLatch(1);
            client = new JournalClient(new ClientConfig("localhost"), getFactory());
            client.subscribe(Quote.class, "remote", "local", 2 * size, new JournalListener() {

                @Override
                public void onCommit() {
                }

                @Override
                public void onEvent(int event) {
                    errorCountDown.countDown();
                }
            });
            client.start();
            Assert.assertTrue(errorCountDown.await(5, TimeUnit.SECONDS));
            client.halt();
        } finally {
            server.halt();
        }
    }
}
Also used : Quote(com.questdb.model.Quote) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConfig(com.questdb.net.ha.config.ClientConfig) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 22 with ClientConfig

use of com.questdb.net.ha.config.ClientConfig 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 23 with ClientConfig

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

the class MulticastTest method assertMulticast.

private void assertMulticast() throws JournalNetworkException, InterruptedException {
    AbstractOnDemandSender sender = new OnDemandAddressSender(new ServerConfig(), 120, 150, 0);
    sender.start();
    Thread.sleep(1000L);
    OnDemandAddressPoller poller = new OnDemandAddressPoller(new ClientConfig(), 150, 120);
    ServerNode address = poller.poll(2, 500, TimeUnit.MILLISECONDS);
    Assert.assertNotNull(address);
    sender.halt();
}
Also used : ServerConfig(com.questdb.net.ha.config.ServerConfig) AbstractOnDemandSender(com.questdb.net.ha.mcast.AbstractOnDemandSender) OnDemandAddressSender(com.questdb.net.ha.mcast.OnDemandAddressSender) OnDemandAddressPoller(com.questdb.net.ha.mcast.OnDemandAddressPoller) ClientConfig(com.questdb.net.ha.config.ClientConfig) ServerNode(com.questdb.net.ha.config.ServerNode)

Example 24 with ClientConfig

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

the class MulticastTest method testIPv6.

@Test
public void testIPv6() throws Exception {
    if (multicastDisabled || !hasIPv6()) {
        return;
    }
    JournalServer server = new JournalServer(new ServerConfig() {

        {
            addNode(new ServerNode(0, "[0:0:0:0:0:0:0:0]"));
            setHeartbeatFrequency(100);
        }
    }, getFactory(), null, 0);
    final CountDownLatch connected = new CountDownLatch(1);
    JournalClient client = new JournalClient(new ClientConfig(), getFactory(), null, evt -> {
        if (evt == JournalClientEvents.EVT_CONNECTED) {
            connected.countDown();
        }
    });
    server.start();
    client.start();
    connected.await(3, TimeUnit.SECONDS);
    client.halt();
    server.halt();
}
Also used : ServerConfig(com.questdb.net.ha.config.ServerConfig) ServerNode(com.questdb.net.ha.config.ServerNode) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConfig(com.questdb.net.ha.config.ClientConfig) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 25 with ClientConfig

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

the class SSLTest method testAuthBothCertsMissing.

@Test
@Ignore
public void testAuthBothCertsMissing() 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");
                    }
                }
            }, 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.assertEquals(0, server.getConnectedClients());
            Assert.assertFalse(client.isRunning());
            Assert.assertEquals(1, serverErrorCount.get());
        } 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)

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