mirror of https://github.com/apache/lucene.git
LUCENE-9110: Backport refactored stack analysis in tests to use generalized LuceneTestCase methods
This commit is contained in:
parent
8f5f18041a
commit
a6a220c89a
|
@ -23,6 +23,9 @@ Improvements
|
||||||
* LUCENE-9109: Backport some changes from master (except StackWalker) to improve
|
* LUCENE-9109: Backport some changes from master (except StackWalker) to improve
|
||||||
TestSecurityManager (Uwe Schindler)
|
TestSecurityManager (Uwe Schindler)
|
||||||
|
|
||||||
|
* LUCENE-9110: Backport refactored stack analysis in tests to use generalized
|
||||||
|
LuceneTestCase methods (Uwe Schindler)
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
---------------------
|
---------------------
|
||||||
(No changes)
|
(No changes)
|
||||||
|
|
|
@ -89,18 +89,15 @@ public class TestMergeSchedulerExternal extends LuceneTestCase {
|
||||||
private static class FailOnlyOnMerge extends MockDirectoryWrapper.Failure {
|
private static class FailOnlyOnMerge extends MockDirectoryWrapper.Failure {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
StackTraceElement[] trace = new Exception().getStackTrace();
|
if (callStackContainsAnyOf("doMerge")) {
|
||||||
for (int i = 0; i < trace.length; i++) {
|
IOException ioe = new IOException("now failing during merge");
|
||||||
if ("doMerge".equals(trace[i].getMethodName())) {
|
StringWriter sw = new StringWriter();
|
||||||
IOException ioe = new IOException("now failing during merge");
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
StringWriter sw = new StringWriter();
|
ioe.printStackTrace(pw);
|
||||||
PrintWriter pw = new PrintWriter(sw);
|
if (infoStream.isEnabled("IW")) {
|
||||||
ioe.printStackTrace(pw);
|
infoStream.message("IW", "TEST: now throw exc:\n" + sw.toString());
|
||||||
if (infoStream.isEnabled("IW")) {
|
|
||||||
infoStream.message("IW", "TEST: now throw exc:\n" + sw.toString());
|
|
||||||
}
|
|
||||||
throw ioe;
|
|
||||||
}
|
}
|
||||||
|
throw ioe;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,21 +54,7 @@ public class TestConcurrentMergeScheduler extends LuceneTestCase {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
if (doFail && isTestThread()) {
|
if (doFail && isTestThread()) {
|
||||||
boolean isDoFlush = false;
|
if (callStackContainsAnyOf("flush") && false == callStackContainsAnyOf("close") && random().nextBoolean()) {
|
||||||
boolean isClose = false;
|
|
||||||
StackTraceElement[] trace = new Exception().getStackTrace();
|
|
||||||
for (int i = 0; i < trace.length; i++) {
|
|
||||||
if (isDoFlush && isClose) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if ("flush".equals(trace[i].getMethodName())) {
|
|
||||||
isDoFlush = true;
|
|
||||||
}
|
|
||||||
if ("close".equals(trace[i].getMethodName())) {
|
|
||||||
isClose = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isDoFlush && !isClose && random().nextBoolean()) {
|
|
||||||
hitExc = true;
|
hitExc = true;
|
||||||
throw new IOException(Thread.currentThread().getName() + ": now failing during flush");
|
throw new IOException(Thread.currentThread().getName() + ": now failing during flush");
|
||||||
}
|
}
|
||||||
|
|
|
@ -659,16 +659,13 @@ public class TestDirectoryReaderReopen extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
//System.out.println("failOn: ");
|
//System.out.println("failOn: ");
|
||||||
//new Throwable().printStackTrace(System.out);
|
//new Throwable().printStackTrace(System.out);
|
||||||
StackTraceElement[] trace = new Exception().getStackTrace();
|
if (callStackContainsAnyOf("readLiveDocs")) {
|
||||||
for (int i = 0; i < trace.length; i++) {
|
if (VERBOSE) {
|
||||||
if ("readLiveDocs".equals(trace[i].getMethodName())) {
|
System.out.println("TEST: now fail; exc:");
|
||||||
if (VERBOSE) {
|
new Throwable().printStackTrace(System.out);
|
||||||
System.out.println("TEST: now fail; exc:");
|
|
||||||
new Throwable().printStackTrace(System.out);
|
|
||||||
}
|
|
||||||
failed = true;
|
|
||||||
throw new FakeIOException();
|
|
||||||
}
|
}
|
||||||
|
failed = true;
|
||||||
|
throw new FakeIOException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -414,12 +414,8 @@ public class TestIndexFileDeleter extends LuceneTestCase {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
if (doFailExc.get() && random().nextInt(4) == 1) {
|
if (doFailExc.get() && random().nextInt(4) == 1) {
|
||||||
Exception e = new Exception();
|
if (callStackContains(IndexFileDeleter.class, "decRef")) {
|
||||||
StackTraceElement stack[] = e.getStackTrace();
|
throw new RuntimeException("fake fail");
|
||||||
for (int i = 0; i < stack.length; i++) {
|
|
||||||
if (stack[i].getClassName().equals(IndexFileDeleter.class.getName()) && stack[i].getMethodName().equals("decRef")) {
|
|
||||||
throw new RuntimeException("fake fail");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -497,12 +493,8 @@ public class TestIndexFileDeleter extends LuceneTestCase {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
if (doFailExc.get() && random().nextInt(4) == 1) {
|
if (doFailExc.get() && random().nextInt(4) == 1) {
|
||||||
Exception e = new Exception();
|
if (callStackContains(MockDirectoryWrapper.class, "deleteFile")) {
|
||||||
StackTraceElement stack[] = e.getStackTrace();
|
throw new MockDirectoryWrapper.FakeIOException();
|
||||||
for (int i = 0; i < stack.length; i++) {
|
|
||||||
if (stack[i].getClassName().equals(MockDirectoryWrapper.class.getName()) && stack[i].getMethodName().equals("deleteFile")) {
|
|
||||||
throw new MockDirectoryWrapper.FakeIOException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3048,13 +3048,8 @@ public class TestIndexWriter extends LuceneTestCase {
|
||||||
dir.failOn(new MockDirectoryWrapper.Failure() {
|
dir.failOn(new MockDirectoryWrapper.Failure() {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
StackTraceElement[] trace = new Exception().getStackTrace();
|
if (callStackContains(DocumentsWriterPerThread.class, "flush")) {
|
||||||
for (int i = 0; i < trace.length; i++) {
|
flushingThreads.add(Thread.currentThread().getName());
|
||||||
if ("flush".equals(trace[i].getMethodName())
|
|
||||||
&& "org.apache.lucene.index.DocumentsWriterPerThread".equals(trace[i].getClassName())) {
|
|
||||||
flushingThreads.add(Thread.currentThread().getName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -3384,15 +3379,12 @@ public class TestIndexWriter extends LuceneTestCase {
|
||||||
try (Directory dir = new FilterDirectory(newDirectory()) {
|
try (Directory dir = new FilterDirectory(newDirectory()) {
|
||||||
@Override
|
@Override
|
||||||
public IndexOutput createOutput(String name, IOContext context) throws IOException {
|
public IndexOutput createOutput(String name, IOContext context) throws IOException {
|
||||||
StackTraceElement[] trace = new Exception().getStackTrace();
|
if (callStackContains(DefaultIndexingChain.class, "flush")) {
|
||||||
for (int i = 0; i < trace.length; i++) {
|
try {
|
||||||
if ("flush".equals(trace[i].getMethodName()) && DefaultIndexingChain.class.getName().equals(trace[i].getClassName())) {
|
inFlush.countDown();
|
||||||
try {
|
latch.await();
|
||||||
inFlush.countDown();
|
} catch (InterruptedException e) {
|
||||||
latch.await();
|
throw new AssertionError(e);
|
||||||
} catch (InterruptedException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.createOutput(name, context);
|
return super.createOutput(name, context);
|
||||||
|
|
|
@ -731,15 +731,7 @@ public class TestIndexWriterDelete extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
new Throwable().printStackTrace(System.out);
|
new Throwable().printStackTrace(System.out);
|
||||||
if (sawMaybe && !failed) {
|
if (sawMaybe && !failed) {
|
||||||
boolean seen = false;
|
boolean seen = callStackContainsAnyOf("applyDeletesAndUpdates", "slowFileExists");
|
||||||
StackTraceElement[] trace = new Exception().getStackTrace();
|
|
||||||
for (int i = 0; i < trace.length; i++) {
|
|
||||||
if ("applyDeletesAndUpdates".equals(trace[i].getMethodName()) ||
|
|
||||||
"slowFileExists".equals(trace[i].getMethodName())) {
|
|
||||||
seen = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!seen) {
|
if (!seen) {
|
||||||
// Only fail once we are no longer in applyDeletes
|
// Only fail once we are no longer in applyDeletes
|
||||||
failed = true;
|
failed = true;
|
||||||
|
@ -751,16 +743,12 @@ public class TestIndexWriterDelete extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!failed) {
|
if (!failed) {
|
||||||
StackTraceElement[] trace = new Exception().getStackTrace();
|
if (callStackContainsAnyOf("applyDeletesAndUpdates")) {
|
||||||
for (int i = 0; i < trace.length; i++) {
|
if (VERBOSE) {
|
||||||
if ("applyDeletesAndUpdates".equals(trace[i].getMethodName())) {
|
System.out.println("TEST: mock failure: saw applyDeletes");
|
||||||
if (VERBOSE) {
|
new Throwable().printStackTrace(System.out);
|
||||||
System.out.println("TEST: mock failure: saw applyDeletes");
|
|
||||||
new Throwable().printStackTrace(System.out);
|
|
||||||
}
|
|
||||||
sawMaybe = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
sawMaybe = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -566,19 +566,7 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
if (doFail) {
|
if (doFail) {
|
||||||
StackTraceElement[] trace = new Exception().getStackTrace();
|
if (callStackContainsAnyOf("flush") && false == callStackContainsAnyOf("finishDocument") && count++ >= 30) {
|
||||||
boolean sawFlush = false;
|
|
||||||
boolean sawFinishDocument = false;
|
|
||||||
for (int i = 0; i < trace.length; i++) {
|
|
||||||
if ("flush".equals(trace[i].getMethodName())) {
|
|
||||||
sawFlush = true;
|
|
||||||
}
|
|
||||||
if ("finishDocument".equals(trace[i].getMethodName())) {
|
|
||||||
sawFinishDocument = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sawFlush && sawFinishDocument == false && count++ >= 30) {
|
|
||||||
doFail = false;
|
doFail = false;
|
||||||
throw new IOException("now failing during flush");
|
throw new IOException("now failing during flush");
|
||||||
}
|
}
|
||||||
|
@ -871,16 +859,14 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
if (doFail) {
|
if (doFail) {
|
||||||
StackTraceElement[] trace = new Exception().getStackTrace();
|
if (callStackContains(MockDirectoryWrapper.class, "sync")) {
|
||||||
for (int i = 0; i < trace.length; i++) {
|
didFail = true;
|
||||||
if (doFail && MockDirectoryWrapper.class.getName().equals(trace[i].getClassName()) && "sync".equals(trace[i].getMethodName())) {
|
if (VERBOSE) {
|
||||||
didFail = true;
|
System.out.println("TEST: now throw exc:");
|
||||||
if (VERBOSE) {
|
new Throwable().printStackTrace(System.out);
|
||||||
System.out.println("TEST: now throw exc:");
|
|
||||||
new Throwable().printStackTrace(System.out);
|
|
||||||
}
|
|
||||||
throw new IOException("now failing on purpose during sync");
|
|
||||||
}
|
}
|
||||||
|
throw new IOException("now failing on purpose during sync");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -948,28 +934,10 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
StackTraceElement[] trace = new Exception().getStackTrace();
|
boolean isCommit = callStackContains(SegmentInfos.class, stage);
|
||||||
boolean isCommit = false;
|
boolean isDelete = callStackContains(MockDirectoryWrapper.class, "deleteFile");
|
||||||
boolean isDelete = false;
|
boolean isSyncMetadata = callStackContains(MockDirectoryWrapper.class, "syncMetaData");
|
||||||
boolean isSyncMetadata = false;
|
boolean isInGlobalFieldMap = callStackContains(SegmentInfos.class, "writeGlobalFieldMap");
|
||||||
boolean isInGlobalFieldMap = false;
|
|
||||||
for (int i = 0; i < trace.length; i++) {
|
|
||||||
if (isCommit && isDelete && isInGlobalFieldMap && isSyncMetadata) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (SegmentInfos.class.getName().equals(trace[i].getClassName()) && stage.equals(trace[i].getMethodName())) {
|
|
||||||
isCommit = true;
|
|
||||||
}
|
|
||||||
if (MockDirectoryWrapper.class.getName().equals(trace[i].getClassName()) && "deleteFile".equals(trace[i].getMethodName())) {
|
|
||||||
isDelete = true;
|
|
||||||
}
|
|
||||||
if (SegmentInfos.class.getName().equals(trace[i].getClassName()) && "writeGlobalFieldMap".equals(trace[i].getMethodName())) {
|
|
||||||
isInGlobalFieldMap = true;
|
|
||||||
}
|
|
||||||
if (MockDirectoryWrapper.class.getName().equals(trace[i].getClassName()) && "syncMetaData".equals(trace[i].getMethodName())) {
|
|
||||||
isSyncMetadata = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isInGlobalFieldMap && dontFailDuringGlobalFieldMap) {
|
if (isInGlobalFieldMap && dontFailDuringGlobalFieldMap) {
|
||||||
isCommit = false;
|
isCommit = false;
|
||||||
}
|
}
|
||||||
|
@ -1383,17 +1351,7 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
|
if (callStackContains(TermVectorsConsumer.class, stage)) {
|
||||||
StackTraceElement[] trace = new Exception().getStackTrace();
|
|
||||||
boolean fail = false;
|
|
||||||
for (int i = 0; i < trace.length; i++) {
|
|
||||||
if (TermVectorsConsumer.class.getName().equals(trace[i].getClassName()) && stage.equals(trace[i].getMethodName())) {
|
|
||||||
fail = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fail) {
|
|
||||||
throw new RuntimeException(EXC_MSG);
|
throw new RuntimeException(EXC_MSG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1719,11 +1677,8 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
|
||||||
@Override
|
@Override
|
||||||
public IndexInput openInput(String name, IOContext context) throws IOException {
|
public IndexInput openInput(String name, IOContext context) throws IOException {
|
||||||
if (doFail && name.startsWith("segments_")) {
|
if (doFail && name.startsWith("segments_")) {
|
||||||
StackTraceElement[] trace = new Exception().getStackTrace();
|
if (callStackContainsAnyOf("readCommit", "readLatestCommit")) {
|
||||||
for (int i = 0; i < trace.length; i++) {
|
throw new UnsupportedOperationException("expected UOE");
|
||||||
if ("readCommit".equals(trace[i].getMethodName()) || "readLatestCommit".equals(trace[i].getMethodName())) {
|
|
||||||
throw new UnsupportedOperationException("expected UOE");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.openInput(name, context);
|
return super.openInput(name, context);
|
||||||
|
@ -1939,17 +1894,7 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
|
||||||
if (random().nextInt(10) != 0) {
|
if (random().nextInt(10) != 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean maybeFail = false;
|
if (callStackContainsAnyOf("rollbackInternal")) {
|
||||||
StackTraceElement[] trace = Thread.currentThread().getStackTrace();
|
|
||||||
|
|
||||||
for (int i = 0; i < trace.length; i++) {
|
|
||||||
if ("rollbackInternal".equals(trace[i].getMethodName())) {
|
|
||||||
maybeFail = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (maybeFail) {
|
|
||||||
if (VERBOSE) {
|
if (VERBOSE) {
|
||||||
System.out.println("TEST: now fail; thread=" + Thread.currentThread().getName() + " exc:");
|
System.out.println("TEST: now fail; thread=" + Thread.currentThread().getName() + " exc:");
|
||||||
new Throwable().printStackTrace(System.out);
|
new Throwable().printStackTrace(System.out);
|
||||||
|
@ -2012,17 +1957,14 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
|
||||||
// Already failed
|
// Already failed
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
StackTraceElement[] trace = Thread.currentThread().getStackTrace();
|
|
||||||
|
if (callStackContainsAnyOf("merge")) {
|
||||||
for (int i = 0; i < trace.length; i++) {
|
if (VERBOSE) {
|
||||||
if ("merge".equals(trace[i].getMethodName())) {
|
System.out.println("TEST: now fail; thread=" + Thread.currentThread().getName() + " exc:");
|
||||||
if (VERBOSE) {
|
new Throwable().printStackTrace(System.out);
|
||||||
System.out.println("TEST: now fail; thread=" + Thread.currentThread().getName() + " exc:");
|
|
||||||
new Throwable().printStackTrace(System.out);
|
|
||||||
}
|
|
||||||
didFail.set(true);
|
|
||||||
throw new FakeIOException();
|
|
||||||
}
|
}
|
||||||
|
didFail.set(true);
|
||||||
|
throw new FakeIOException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,7 +18,6 @@ package org.apache.lucene.index;
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.MockAnalyzer;
|
import org.apache.lucene.analysis.MockAnalyzer;
|
||||||
import org.apache.lucene.codecs.LiveDocsFormat;
|
import org.apache.lucene.codecs.LiveDocsFormat;
|
||||||
import org.apache.lucene.document.Document;
|
import org.apache.lucene.document.Document;
|
||||||
|
@ -478,16 +477,13 @@ public class TestIndexWriterOnDiskFull extends LuceneTestCase {
|
||||||
if (!doFail) {
|
if (!doFail) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
StackTraceElement[] trace = new Exception().getStackTrace();
|
if (callStackContains(SegmentMerger.class, "mergeTerms") && !didFail1) {
|
||||||
for (int i = 0; i < trace.length; i++) {
|
didFail1 = true;
|
||||||
if (SegmentMerger.class.getName().equals(trace[i].getClassName()) && "mergeTerms".equals(trace[i].getMethodName()) && !didFail1) {
|
throw new IOException("fake disk full during mergeTerms");
|
||||||
didFail1 = true;
|
}
|
||||||
throw new IOException("fake disk full during mergeTerms");
|
if (callStackContains(LiveDocsFormat.class, "writeLiveDocs") && !didFail2) {
|
||||||
}
|
didFail2 = true;
|
||||||
if (LiveDocsFormat.class.getName().equals(trace[i].getClassName()) && "writeLiveDocs".equals(trace[i].getMethodName()) && !didFail2) {
|
throw new IOException("fake disk full while writing LiveDocs");
|
||||||
didFail2 = true;
|
|
||||||
throw new IOException("fake disk full while writing LiveDocs");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,14 +238,7 @@ public class TestIndexWriterOnVMError extends LuceneTestCase {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
if (r.nextInt(3000) == 0) {
|
if (r.nextInt(3000) == 0) {
|
||||||
StackTraceElement stack[] = Thread.currentThread().getStackTrace();
|
if (callStackContains(IndexWriter.class)) {
|
||||||
boolean ok = false;
|
|
||||||
for (int i = 0; i < stack.length; i++) {
|
|
||||||
if (stack[i].getClassName().equals(IndexWriter.class.getName())) {
|
|
||||||
ok = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ok) {
|
|
||||||
throw new OutOfMemoryError("Fake OutOfMemoryError");
|
throw new OutOfMemoryError("Fake OutOfMemoryError");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,14 +252,7 @@ public class TestIndexWriterOnVMError extends LuceneTestCase {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
if (r.nextInt(3000) == 0) {
|
if (r.nextInt(3000) == 0) {
|
||||||
StackTraceElement stack[] = Thread.currentThread().getStackTrace();
|
if (callStackContains(IndexWriter.class)) {
|
||||||
boolean ok = false;
|
|
||||||
for (int i = 0; i < stack.length; i++) {
|
|
||||||
if (stack[i].getClassName().equals(IndexWriter.class.getName())) {
|
|
||||||
ok = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ok) {
|
|
||||||
throw new UnknownError("Fake UnknownError");
|
throw new UnknownError("Fake UnknownError");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -281,16 +267,11 @@ public class TestIndexWriterOnVMError extends LuceneTestCase {
|
||||||
doTest(new Failure() {
|
doTest(new Failure() {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
StackTraceElement stack[] = Thread.currentThread().getStackTrace();
|
if (r.nextInt(4) == 0) {
|
||||||
boolean ok = false;
|
if (callStackContains(IndexFileDeleter.class, "checkpoint")) {
|
||||||
for (int i = 0; i < stack.length; i++) {
|
throw new OutOfMemoryError("Fake OutOfMemoryError");
|
||||||
if (stack[i].getClassName().equals(IndexFileDeleter.class.getName()) && stack[i].getMethodName().equals("checkpoint")) {
|
|
||||||
ok = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ok && r.nextInt(4) == 0) {
|
|
||||||
throw new OutOfMemoryError("Fake OutOfMemoryError");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1067,17 +1067,14 @@ public class TestIndexWriterReader extends LuceneTestCase {
|
||||||
dir.failOn(new MockDirectoryWrapper.Failure() {
|
dir.failOn(new MockDirectoryWrapper.Failure() {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
StackTraceElement[] trace = new Exception().getStackTrace();
|
|
||||||
if (shouldFail.get()) {
|
if (shouldFail.get()) {
|
||||||
for (int i = 0; i < trace.length; i++) {
|
if (callStackContainsAnyOf("getReadOnlyClone")) {
|
||||||
if ("getReadOnlyClone".equals(trace[i].getMethodName())) {
|
if (VERBOSE) {
|
||||||
if (VERBOSE) {
|
System.out.println("TEST: now fail; exc:");
|
||||||
System.out.println("TEST: now fail; exc:");
|
new Throwable().printStackTrace(System.out);
|
||||||
new Throwable().printStackTrace(System.out);
|
|
||||||
}
|
|
||||||
shouldFail.set(false);
|
|
||||||
throw new FakeIOException();
|
|
||||||
}
|
}
|
||||||
|
shouldFail.set(false);
|
||||||
|
throw new FakeIOException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -407,26 +407,7 @@ public class TestIndexWriterWithThreads extends LuceneTestCase {
|
||||||
dir.setAssertNoUnrefencedFilesOnClose(false);
|
dir.setAssertNoUnrefencedFilesOnClose(false);
|
||||||
|
|
||||||
if (doFail) {
|
if (doFail) {
|
||||||
StackTraceElement[] trace = new Exception().getStackTrace();
|
if (callStackContainsAnyOf("abort", "finishDocument") && false == callStackContainsAnyOf("merge", "close")) {
|
||||||
boolean sawAbortOrFlushDoc = false;
|
|
||||||
boolean sawClose = false;
|
|
||||||
boolean sawMerge = false;
|
|
||||||
for (int i = 0; i < trace.length; i++) {
|
|
||||||
if (sawAbortOrFlushDoc && sawMerge && sawClose) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if ("abort".equals(trace[i].getMethodName()) ||
|
|
||||||
"finishDocument".equals(trace[i].getMethodName())) {
|
|
||||||
sawAbortOrFlushDoc = true;
|
|
||||||
}
|
|
||||||
if ("merge".equals(trace[i].getMethodName())) {
|
|
||||||
sawMerge = true;
|
|
||||||
}
|
|
||||||
if ("close".equals(trace[i].getMethodName())) {
|
|
||||||
sawClose = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (sawAbortOrFlushDoc && !sawClose && !sawMerge) {
|
|
||||||
if (onlyOnce) {
|
if (onlyOnce) {
|
||||||
doFail = false;
|
doFail = false;
|
||||||
}
|
}
|
||||||
|
@ -473,15 +454,12 @@ public class TestIndexWriterWithThreads extends LuceneTestCase {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
if (doFail) {
|
if (doFail) {
|
||||||
StackTraceElement[] trace = new Exception().getStackTrace();
|
if (callStackContains(DefaultIndexingChain.class, "flush")) {
|
||||||
for (int i = 0; i < trace.length; i++) {
|
if (onlyOnce)
|
||||||
if ("flush".equals(trace[i].getMethodName()) && DefaultIndexingChain.class.getName().equals(trace[i].getClassName())) {
|
doFail = false;
|
||||||
if (onlyOnce)
|
//System.out.println(Thread.currentThread().getName() + ": NOW FAIL: onlyOnce=" + onlyOnce);
|
||||||
doFail = false;
|
//new Throwable().printStackTrace(System.out);
|
||||||
//System.out.println(Thread.currentThread().getName() + ": NOW FAIL: onlyOnce=" + onlyOnce);
|
throw new IOException("now failing on purpose");
|
||||||
//new Throwable().printStackTrace(System.out);
|
|
||||||
throw new IOException("now failing on purpose");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,11 +116,8 @@ public class TestPersistentSnapshotDeletionPolicy extends TestSnapshotDeletionPo
|
||||||
dir.failOn(new MockDirectoryWrapper.Failure() {
|
dir.failOn(new MockDirectoryWrapper.Failure() {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
StackTraceElement[] trace = Thread.currentThread().getStackTrace();
|
if (callStackContains(PersistentSnapshotDeletionPolicy.class, "persist")) {
|
||||||
for (int i = 0; i < trace.length; i++) {
|
throw new IOException("now fail on purpose");
|
||||||
if (PersistentSnapshotDeletionPolicy.class.getName().equals(trace[i].getClassName()) && "persist".equals(trace[i].getMethodName())) {
|
|
||||||
throw new IOException("now fail on purpose");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -133,8 +133,8 @@ public class TestUnifiedHighlighterTermVec extends LuceneTestCase {
|
||||||
@Override
|
@Override
|
||||||
public Fields getTermVectors(int docID) throws IOException {
|
public Fields getTermVectors(int docID) throws IOException {
|
||||||
// if we're invoked by ParallelLeafReader then we can't do our assertion. TODO see LUCENE-6868
|
// if we're invoked by ParallelLeafReader then we can't do our assertion. TODO see LUCENE-6868
|
||||||
if (calledBy(ParallelLeafReader.class) == false
|
if (callStackContains(ParallelLeafReader.class) == false
|
||||||
&& calledBy(CheckIndex.class) == false) {
|
&& callStackContains(CheckIndex.class) == false) {
|
||||||
assertFalse("Should not request TVs for doc more than once.", seenDocIDs.get(docID));
|
assertFalse("Should not request TVs for doc more than once.", seenDocIDs.get(docID));
|
||||||
seenDocIDs.set(docID);
|
seenDocIDs.set(docID);
|
||||||
}
|
}
|
||||||
|
@ -170,14 +170,6 @@ public class TestUnifiedHighlighterTermVec extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean calledBy(Class<?> clazz) {
|
|
||||||
for (StackTraceElement stackTraceElement : Thread.currentThread().getStackTrace()) {
|
|
||||||
if (stackTraceElement.getClassName().equals(clazz.getName()))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testUserFailedToIndexOffsets() throws IOException {
|
public void testUserFailedToIndexOffsets() throws IOException {
|
||||||
FieldType fieldType = new FieldType(UHTestHelper.tvType); // note: it's indexed too
|
FieldType fieldType = new FieldType(UHTestHelper.tvType); // note: it's indexed too
|
||||||
|
|
|
@ -102,10 +102,8 @@ public abstract class BaseFieldInfoFormatTestCase extends BaseIndexFileFormatTes
|
||||||
Failure fail = new Failure() {
|
Failure fail = new Failure() {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
for (StackTraceElement e : Thread.currentThread().getStackTrace()) {
|
if (doFail && callStackContainsAnyOf("createOutput")) {
|
||||||
if (doFail && "createOutput".equals(e.getMethodName())) {
|
throw new FakeIOException();
|
||||||
throw new FakeIOException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -137,10 +135,8 @@ public abstract class BaseFieldInfoFormatTestCase extends BaseIndexFileFormatTes
|
||||||
Failure fail = new Failure() {
|
Failure fail = new Failure() {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
for (StackTraceElement e : Thread.currentThread().getStackTrace()) {
|
if (doFail && callStackContainsAnyOf("close")) {
|
||||||
if (doFail && "close".equals(e.getMethodName())) {
|
throw new FakeIOException();
|
||||||
throw new FakeIOException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -172,10 +168,8 @@ public abstract class BaseFieldInfoFormatTestCase extends BaseIndexFileFormatTes
|
||||||
Failure fail = new Failure() {
|
Failure fail = new Failure() {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
for (StackTraceElement e : Thread.currentThread().getStackTrace()) {
|
if (doFail && callStackContainsAnyOf("openInput")) {
|
||||||
if (doFail && "openInput".equals(e.getMethodName())) {
|
throw new FakeIOException();
|
||||||
throw new FakeIOException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -208,10 +202,8 @@ public abstract class BaseFieldInfoFormatTestCase extends BaseIndexFileFormatTes
|
||||||
Failure fail = new Failure() {
|
Failure fail = new Failure() {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
for (StackTraceElement e : Thread.currentThread().getStackTrace()) {
|
if (doFail && callStackContainsAnyOf("close")) {
|
||||||
if (doFail && "close".equals(e.getMethodName())) {
|
throw new FakeIOException();
|
||||||
throw new FakeIOException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -292,10 +292,8 @@ public abstract class BaseSegmentInfoFormatTestCase extends BaseIndexFileFormatT
|
||||||
Failure fail = new Failure() {
|
Failure fail = new Failure() {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
for (StackTraceElement e : Thread.currentThread().getStackTrace()) {
|
if (doFail && callStackContainsAnyOf("createOutput")) {
|
||||||
if (doFail && "createOutput".equals(e.getMethodName())) {
|
throw new FakeIOException();
|
||||||
throw new FakeIOException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -325,10 +323,8 @@ public abstract class BaseSegmentInfoFormatTestCase extends BaseIndexFileFormatT
|
||||||
Failure fail = new Failure() {
|
Failure fail = new Failure() {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
for (StackTraceElement e : Thread.currentThread().getStackTrace()) {
|
if (doFail && callStackContainsAnyOf("close")) {
|
||||||
if (doFail && "close".equals(e.getMethodName())) {
|
throw new FakeIOException();
|
||||||
throw new FakeIOException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -358,10 +354,8 @@ public abstract class BaseSegmentInfoFormatTestCase extends BaseIndexFileFormatT
|
||||||
Failure fail = new Failure() {
|
Failure fail = new Failure() {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
for (StackTraceElement e : Thread.currentThread().getStackTrace()) {
|
if (doFail && callStackContainsAnyOf("openInput")) {
|
||||||
if (doFail && "openInput".equals(e.getMethodName())) {
|
throw new FakeIOException();
|
||||||
throw new FakeIOException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -392,10 +386,8 @@ public abstract class BaseSegmentInfoFormatTestCase extends BaseIndexFileFormatT
|
||||||
Failure fail = new Failure() {
|
Failure fail = new Failure() {
|
||||||
@Override
|
@Override
|
||||||
public void eval(MockDirectoryWrapper dir) throws IOException {
|
public void eval(MockDirectoryWrapper dir) throws IOException {
|
||||||
for (StackTraceElement e : Thread.currentThread().getStackTrace()) {
|
if (doFail && callStackContainsAnyOf("close")) {
|
||||||
if (doFail && "close".equals(e.getMethodName())) {
|
throw new FakeIOException();
|
||||||
throw new FakeIOException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -66,6 +66,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
import org.apache.lucene.analysis.MockAnalyzer;
|
import org.apache.lucene.analysis.MockAnalyzer;
|
||||||
|
@ -2700,6 +2701,27 @@ public abstract class LuceneTestCase extends Assert {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Inspects stack trace to figure out if a method of a specific class called us. */
|
||||||
|
public static boolean callStackContains(Class<?> clazz, String methodName) {
|
||||||
|
final String className = clazz.getName();
|
||||||
|
return Stream.of(new Exception().getStackTrace()).skip(1) // exclude this utility method
|
||||||
|
.anyMatch(f -> className.equals(f.getClassName()) && methodName.equals(f.getMethodName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Inspects stack trace to figure out if one of the given method names (no class restriction) called us. */
|
||||||
|
public static boolean callStackContainsAnyOf(String... methodNames) {
|
||||||
|
return Stream.of(new Exception().getStackTrace()).skip(1) // exclude this utility method
|
||||||
|
.map(StackTraceElement::getMethodName)
|
||||||
|
.anyMatch(Arrays.asList(methodNames)::contains);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Inspects stack trace if the given class called us. */
|
||||||
|
public static boolean callStackContains(Class<?> clazz) {
|
||||||
|
return Stream.of(new Exception().getStackTrace()).skip(1) // exclude this utility method
|
||||||
|
.map(StackTraceElement::getClassName)
|
||||||
|
.anyMatch(clazz.getName()::equals);
|
||||||
|
}
|
||||||
|
|
||||||
/** A runnable that can throw any checked exception. */
|
/** A runnable that can throw any checked exception. */
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
|
|
Loading…
Reference in New Issue