File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
tests/objectbox-java-test/src/test/java/io/objectbox Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change 3333
3434public class TestUtils {
3535
36+ public static boolean isWindows () {
37+ final String osName = System .getProperty ("os.name" ).toLowerCase ();
38+ return osName .contains ("windows" );
39+ }
40+
3641 public static String loadFile (String filename ) {
3742 try {
3843 InputStream in = openInputStream ("/" + filename );
Original file line number Diff line number Diff line change 2929import java .util .concurrent .Executors ;
3030import java .util .concurrent .Future ;
3131import java .util .concurrent .LinkedBlockingQueue ;
32+ import java .util .concurrent .ThreadPoolExecutor ;
3233import java .util .concurrent .TimeUnit ;
3334import java .util .concurrent .atomic .AtomicInteger ;
3435
@@ -496,7 +497,8 @@ private void runThreadPoolReaderTest(Runnable runnable) throws Exception {
496497 .noReaderThreadLocals () // This is the essential flag to make this test work
497498 .build ();
498499
499- // Unbounded thread pool so number of threads run exceeds max readers.
500+ // Unbounded (but throttled) thread pool so number of threads run exceeds max readers.
501+ int numThreads = TestUtils .isWindows () ? 300 : 1000 ; // Less on Windows; had some resource issues on Windows CI
500502 ExecutorService pool = Executors .newCachedThreadPool ();
501503
502504 ArrayList <Future <Integer >> txTasks = new ArrayList <>(10000 );
@@ -510,6 +512,9 @@ private void runThreadPoolReaderTest(Runnable runnable) throws Exception {
510512 return txNumber ;
511513 }
512514 }));
515+ if (pool instanceof ThreadPoolExecutor && ((ThreadPoolExecutor ) pool ).getActiveCount () > numThreads ) {
516+ Thread .sleep (1 ); // Throttle processing to limit thread resources
517+ }
513518 }
514519
515520 //Iterate through all the txTasks and make sure all transactions succeeded.
You can’t perform that action at this time.
0 commit comments