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