Search in sources :

Example 1 with FactoryEventListener

use of com.questdb.store.factory.FactoryEventListener in project questdb by bluestreak01.

the class FactoryEventLoggerTest method testThroughput.

@Test
@Ignore
public void testThroughput() throws Exception {
    final FactoryEventLogger logger = new FactoryEventLogger(getFactory(), 1000, 1000, MicrosecondClockImpl.INSTANCE);
    final int count = 1000;
    final CountDownLatch done = new CountDownLatch(1);
    final CyclicBarrier barrier = new CyclicBarrier(2);
    final FactoryEventListener listener = getFactory().getEventListener();
    new Thread(() -> {
        try (Journal r = getFactory().reader("$mon_factory")) {
            barrier.await();
            int i = 0;
            while (i < count) {
                if (logger.run()) {
                    i++;
                } else {
                    r.refresh();
                    if (r.size() == count) {
                        break;
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            done.countDown();
        }
    }).start();
    barrier.await();
    int i = 0;
    while (i < count) {
        if (listener.onEvent((byte) 1, 1, "test", (short) 1, (short) 0, (short) 5)) {
            i++;
        } else {
            LockSupport.parkNanos(1);
        }
    }
    done.await();
    logger.close();
    try (Journal r = getFactory().reader("$mon_factory")) {
        System.out.println(r.size());
    }
}
Also used : FactoryEventListener(com.questdb.store.factory.FactoryEventListener) Journal(com.questdb.store.Journal) CountDownLatch(java.util.concurrent.CountDownLatch) CyclicBarrier(java.util.concurrent.CyclicBarrier) Ignore(org.junit.Ignore) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Aggregations

Journal (com.questdb.store.Journal)1 FactoryEventListener (com.questdb.store.factory.FactoryEventListener)1 AbstractTest (com.questdb.test.tools.AbstractTest)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1