use of com.questdb.store.factory.configuration.JournalConfigurationBuilder 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.store.factory.configuration.JournalConfigurationBuilder in project questdb by bluestreak01.
the class JournalTest method testOpenJournalWithWrongPartitionType.
@Test
public void testOpenJournalWithWrongPartitionType() throws Exception {
try (JournalWriter<Quote> w = getFactory().writer(new JournalKey<>(Quote.class, "quote", PartitionBy.NONE))) {
TestUtils.generateQuoteData(w, 1000);
}
try {
getFactory().writer(new JournalKey<>(Quote.class, "quote", PartitionBy.MONTH));
Assert.fail("Exception expected");
} catch (JournalException e) {
// expect exception
}
try (Factory f2 = new Factory(new JournalConfigurationBuilder() {
{
$(Quote.class).$sym("mode");
}
}.build(factoryContainer.getConfiguration().getJournalBase()))) {
f2.writer(new JournalKey<>(Quote.class, "quote"));
Assert.fail("Exception expected");
} catch (JournalException e) {
// expect exception
}
}
use of com.questdb.store.factory.configuration.JournalConfigurationBuilder in project questdb by bluestreak01.
the class AppendObjectPartitioned method main.
/**
* Appends 1 million quotes into journal partitioned by day. Journal can only be partitioned on values of timestamp column.
*
* @param args factory directory
* @throws JournalException in case of any problems with the journal.
*/
public static void main(String[] args) throws JournalException {
if (args.length != 1) {
System.out.println("Usage: " + AppendObjectPartitioned.class.getName() + " <path>");
System.exit(1);
}
String journalLocation = args[0];
try (Factory factory = new Factory(new JournalConfigurationBuilder() {
{
$(Quote.class, "quote-by-day").partitionBy(PartitionBy.DAY).$ts();
}
}.build(journalLocation), 1000, 1, 0)) {
Files.delete(new File(factory.getConfiguration().getJournalBase(), "quote-by-day"));
// you can change it in runtime and also, optionally put journal in alternative location
try (JournalWriter<Quote> writer = factory.writer(Quote.class)) {
final int count = 1000000;
final String[] symbols = { "AGK.L", "BP.L", "TLW.L", "ABF.L", "LLOY.L", "BT-A.L", "WTB.L", "RRS.L", "ADM.L", "GKN.L", "HSBA.L" };
final Rnd r = new Rnd();
// reuse same same instance of Quote class to keep GC under control
final Quote q = new Quote();
long t = System.nanoTime();
for (int i = 0; i < count; i++) {
// prepare object for new set of data
q.clear();
// generate some data
q.setSym(symbols[Math.abs(r.nextInt() % (symbols.length - 1))]);
q.setAsk(Math.abs(r.nextDouble()));
q.setBid(Math.abs(r.nextDouble()));
q.setAskSize(Math.abs(r.nextInt() % 10000));
q.setBidSize(Math.abs(r.nextInt() % 10000));
q.setEx("LXE");
q.setMode("Fast trading");
q.setTimestamp(System.currentTimeMillis() + (i * 100));
writer.append(q);
}
// commit is necessary
writer.commit();
System.out.println("Journal size: " + writer.size());
System.out.println("Generated " + count + " objects in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t) + "ms.");
}
}
}
use of com.questdb.store.factory.configuration.JournalConfigurationBuilder in project questdb by bluestreak01.
the class AppendObjectTimeSeries method main.
/**
* Appends 1 million quotes to journal. Timestamp values are in chronological order.
*/
public static void main(String[] args) throws JournalException {
if (args.length != 1) {
System.out.println("Usage: " + AppendObjectTimeSeries.class.getName() + " <path>");
System.exit(1);
}
String journalLocation = args[0];
JournalConfiguration configuration = new JournalConfigurationBuilder() {
{
$(Quote.class, "quote").$ts();
}
}.build(journalLocation);
try (Factory factory = new Factory(configuration, 1000, 1, 0)) {
// delete existing quote journal
Files.delete(new File(configuration.getJournalBase(), "quote"));
try (JournalWriter<Quote> writer = factory.writer(Quote.class)) {
final int count = 1000000;
final String[] symbols = { "AGK.L", "BP.L", "TLW.L", "ABF.L", "LLOY.L", "BT-A.L", "WTB.L", "RRS.L", "ADM.L", "GKN.L", "HSBA.L" };
final Random r = new Random(System.currentTimeMillis());
// reuse same same instance of Quote class to keep GC under control
final Quote q = new Quote();
long t = System.nanoTime();
for (int i = 0; i < count; i++) {
// prepare object for new set of data
q.clear();
// generate some data
q.setSym(symbols[Math.abs(r.nextInt() % (symbols.length - 1))]);
q.setAsk(Math.abs(r.nextDouble()));
q.setBid(Math.abs(r.nextDouble()));
q.setAskSize(Math.abs(r.nextInt() % 10000));
q.setBidSize(Math.abs(r.nextInt() % 10000));
q.setEx("LXE");
q.setMode("Fast trading");
q.setTimestamp(System.currentTimeMillis());
writer.append(q);
}
// commit is necessary
writer.commit();
System.out.println("Journal size: " + writer.size());
System.out.println("Generated " + count + " objects in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t) + "ms.");
}
}
}
use of com.questdb.store.factory.configuration.JournalConfigurationBuilder in project questdb by bluestreak01.
the class AuthReplicationServerMain method start.
public void start() throws Exception {
JournalConfiguration configuration = new JournalConfigurationBuilder().build(location);
Factory factory = new Factory(configuration, 1000, 2, 0);
JournalServer server = new JournalServer(factory, (token, requestedKeys) -> "MY SECRET".equals(new String(token, "UTF8")));
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]");
}
Aggregations