GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — TransactionTest: use noReaderThreadLocals to fix unbounded threads tests · hehuelet/objectbox-java@b76c39b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • tests/objectbox-java-test/src/test/java/io/objectbox
    • TransactionTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: tests/objectbox-java-test/src/test/java/io/objectbox/TransactionTest.java
+14-3Lines 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 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.