You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by er...@apache.org on 2014/09/01 23:22:47 UTC
svn commit: r1621889 - in /lucene/dev/trunk/lucene: CHANGES.txt
core/src/test/org/apache/lucene/index/TestFieldsReader.java
Author: erick
Date: Mon Sep 1 21:22:47 2014
New Revision: 1621889
URL: http://svn.apache.org/r1621889
Log:
LUCENE-5916: Static scope test components should be consistent between tests (and test iterations)
Modified:
lucene/dev/trunk/lucene/CHANGES.txt
lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java
Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1621889&r1=1621888&r2=1621889&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Mon Sep 1 21:22:47 2014
@@ -127,6 +127,10 @@ Bug Fixes
MockDirectoryWrapper to have it simulate a virus checker holding a
file open and preventing deletion (Robert Muir, Mike McCandless)
+* LUCENE-5916: Static scope test components should be consistent between
+ tests (and test iterations). Fix for FaultyIndexInput in particular.
+ (Dawid Weiss)
+
Build
* LUCENE-5909: Smoke tester now has better command line parsing and
Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java?rev=1621889&r1=1621888&r2=1621889&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java Mon Sep 1 21:22:47 2014
@@ -20,6 +20,7 @@ package org.apache.lucene.index;
import java.io.File;
import java.io.IOException;
import java.util.*;
+import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
@@ -58,9 +59,8 @@ public class TestFieldsReader extends Lu
IndexWriter writer = new IndexWriter(dir, conf);
writer.addDocument(testDoc);
writer.close();
- FaultyIndexInput.doFail = false;
}
-
+
@AfterClass
public static void afterClass() throws Exception {
dir.close();
@@ -105,77 +105,97 @@ public class TestFieldsReader extends Lu
}
- public static class FaultyFSDirectory extends BaseDirectory {
-
+ public class FaultyFSDirectory extends BaseDirectory {
Directory fsDir;
-
+ AtomicBoolean doFail = new AtomicBoolean();
+
public FaultyFSDirectory(File dir) {
fsDir = newFSDirectory(dir);
lockFactory = fsDir.getLockFactory();
}
+
@Override
public IndexInput openInput(String name, IOContext context) throws IOException {
- return new FaultyIndexInput(fsDir.openInput(name, context));
+ return new FaultyIndexInput(doFail, fsDir.openInput(name, context));
}
+
@Override
public String[] listAll() throws IOException {
return fsDir.listAll();
}
+
@Override
public void deleteFile(String name) throws IOException {
fsDir.deleteFile(name);
}
+
@Override
public long fileLength(String name) throws IOException {
return fsDir.fileLength(name);
}
+
@Override
public IndexOutput createOutput(String name, IOContext context) throws IOException {
return fsDir.createOutput(name, context);
}
+
@Override
public void sync(Collection<String> names) throws IOException {
fsDir.sync(names);
}
+
@Override
public void close() throws IOException {
fsDir.close();
}
+
+ public void startFailing() {
+ doFail.set(true);
+ }
}
- private static class FaultyIndexInput extends BufferedIndexInput {
+ private class FaultyIndexInput extends BufferedIndexInput {
+ private final AtomicBoolean doFail;
+
IndexInput delegate;
- static boolean doFail;
int count;
- private FaultyIndexInput(IndexInput delegate) {
+
+ private FaultyIndexInput(AtomicBoolean doFail, IndexInput delegate) {
super("FaultyIndexInput(" + delegate + ")", BufferedIndexInput.BUFFER_SIZE);
this.delegate = delegate;
+ this.doFail = doFail;
}
+
private void simOutage() throws IOException {
- if (doFail && count++ % 2 == 1) {
+ if (doFail.get() && count++ % 2 == 1) {
throw new IOException("Simulated network outage");
}
}
+
@Override
public void readInternal(byte[] b, int offset, int length) throws IOException {
simOutage();
delegate.seek(getFilePointer());
delegate.readBytes(b, offset, length);
}
+
@Override
public void seekInternal(long pos) throws IOException {
}
+
@Override
public long length() {
return delegate.length();
}
+
@Override
public void close() throws IOException {
delegate.close();
}
+
@Override
public FaultyIndexInput clone() {
- FaultyIndexInput i = new FaultyIndexInput(delegate.clone());
+ FaultyIndexInput i = new FaultyIndexInput(doFail, delegate.clone());
// seek the clone to our current position
try {
i.seek(getFilePointer());
@@ -188,7 +208,7 @@ public class TestFieldsReader extends Lu
@Override
public IndexInput slice(String sliceDescription, long offset, long length) throws IOException {
IndexInput slice = delegate.slice(sliceDescription, offset, length);
- return new FaultyIndexInput(slice);
+ return new FaultyIndexInput(doFail, slice);
}
}
@@ -197,7 +217,7 @@ public class TestFieldsReader extends Lu
File indexDir = createTempDir("testfieldswriterexceptions");
try {
- Directory dir = new FaultyFSDirectory(indexDir);
+ FaultyFSDirectory dir = new FaultyFSDirectory(indexDir);
IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()))
.setOpenMode(OpenMode.CREATE);
IndexWriter writer = new IndexWriter(dir, iwc);
@@ -207,8 +227,7 @@ public class TestFieldsReader extends Lu
writer.close();
IndexReader reader = DirectoryReader.open(dir);
-
- FaultyIndexInput.doFail = true;
+ dir.startFailing();
boolean exc = false;