|
19 | 19 | import io.objectbox.exception.DbException; |
20 | 20 | import io.objectbox.exception.DbExceptionListener; |
21 | 21 | import io.objectbox.exception.DbMaxReadersExceededException; |
22 | | -import io.objectbox.internal.ObjectBoxThreadPool; |
23 | 22 | import org.junit.Ignore; |
24 | 23 | import org.junit.Test; |
25 | 24 |
|
26 | 25 | import java.util.ArrayList; |
27 | 26 | import java.util.concurrent.Callable; |
28 | 27 | import java.util.concurrent.CountDownLatch; |
29 | 28 | import java.util.concurrent.ExecutorService; |
| 29 | +import java.util.concurrent.Executors; |
30 | 30 | import java.util.concurrent.Future; |
31 | 31 | import java.util.concurrent.LinkedBlockingQueue; |
32 | 32 | import java.util.concurrent.TimeUnit; |
@@ -447,6 +447,16 @@ public void testCallInTxAsync_Error() throws InterruptedException { |
447 | 447 | assertNotNull(result); |
448 | 448 | } |
449 | 449 |
|
| 450 | + @Test |
| 451 | + public void transaction_unboundedThreadPool() throws Exception { |
| 452 | + runThreadPoolReaderTest( |
| 453 | + () -> { |
| 454 | + Transaction tx = store.beginReadTx(); |
| 455 | + tx.close(); |
| 456 | + } |
| 457 | + ); |
| 458 | + } |
| 459 | + |
450 | 460 | @Test |
451 | 461 | public void runInReadTx_unboundedThreadPool() throws Exception { |
452 | 462 | runThreadPoolReaderTest( |
@@ -483,10 +493,11 @@ private void runThreadPoolReaderTest(Runnable runnable) throws Exception { |
483 | 493 | store = createBoxStoreBuilder(null) |
484 | 494 | .maxReaders(100) |
485 | 495 | .debugFlags(0) |
| 496 | + .noReaderThreadLocals() // This is the essential flag to make this test work |
486 | 497 | .build(); |
487 | 498 |
|
488 | 499 | // Unbounded thread pool so number of threads run exceeds max readers. |
489 | | - ExecutorService pool = new ObjectBoxThreadPool(store); |
| 500 | + ExecutorService pool = Executors.newCachedThreadPool(); |
490 | 501 |
|
491 | 502 | ArrayList<Future<Integer>> txTasks = new ArrayList<>(10000); |
492 | 503 | final Object lock = new Object(); |
@@ -503,7 +514,7 @@ private void runThreadPoolReaderTest(Runnable runnable) throws Exception { |
503 | 514 |
|
504 | 515 | //Iterate through all the txTasks and make sure all transactions succeeded. |
505 | 516 | 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 |
507 | 518 | } |
508 | 519 | } |
509 | 520 | } |