Skip to content

Commit 88c4dcb

Browse files
Justin Breitfellergreenrobot-team
authored andcommitted
Add a test that passes that notices that if the thread pool size is <= the max readers, we will not have a MaxDbReaders error
1 parent a08b8c8 commit 88c4dcb

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.util.ArrayList;
2323
import java.util.concurrent.Callable;
2424
import java.util.concurrent.CountDownLatch;
25+
import java.util.concurrent.ExecutorService;
26+
import java.util.concurrent.Executors;
2527
import java.util.concurrent.Future;
2628
import java.util.concurrent.LinkedBlockingQueue;
2729
import java.util.concurrent.TimeUnit;
@@ -441,9 +443,34 @@ public void testCallInTxAsync_Error() throws InterruptedException {
441443
}
442444

443445
@Test
444-
public void transactionsOnLargeThreadPool() throws Exception {
446+
public void transactionsOnUnboundedThreadPool() throws Exception {
447+
//Silence the unnecessary debug output and set the max readers
448+
resetBoxStoreWithoutDebugFlags(100);
449+
450+
runThreadPoolTransactionTest(new ObjectBoxThreadPool(store));
451+
}
452+
453+
@Test
454+
public void transactionsOnBoundedThreadPool() throws Exception {
455+
//Silence the unnecessary debug output and set the max readers
456+
int maxReaders = 100;
457+
resetBoxStoreWithoutDebugFlags(maxReaders);
458+
459+
runThreadPoolTransactionTest(Executors.newFixedThreadPool(maxReaders));
460+
}
461+
462+
private void resetBoxStoreWithoutDebugFlags(int maxReaders) {
463+
// Remove existing store
464+
tearDown();
465+
466+
BoxStoreBuilder builder = createBoxStoreBuilder(false);
467+
builder.maxReaders = maxReaders;
468+
builder.debugFlags = 0;
469+
store = builder.build();
470+
}
471+
472+
private void runThreadPoolTransactionTest(ExecutorService pool) throws Exception {
445473
//Create a bunch of transactions on a thread pool. We can even run them synchronously.
446-
ObjectBoxThreadPool pool = new ObjectBoxThreadPool(store);
447474
ArrayList<Future<Integer>> txTasks = new ArrayList<>(10000);
448475
for (int i = 0; i < 10000; i++) {
449476
final int txNumber = i;

0 commit comments

Comments
 (0)