use of com.questdb.net.ha.config.ServerConfig 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();
}
}
}
use of com.questdb.net.ha.config.ServerConfig 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();
}
}
}
use of com.questdb.net.ha.config.ServerConfig 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();
}
}
}
use of com.questdb.net.ha.config.ServerConfig 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);
}
}
}
use of com.questdb.net.ha.config.ServerConfig in project questdb by bluestreak01.
the class ClusteredProducerMain method main.
public static void main(String[] args) throws JournalException, IOException, JournalNetworkException, NumericException {
final String pathToDatabase = args[0];
final int instance = Numbers.parseInt(args[1]);
final JournalConfiguration configuration = new JournalConfigurationBuilder() {
{
$(Price.class).$ts();
}
}.build(pathToDatabase);
final Factory factory = new Factory(configuration, 1000, 1, 0);
final JournalWriter<Price> writer = factory.writer(new JournalKey<>(Price.class, null, PartitionBy.DEFAULT, 1000000000));
final WorkerController wc = new WorkerController(writer);
final ClusterController cc = new ClusterController(new ServerConfig() {
{
addNode(new ServerNode(1, "127.0.0.1:7080"));
addNode(new ServerNode(2, "127.0.0.1:7090"));
}
}, new ClientConfig(), factory, instance, new ArrayList<JournalWriter>() {
{
add(writer);
}
}, wc);
cc.start();
Runtime.getRuntime().addShutdownHook(new Thread(cc::halt));
}
Aggregations