use of com.questdb.store.JournalListener 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.store.JournalListener in project questdb by bluestreak01.
the class AuthReplicationClientMain method main.
public static void main(String[] args) throws Exception {
JournalConfiguration configuration = new JournalConfigurationBuilder().build(args[0]);
Factory factory = new Factory(configuration);
final JournalClient client = new JournalClient(factory, () -> "MY SECRET".getBytes("UTF8"));
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.JournalListener 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.JournalListener 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.JournalListener in project questdb by bluestreak01.
the class DataLossTest method testDiscardFile.
@Test
@Ignore
public void testDiscardFile() throws Exception {
// create master journal
try (JournalWriter<Quote> master = getFactory().writer(Quote.class, "master")) {
TestUtils.generateQuoteData(master, 300, master.getMaxTimestamp());
master.commit();
// publish master out
JournalServer server = new JournalServer(new ServerConfig() {
{
addNode(new ServerNode(0, "localhost"));
setEnableMultiCast(false);
setHeartbeatFrequency(50);
}
}, getFactory());
server.publish(master);
server.start();
final AtomicInteger counter = new AtomicInteger();
final AtomicInteger doNotExpect = new AtomicInteger();
// equalize slave
JournalClient client = new JournalClient(new ClientConfig("localhost") {
{
setEnableMultiCast(false);
}
}, getFactory());
client.subscribe(Quote.class, "master", "slave", new JournalListener() {
@Override
public void onCommit() {
counter.incrementAndGet();
}
@Override
public void onEvent(int event) {
}
});
client.start();
TestUtils.assertCounter(counter, 1, 10, TimeUnit.SECONDS);
// stop client to be able to add to slave manually
client.halt();
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
// add more data to slave
try (JournalWriter<Quote> slave = getFactory().writer(Quote.class, "slave")) {
TestUtils.generateQuoteData(slave, 200, slave.getMaxTimestamp());
slave.commit();
}
// synchronise slave again
client = new JournalClient(new ClientConfig("localhost"), getFactory());
client.subscribe(Quote.class, "master", "slave", new JournalListener() {
@Override
public void onCommit() {
doNotExpect.incrementAndGet();
}
@Override
public void onEvent(int event) {
counter.incrementAndGet();
}
});
client.start();
TestUtils.assertCounter(counter, 2, 180, TimeUnit.SECONDS);
client.halt();
Assert.assertEquals(0, doNotExpect.get());
try (JournalWriter w = getFactory().writer(Quote.class, "slave")) {
Assert.assertNotNull(w);
}
server.halt();
}
}
Aggregations