Skip to content

Commit b76c39b

Browse files
committed
TransactionTest: use noReaderThreadLocals to fix unbounded threads tests
1 parent 8fd8a8c commit b76c39b

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

tests/objectbox-java-test/src/test/java/io/objectbox/TransactionTest.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
import io.objectbox.exception.DbException;
2020
import io.objectbox.exception.DbExceptionListener;
2121
import io.objectbox.exception.DbMaxReadersExceededException;
22-
import io.objectbox.internal.ObjectBoxThreadPool;
2322
import org.junit.Ignore;
2423
import org.junit.Test;
2524

2625
import java.util.ArrayList;
2726
import java.util.concurrent.Callable;
2827
import java.util.concurrent.CountDownLatch;
2928
import java.util.concurrent.ExecutorService;
29+
import java.util.concurrent.Executors;
3030
import java.util.concurrent.Future;
3131
import java.util.concurrent.LinkedBlockingQueue;
3232
import 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

Comments
 (0)