use of com.questdb.model.Quote in project questdb by bluestreak01.
the class IntegrationTest method testBadSubscriptionOnTheFlyFollowedByReconnect.
@Test
public void testBadSubscriptionOnTheFlyFollowedByReconnect() throws Exception {
try (final JournalWriter<Quote> origin = getFactory().writer(Quote.class, "origin")) {
final int batchSize = 1000;
final int batchCount = 100;
server.publish(origin);
server.start();
try {
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 AtomicInteger commits = new AtomicInteger();
final AtomicInteger errors = new AtomicInteger();
final CountDownLatch localSubscribed = new CountDownLatch(1);
final CountDownLatch dataReceived = new CountDownLatch(1);
try {
// create empty journal
getFactory().writer(Quote.class, "local").close();
try (final Journal local = getFactory().reader("local")) {
client.subscribe(Quote.class, "origin", "local", new JournalListener() {
@Override
public void onCommit() {
commits.incrementAndGet();
try {
local.refresh();
if (local.size() == batchCount * batchSize) {
dataReceived.countDown();
}
} catch (JournalException e) {
e.printStackTrace();
errors.incrementAndGet();
}
}
@Override
public void onEvent(int event) {
switch(event) {
case JournalEvents.EVT_JNL_SUBSCRIBED:
localSubscribed.countDown();
break;
default:
errors.incrementAndGet();
break;
}
}
});
final CountDownLatch published = new CountDownLatch(1);
final CyclicBarrier barrier = new CyclicBarrier(2);
final AtomicInteger publisherErrors = new AtomicInteger();
new Thread(() -> {
try {
barrier.await();
long timestamp = DateFormatUtils.parseDateTime("2013-09-04T10:00:00.000Z");
long increment = 1000L;
for (int i = 0; i < batchCount; i++) {
TestUtils.generateQuoteData(origin, batchSize, timestamp, increment);
timestamp += increment * (batchSize);
origin.commit();
}
} catch (Throwable e) {
e.printStackTrace();
publisherErrors.incrementAndGet();
}
published.countDown();
}).start();
Assert.assertTrue(localSubscribed.await(10, TimeUnit.SECONDS));
barrier.await();
// after publishing stream is setup we attempt to subscribe bad journal
// todo: this part breaks server, fix server and continue
// readerFactory.writer(new JournalConfigurationBuilder().$("x").$int("x").$()).close();
//
// client.subscribe(Quote.class, "origin", "x", new JournalListener() {
// @Override
// public void onCommit() {
//
// }
//
// @Override
// public void onEvent(int event) {
// System.out.println("bad event: " + event);
// }
// });
Assert.assertTrue(published.await(60, TimeUnit.SECONDS));
Assert.assertTrue(dataReceived.await(60, TimeUnit.SECONDS));
Assert.assertEquals(0, publisherErrors.get());
Assert.assertEquals(0, errors.get());
Assert.assertTrue(commits.get() > 0);
local.refresh();
Assert.assertEquals(batchSize * batchCount, local.size());
}
} catch (Throwable e) {
e.printStackTrace();
Assert.fail();
} finally {
client.halt();
}
Assert.assertTrue(terminated.await(5, TimeUnit.SECONDS));
} finally {
server.halt();
}
}
// Assert.fail();
}
use of com.questdb.model.Quote in project questdb by bluestreak01.
the class IntegrationTest method testSingleJournalSync.
@Test
public void testSingleJournalSync() throws Exception {
int size = 100000;
try (JournalWriter<Quote> remote = getFactory().writer(Quote.class, "remote", 2 * size)) {
server.publish(remote);
server.start();
try {
final CountDownLatch latch = new CountDownLatch(1);
client.subscribe(Quote.class, "remote", "local", 2 * size, new JournalListener() {
@Override
public void onCommit() {
latch.countDown();
}
@Override
public void onEvent(int event) {
}
});
client.start();
TestUtils.generateQuoteData(remote, size);
latch.await();
client.halt();
} finally {
server.halt();
}
try (Journal<Quote> local = getFactory().reader(Quote.class, "local")) {
TestUtils.assertDataEquals(remote, local);
}
}
}
use of com.questdb.model.Quote in project questdb by bluestreak01.
the class IntegrationTest method testOutOfSyncServerSide.
@Test
@Ignore
public // this is failing intermittently, replication is up for rewrite, cant be bothered fixing badly designed code
void testOutOfSyncServerSide() throws Exception {
int size = 10000;
try (JournalWriter<Quote> remote = getFactory().writer(Quote.class, "remote", 2 * size)) {
server.publish(remote);
server.start();
try {
final AtomicInteger serverErrors = new AtomicInteger();
final AtomicInteger commits = new AtomicInteger();
client = new JournalClient(new ClientConfig("localhost"), getFactory(), null, evt -> {
if (evt == JournalClientEvents.EVT_SERVER_DIED) {
serverErrors.incrementAndGet();
}
});
client.subscribe(Quote.class, "remote", "local", 2 * size, new JournalListener() {
@Override
public void onCommit() {
commits.incrementAndGet();
}
@Override
public void onEvent(int event) {
}
});
client.start();
TestUtils.generateQuoteData(remote, size);
TestUtils.assertCounter(commits, 1, 1, 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();
TestUtils.generateQuoteData(remote, 10000, remote.getMaxTimestamp());
remote.commit();
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 AtomicInteger errorCounter = new AtomicInteger();
client = new JournalClient(new ClientConfig("localhost"), getFactory(), null, evt -> {
if (evt == JournalClientEvents.EVT_SERVER_DIED) {
serverErrors.incrementAndGet();
}
});
client.subscribe(Quote.class, "remote", "local", 2 * size, new JournalListener() {
@Override
public void onCommit() {
commits.incrementAndGet();
}
@Override
public void onEvent(int event) {
errorCounter.incrementAndGet();
System.out.println("EV: " + event);
}
});
client.start();
TestUtils.assertCounter(commits, 1, 1, TimeUnit.SECONDS);
TestUtils.assertCounter(errorCounter, 1, 1, TimeUnit.SECONDS);
client.halt();
Assert.assertEquals(0, serverErrors.get());
} finally {
server.halt();
}
}
}
use of com.questdb.model.Quote 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();
}
}
}
}
use of com.questdb.model.Quote in project questdb by bluestreak01.
the class IntegrationTest method testTwoJournalsSync.
@Test
public void testTwoJournalsSync() throws Exception {
int size = 10000;
try (JournalWriter<Quote> remote1 = getFactory().writer(Quote.class, "remote1", 2 * size)) {
try (JournalWriter<TestEntity> remote2 = getFactory().writer(TestEntity.class, "remote2", 2 * size)) {
server.publish(remote1);
server.publish(remote2);
server.start();
final CountDownLatch latch = new CountDownLatch(2);
client.subscribe(Quote.class, "remote1", "local1", 2 * size, new JournalListener() {
@Override
public void onCommit() {
latch.countDown();
}
@Override
public void onEvent(int event) {
}
});
client.subscribe(TestEntity.class, "remote2", "local2", 2 * size, new JournalListener() {
@Override
public void onCommit() {
latch.countDown();
}
@Override
public void onEvent(int event) {
}
});
client.start();
TestUtils.generateQuoteData(remote1, size);
TestUtils.generateTestEntityData(remote2, size);
latch.await();
client.halt();
server.halt();
try (Journal<Quote> local1 = getFactory().reader(Quote.class, "local1")) {
Assert.assertEquals("Local1 has wrong size", size, local1.size());
}
try (Journal<TestEntity> local2 = getFactory().reader(TestEntity.class, "local2")) {
Assert.assertEquals("Remote2 has wrong size", size, remote2.size());
Assert.assertEquals("Local2 has wrong size", size, local2.size());
}
}
}
}
Aggregations