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());
});
}
}
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());
});
}
}
Aggregations