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]");
}
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();
}
}
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();
}
}
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();
}
}
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);
}
Aggregations