Search in sources :

Example 1 with FactoryFullException

use of com.questdb.ex.FactoryFullException in project questdb by bluestreak01.

the class CachingReaderFactoryTest method testAllocateAndClear.

@Test
public void testAllocateAndClear() throws Exception {
    final JournalMetadata<?> m = new JournalStructure("z").$date("ts").$().build();
    getFactory().writer(m).close();
    try (CachingReaderFactory rf = new CachingReaderFactory(factoryContainer.getConfiguration(), 1, 2)) {
        int n = 2;
        final CyclicBarrier barrier = new CyclicBarrier(n);
        final CountDownLatch halt = new CountDownLatch(n);
        final AtomicInteger errors = new AtomicInteger();
        final AtomicInteger readerCount = new AtomicInteger();
        new Thread(() -> {
            try {
                for (int i = 0; i < 1000; i++) {
                    try (Journal ignored = rf.reader(m)) {
                        readerCount.incrementAndGet();
                    } catch (FactoryFullException ignored) {
                    }
                    if (i == 1) {
                        barrier.await();
                    }
                    LockSupport.parkNanos(10L);
                }
            } catch (Exception e) {
                e.printStackTrace();
                errors.incrementAndGet();
            } finally {
                halt.countDown();
            }
        }).start();
        new Thread(() -> {
            try {
                barrier.await();
                for (int i = 0; i < 1000; i++) {
                    rf.releaseInactive();
                    LockSupport.parkNanos(10L);
                }
            } catch (Exception e) {
                e.printStackTrace();
                errors.incrementAndGet();
            } finally {
                halt.countDown();
            }
        }).start();
        halt.await();
        Assert.assertTrue(readerCount.get() > 0);
        Assert.assertEquals(0, errors.get());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Journal(com.questdb.store.Journal) CountDownLatch(java.util.concurrent.CountDownLatch) FactoryFullException(com.questdb.ex.FactoryFullException) JournalLockedException(com.questdb.ex.JournalLockedException) JournalException(com.questdb.std.ex.JournalException) FactoryFullException(com.questdb.ex.FactoryFullException) RetryLockException(com.questdb.ex.RetryLockException) CyclicBarrier(java.util.concurrent.CyclicBarrier) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 2 with FactoryFullException

use of com.questdb.ex.FactoryFullException in project questdb by bluestreak01.

the class CachingReaderFactoryTest method testGetReadersBeforeFailure.

@SuppressWarnings("InfiniteLoopStatement")
@Test
public void testGetReadersBeforeFailure() throws Exception {
    // create journal
    final JournalMetadata<?> m = new JournalStructure("x").$date("ts").$().build();
    ((WriterFactory) getFactory()).writer(m).close();
    try (final CachingReaderFactory rf = new CachingReaderFactory(factoryContainer.getConfiguration(), 1000, 2)) {
        ObjList<Journal> readers = new ObjList<>();
        try {
            do {
                readers.add(rf.reader(m));
            } while (true);
        } catch (FactoryFullException e) {
            Assert.assertEquals(rf.getMaxEntries(), readers.size());
        } finally {
            for (int i = 0, n = readers.size(); i < n; i++) {
                readers.getQuick(i).close();
            }
        }
    }
}
Also used : ObjList(com.questdb.std.ObjList) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Journal(com.questdb.store.Journal) FactoryFullException(com.questdb.ex.FactoryFullException) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Aggregations

FactoryFullException (com.questdb.ex.FactoryFullException)2 Journal (com.questdb.store.Journal)2 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)2 AbstractTest (com.questdb.test.tools.AbstractTest)2 Test (org.junit.Test)2 JournalLockedException (com.questdb.ex.JournalLockedException)1 RetryLockException (com.questdb.ex.RetryLockException)1 ObjList (com.questdb.std.ObjList)1 JournalException (com.questdb.std.ex.JournalException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1