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