1919import io .objectbox .exception .DbException ;
2020import io .objectbox .exception .DbExceptionListener ;
2121import io .objectbox .exception .DbMaxReadersExceededException ;
22- import io .objectbox .internal .ObjectBoxThreadPool ;
2322import org .junit .Ignore ;
2423import org .junit .Test ;
2524
2625import java .util .ArrayList ;
2726import java .util .concurrent .Callable ;
2827import java .util .concurrent .CountDownLatch ;
2928import java .util .concurrent .ExecutorService ;
29+ import java .util .concurrent .Executors ;
3030import java .util .concurrent .Future ;
3131import java .util .concurrent .LinkedBlockingQueue ;
3232import java .util .concurrent .TimeUnit ;
@@ -447,6 +447,16 @@ public void testCallInTxAsync_Error() throws InterruptedException {
447447 assertNotNull (result );
448448 }
449449
450+ @ Test
451+ public void transaction_unboundedThreadPool () throws Exception {
452+ runThreadPoolReaderTest (
453+ () -> {
454+ Transaction tx = store .beginReadTx ();
455+ tx .close ();
456+ }
457+ );
458+ }
459+
450460 @ Test
451461 public void runInReadTx_unboundedThreadPool () throws Exception {
452462 runThreadPoolReaderTest (
@@ -483,10 +493,11 @@ private void runThreadPoolReaderTest(Runnable runnable) throws Exception {
483493 store = createBoxStoreBuilder (null )
484494 .maxReaders (100 )
485495 .debugFlags (0 )
496+ .noReaderThreadLocals () // This is the essential flag to make this test work
486497 .build ();
487498
488499 // Unbounded thread pool so number of threads run exceeds max readers.
489- ExecutorService pool = new ObjectBoxThreadPool ( store );
500+ ExecutorService pool = Executors . newCachedThreadPool ( );
490501
491502 ArrayList <Future <Integer >> txTasks = new ArrayList <>(10000 );
492503 final Object lock = new Object ();
@@ -503,7 +514,7 @@ private void runThreadPoolReaderTest(Runnable runnable) throws Exception {
503514
504515 //Iterate through all the txTasks and make sure all transactions succeeded.
505516 for (Future <Integer > txTask : txTasks ) {
506- txTask .get (1 , TimeUnit .SECONDS );
517+ txTask .get (1 , TimeUnit .MINUTES ); // 1s would be enough for normally, but use 1 min to allow debug sessions
507518 }
508519 }
509520}
0 commit comments