Fix issues with BP tests and the security manager. (#12568)

The default ForkJoinPool implementation uses a thread factory that removes all
permissions on threads, so we need to create our own to avoid tests failing
with FS-based directories.
This commit is contained in:
Adrien Grand 2023-09-19 08:55:48 +02:00 committed by GitHub
parent ebfbc831ab
commit 36432fa672
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -74,7 +74,9 @@ import org.apache.lucene.util.OfflineSorter.BufferSize;
*
* Directory targetDir = FSDirectory.open(targetPath);
* BPIndexReorderer reorderer = new BPIndexReorderer();
* reorderer.setForkJoinPool(ForkJoinPool.commonPool());
* ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(),
* p -> new ForkJoinWorkerThread(p) {}, null, random().nextBoolean());
* reorderer.setForkJoinPool(pool);
* reorderer.setFields(Collections.singleton("body"));
* CodecReader reorderedReaderView = reorderer.reorder(SlowCodecReaderWrapper.wrap(reader), targetDir);
* try (IndexWriter w = new IndexWriter(targetDir, new IndexWriterConfig().setOpenMode(OpenMode.CREATE))) {

View File

@ -21,6 +21,7 @@ import static org.apache.lucene.misc.index.BPIndexReorderer.fastLog2;
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinWorkerThread;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.document.StoredField;
@ -47,7 +48,11 @@ public class TestBPIndexReorderer extends LuceneTestCase {
public void testSingleTermWithForkJoinPool() throws IOException {
int concurrency = TestUtil.nextInt(random(), 1, 8);
ForkJoinPool pool = new ForkJoinPool(concurrency);
// The default ForkJoinPool implementation uses a thread factory that removes all permissions on
// threads, so we need to create our own to avoid tests failing with FS-based directories.
ForkJoinPool pool =
new ForkJoinPool(
concurrency, p -> new ForkJoinWorkerThread(p) {}, null, random().nextBoolean());
try {
doTestSingleTerm(pool);
} finally {