use of com.questdb.store.factory.configuration.JournalConfigurationBuilder in project questdb by bluestreak01.
the class SimpleReplicationClientMain method main.
public static void main(String[] args) throws Exception {
JournalConfiguration configuration = new JournalConfigurationBuilder().build(args[0]);
Factory factory = new Factory(configuration, 1000, 1, 0);
final JournalClient client = new JournalClient(factory);
final Journal<Price> reader = factory.reader(Price.class, "price-copy");
reader.setSequentialAccess(true);
client.subscribe(Price.class, null, "price-copy", new JournalListener() {
@Override
public void onCommit() {
int count = 0;
long t = 0;
for (Price p : JournalIterators.incrementBufferedIterator(reader)) {
if (count == 0) {
t = p.getNanos();
}
count++;
}
System.out.println("took: " + (System.nanoTime() - t) + ", count=" + count);
}
@Override
public void onEvent(int event) {
System.out.println("There was an error");
}
});
client.start();
System.out.println("Client started");
}
use of com.questdb.store.factory.configuration.JournalConfigurationBuilder in project questdb by bluestreak01.
the class SimpleReplicationServerMain method start.
public void start() throws Exception {
JournalConfiguration configuration = new JournalConfigurationBuilder().build(location);
Factory factory = new Factory(configuration, 1000, 1, 0);
JournalServer server = new JournalServer(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.store.factory.configuration.JournalConfigurationBuilder in project questdb by bluestreak01.
the class SslReplicationClientMain method main.
public static void main(String[] args) throws Exception {
JournalConfiguration configuration = new JournalConfigurationBuilder().build(args[0]);
Factory factory = new Factory(configuration, 1000, 1, 0);
final JournalClient client = new JournalClient(new ClientConfig() {
{
getSslConfig().setSecure(true);
try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) {
getSslConfig().setTrustStore(is, "changeit");
}
}
}, factory);
final Journal<Price> reader = factory.reader(Price.class, "price-copy");
reader.setSequentialAccess(true);
client.subscribe(Price.class, null, "price-copy", new JournalListener() {
@Override
public void onCommit() {
int count = 0;
long t = 0;
for (Price p : JournalIterators.incrementBufferedIterator(reader)) {
if (count == 0) {
t = p.getNanos();
}
count++;
}
System.out.println("took: " + (System.nanoTime() - t) + ", count=" + count);
}
@Override
public void onEvent(int event) {
System.out.println("There was an error");
}
});
client.start();
System.out.println("Client started");
}
use of com.questdb.store.factory.configuration.JournalConfigurationBuilder in project questdb by bluestreak01.
the class IntegrationTest method testResubscribeAfterBadSubscription.
@Test
public void testResubscribeAfterBadSubscription() throws Exception {
// check that bad subscription doesn't cause dupe check to go haywire
int size = 1000;
try (JournalWriter<Quote> origin = getFactory().writer(Quote.class, "origin")) {
TestUtils.generateQuoteData(origin, size);
server.publish(origin);
server.start();
try {
getFactory().writer(new JournalConfigurationBuilder().$("local").$int("x").$()).close();
final CountDownLatch terminated = new CountDownLatch(1);
final AtomicInteger serverDied = new AtomicInteger();
JournalClient client = new JournalClient(new ClientConfig("localhost"), getFactory(), null, evt -> {
switch(evt) {
case JournalClientEvents.EVT_TERMINATED:
terminated.countDown();
break;
case JournalClientEvents.EVT_SERVER_DIED:
serverDied.incrementAndGet();
break;
default:
break;
}
});
client.start();
try {
final CountDownLatch incompatible = new CountDownLatch(1);
client.subscribe(Quote.class, "origin", "local", 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));
// delete incompatible journal
getFactory().delete("local");
// subscribe again and have client create compatible journal from server's metadata
final AtomicInteger errorCount = new AtomicInteger();
final CountDownLatch commit = new CountDownLatch(1);
client.subscribe(Quote.class, "origin", "local", new JournalListener() {
@Override
public void onCommit() {
commit.countDown();
}
@Override
public void onEvent(int event) {
if (event != JournalEvents.EVT_JNL_SUBSCRIBED) {
errorCount.incrementAndGet();
}
}
});
Assert.assertTrue(commit.await(30, TimeUnit.SECONDS));
Assert.assertEquals(0, errorCount.get());
} finally {
client.halt();
}
Assert.assertTrue(terminated.await(5, TimeUnit.SECONDS));
Assert.assertEquals(0, serverDied.get());
try (Journal r = getFactory().reader("local")) {
Assert.assertEquals(size, r.size());
}
} finally {
server.halt();
}
}
}
use of com.questdb.store.factory.configuration.JournalConfigurationBuilder in project questdb by bluestreak01.
the class IntegrationTest method testSubscribeIncompatible.
@Test
public void testSubscribeIncompatible() 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();
getFactory().writer(new JournalConfigurationBuilder().$("local").$int("x").$()).close();
final CountDownLatch terminated = new CountDownLatch(1);
JournalClient client = new JournalClient(new ClientConfig("localhost"), getFactory(), null, evt -> {
if (evt == JournalClientEvents.EVT_TERMINATED) {
terminated.countDown();
}
});
client.start();
final CountDownLatch incompatible = new CountDownLatch(1);
try {
client.subscribe(Quote.class, "remote", "local", 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));
} finally {
server.halt();
}
}
}
}
Aggregations