Search in sources :

Example 1 with PoolClosedException

use of io.questdb.cairo.pool.ex.PoolClosedException in project questdb by bluestreak01.

the class ReaderPoolTest method testGetAndCloseRace.

@Test
public void testGetAndCloseRace() throws Exception {
    try (TableModel model = new TableModel(configuration, "xyz", PartitionBy.NONE).col("ts", ColumnType.DATE)) {
        CairoTestUtils.create(model);
    }
    for (int i = 0; i < 100; i++) {
        assertWithPool(pool -> {
            AtomicInteger exceptionCount = new AtomicInteger();
            CyclicBarrier barrier = new CyclicBarrier(2);
            CountDownLatch stopLatch = new CountDownLatch(2);
            new Thread(() -> {
                try {
                    barrier.await();
                    pool.close();
                } catch (Exception e) {
                    exceptionCount.incrementAndGet();
                    e.printStackTrace();
                } finally {
                    stopLatch.countDown();
                }
            }).start();
            new Thread(() -> {
                try {
                    barrier.await();
                    try (TableReader reader = pool.get("xyz")) {
                        Assert.assertNotNull(reader);
                    } catch (PoolClosedException ignore) {
                    // this can also happen when this thread is delayed enough for pool close to complete
                    }
                } catch (Exception e) {
                    exceptionCount.incrementAndGet();
                    e.printStackTrace();
                } finally {
                    stopLatch.countDown();
                }
            }).start();
            Assert.assertTrue(stopLatch.await(2, TimeUnit.SECONDS));
            Assert.assertEquals(0, exceptionCount.get());
        });
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SOCountDownLatch(io.questdb.mp.SOCountDownLatch) CountDownLatch(java.util.concurrent.CountDownLatch) EntryLockedException(io.questdb.cairo.pool.ex.EntryLockedException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) PoolClosedException(io.questdb.cairo.pool.ex.PoolClosedException) CyclicBarrier(java.util.concurrent.CyclicBarrier) PoolClosedException(io.questdb.cairo.pool.ex.PoolClosedException) Test(org.junit.Test)

Example 2 with PoolClosedException

use of io.questdb.cairo.pool.ex.PoolClosedException in project questdb by bluestreak01.

the class WriterPoolTest method testGetAndCloseRace.

@Test
public void testGetAndCloseRace() throws Exception {
    try (TableModel model = new TableModel(configuration, "xyz", PartitionBy.NONE).col("ts", ColumnType.DATE)) {
        CairoTestUtils.create(model);
    }
    for (int i = 0; i < 100; i++) {
        assertWithPool(pool -> {
            AtomicInteger exceptionCount = new AtomicInteger();
            CyclicBarrier barrier = new CyclicBarrier(2);
            CountDownLatch stopLatch = new CountDownLatch(2);
            // make sure writer exists in pool
            try (TableWriter writer = pool.get("xyz", "testing")) {
                Assert.assertNotNull(writer);
            }
            new Thread(() -> {
                try {
                    barrier.await();
                    pool.close();
                } catch (Exception e) {
                    exceptionCount.incrementAndGet();
                    e.printStackTrace();
                } finally {
                    stopLatch.countDown();
                }
            }).start();
            new Thread(() -> {
                try {
                    barrier.await();
                    try (TableWriter writer = pool.get("xyz", "testing")) {
                        Assert.assertNotNull(writer);
                    } catch (PoolClosedException | EntryUnavailableException ignore) {
                    // this can also happen when this thread is delayed enough for pool close to complete
                    }
                } catch (Exception e) {
                    exceptionCount.incrementAndGet();
                    e.printStackTrace();
                } finally {
                    stopLatch.countDown();
                }
            }).start();
            Assert.assertTrue(stopLatch.await(2, TimeUnit.SECONDS));
            Assert.assertEquals(0, exceptionCount.get());
        });
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CountDownLatch(java.util.concurrent.CountDownLatch) EntryLockedException(io.questdb.cairo.pool.ex.EntryLockedException) PoolClosedException(io.questdb.cairo.pool.ex.PoolClosedException) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.junit.Test)

Aggregations

EntryLockedException (io.questdb.cairo.pool.ex.EntryLockedException)2 PoolClosedException (io.questdb.cairo.pool.ex.PoolClosedException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 CyclicBarrier (java.util.concurrent.CyclicBarrier)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Test (org.junit.Test)2 SOCountDownLatch (io.questdb.mp.SOCountDownLatch)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1