Search in sources :

Example 6 with ServerConfig

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

the class SslReplicationServerMain method start.

public void start() throws Exception {
    Factory factory = new Factory(location, 1000, 1, 0);
    JournalServer server = new JournalServer(new ServerConfig() {

        {
            getSslConfig().setSecure(true);
            try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) {
                getSslConfig().setKeyStore(is, "changeit");
            }
        }
    }, 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 : ServerConfig(com.questdb.net.ha.config.ServerConfig) Price(org.questdb.examples.support.Price) InputStream(java.io.InputStream) JournalServer(com.questdb.net.ha.JournalServer) Factory(com.questdb.store.factory.Factory)

Example 7 with ServerConfig

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

the class AuthorizationTest method testClientWithoutAuthProvider.

@Test
public void testClientWithoutAuthProvider() throws Exception {
    JournalServer server = new JournalServer(new ServerConfig() {

        {
            setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(500));
            setEnableMultiCast(false);
        }
    }, getFactory(), (token, requestedKeys) -> "SECRET".equals(new String(token)));
    server.start();
    try {
        final AtomicInteger authErrors = new AtomicInteger();
        final CountDownLatch error = new CountDownLatch(1);
        JournalClient client = new JournalClient(local, getFactory(), null, evt -> {
            switch(evt) {
                case JournalClientEvents.EVT_AUTH_CONFIG_ERROR:
                    authErrors.incrementAndGet();
                    break;
                case JournalClientEvents.EVT_TERMINATED:
                    error.countDown();
                    break;
                default:
                    break;
            }
        });
        client.start();
        Assert.assertTrue(error.await(5, TimeUnit.SECONDS));
        Assert.assertFalse(client.isRunning());
    } finally {
        server.halt();
    }
}
Also used : ServerConfig(com.questdb.net.ha.config.ServerConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 8 with ServerConfig

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

the class AuthorizationTest method testClientWrongAuth.

@Test
public void testClientWrongAuth() throws Exception {
    JournalServer server = new JournalServer(new ServerConfig() {

        {
            setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(500));
            setEnableMultiCast(false);
        }
    }, getFactory(), (token, requestedKeys) -> "SECRET".equals(new String(token)));
    final AtomicInteger authErrorCount = new AtomicInteger();
    final CountDownLatch serverError = new CountDownLatch(1);
    JournalClient client = new JournalClient(local, getFactory(), "NON_SECRET"::getBytes, evt -> {
        switch(evt) {
            case JournalClientEvents.EVT_AUTH_ERROR:
                authErrorCount.incrementAndGet();
                break;
            case JournalClientEvents.EVT_TERMINATED:
                serverError.countDown();
                break;
            default:
                break;
        }
    });
    server.start();
    try {
        client.start();
        Assert.assertTrue(serverError.await(5, TimeUnit.SECONDS));
        Assert.assertFalse(client.isRunning());
        Assert.assertEquals(1, authErrorCount.get());
    } finally {
        server.halt();
    }
}
Also used : ServerConfig(com.questdb.net.ha.config.ServerConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 9 with ServerConfig

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

the class AuthorizationTest method testServerAuthException.

@Test
public void testServerAuthException() throws Exception {
    JournalServer server = new JournalServer(new ServerConfig() {

        {
            setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(500));
            setEnableMultiCast(false);
        }
    }, getFactory(), (token, requestedKeys) -> {
        throw new FatalError("BANG!");
    });
    final AtomicInteger authErrorCount = new AtomicInteger();
    final CountDownLatch serverError = new CountDownLatch(1);
    JournalClient client = new JournalClient(local, getFactory(), "SECRET"::getBytes, evt -> {
        switch(evt) {
            case JournalClientEvents.EVT_AUTH_ERROR:
                authErrorCount.incrementAndGet();
                break;
            case JournalClientEvents.EVT_TERMINATED:
                serverError.countDown();
                break;
            default:
                break;
        }
    });
    server.start();
    try {
        client.start();
        Assert.assertTrue(serverError.await(5, TimeUnit.SECONDS));
        Assert.assertFalse(client.isRunning());
        Assert.assertEquals(1, authErrorCount.get());
    } finally {
        server.halt();
    }
}
Also used : ServerConfig(com.questdb.net.ha.config.ServerConfig) FatalError(com.questdb.std.ex.FatalError) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 10 with ServerConfig

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

the class AuthorizationTest method testClientAndServerSuccessfulAuth.

@Test
public void testClientAndServerSuccessfulAuth() throws Exception {
    JournalServer server = new JournalServer(new ServerConfig() {

        {
            setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(100));
            setEnableMultiCast(false);
        }
    }, getFactory(), (token, requestedKeys) -> "SECRET".equals(new String(token)));
    JournalClient client = new JournalClient(local, getFactory(), "SECRET"::getBytes);
    beginSync(server, client);
}
Also used : ServerConfig(com.questdb.net.ha.config.ServerConfig) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Aggregations

ServerConfig (com.questdb.net.ha.config.ServerConfig)20 ClientConfig (com.questdb.net.ha.config.ClientConfig)13 CountDownLatch (java.util.concurrent.CountDownLatch)11 Quote (com.questdb.model.Quote)10 AbstractTest (com.questdb.test.tools.AbstractTest)10 Test (org.junit.Test)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 ServerNode (com.questdb.net.ha.config.ServerNode)7 InputStream (java.io.InputStream)7 JournalWriter (com.questdb.store.JournalWriter)4 JournalListener (com.questdb.store.JournalListener)3 RecordSource (com.questdb.ql.RecordSource)2 RecordSourcePrinter (com.questdb.ql.RecordSourcePrinter)2 StringSink (com.questdb.std.str.StringSink)2 JournalKey (com.questdb.store.JournalKey)2 Factory (com.questdb.store.factory.Factory)2 Price (org.questdb.examples.support.Price)2 Trade (com.questdb.model.Trade)1 ClusterController (com.questdb.net.ha.ClusterController)1 JournalServer (com.questdb.net.ha.JournalServer)1