LUCENE-8673: Avoid OOMEs because of IOContext randomization.

This commit is contained in:
Adrien Grand 2020-01-06 14:43:13 +01:00
parent ac777a5352
commit b6f31835ad
1 changed files with 10 additions and 11 deletions

View File

@ -1332,7 +1332,7 @@ public abstract class LuceneTestCase extends Assert {
* See {@link #newDirectory()} for more information. * See {@link #newDirectory()} for more information.
*/ */
public static BaseDirectoryWrapper newDirectory(Random r) { public static BaseDirectoryWrapper newDirectory(Random r) {
return wrapDirectory(r, newDirectoryImpl(r, TEST_DIRECTORY), rarely(r)); return wrapDirectory(r, newDirectoryImpl(r, TEST_DIRECTORY), rarely(r), false);
} }
/** /**
@ -1340,7 +1340,7 @@ public abstract class LuceneTestCase extends Assert {
* See {@link #newDirectory()} for more information. * See {@link #newDirectory()} for more information.
*/ */
public static BaseDirectoryWrapper newDirectory(Random r, LockFactory lf) { public static BaseDirectoryWrapper newDirectory(Random r, LockFactory lf) {
return wrapDirectory(r, newDirectoryImpl(r, TEST_DIRECTORY, lf), rarely(r)); return wrapDirectory(r, newDirectoryImpl(r, TEST_DIRECTORY, lf), rarely(r), false);
} }
public static MockDirectoryWrapper newMockDirectory() { public static MockDirectoryWrapper newMockDirectory() {
@ -1348,11 +1348,11 @@ public abstract class LuceneTestCase extends Assert {
} }
public static MockDirectoryWrapper newMockDirectory(Random r) { public static MockDirectoryWrapper newMockDirectory(Random r) {
return (MockDirectoryWrapper) wrapDirectory(r, newDirectoryImpl(r, TEST_DIRECTORY), false); return (MockDirectoryWrapper) wrapDirectory(r, newDirectoryImpl(r, TEST_DIRECTORY), false, false);
} }
public static MockDirectoryWrapper newMockDirectory(Random r, LockFactory lf) { public static MockDirectoryWrapper newMockDirectory(Random r, LockFactory lf) {
return (MockDirectoryWrapper) wrapDirectory(r, newDirectoryImpl(r, TEST_DIRECTORY, lf), false); return (MockDirectoryWrapper) wrapDirectory(r, newDirectoryImpl(r, TEST_DIRECTORY, lf), false, false);
} }
public static MockDirectoryWrapper newMockFSDirectory(Path f) { public static MockDirectoryWrapper newMockFSDirectory(Path f) {
@ -1416,10 +1416,7 @@ public abstract class LuceneTestCase extends Assert {
} }
Directory fsdir = newFSDirectoryImpl(clazz, f, lf); Directory fsdir = newFSDirectoryImpl(clazz, f, lf);
if (rarely()) { BaseDirectoryWrapper wrapped = wrapDirectory(random(), fsdir, bare, true);
}
BaseDirectoryWrapper wrapped = wrapDirectory(random(), fsdir, bare);
return wrapped; return wrapped;
} catch (Exception e) { } catch (Exception e) {
Rethrow.rethrow(e); Rethrow.rethrow(e);
@ -1447,11 +1444,13 @@ public abstract class LuceneTestCase extends Assert {
impl.copyFrom(d, file, file, newIOContext(r)); impl.copyFrom(d, file, file, newIOContext(r));
} }
} }
return wrapDirectory(r, impl, rarely(r)); return wrapDirectory(r, impl, rarely(r), false);
} }
private static BaseDirectoryWrapper wrapDirectory(Random random, Directory directory, boolean bare) { private static BaseDirectoryWrapper wrapDirectory(Random random, Directory directory, boolean bare, boolean filesystem) {
if (rarely(random) && !bare) { // IOContext randomization might make NRTCachingDirectory make bad decisions, so avoid
// using it if the user requested a filesystem directory.
if (rarely(random) && !bare && filesystem == false) {
directory = new NRTCachingDirectory(directory, random.nextDouble(), random.nextDouble()); directory = new NRTCachingDirectory(directory, random.nextDouble(), random.nextDouble());
} }