You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2010/08/24 15:56:41 UTC
svn commit: r988543 - in /lucene/dev/trunk/lucene/src:
java/org/apache/lucene/store/ test/org/apache/lucene/index/
test/org/apache/lucene/store/ test/org/apache/lucene/util/
Author: mikemccand
Date: Tue Aug 24 13:56:41 2010
New Revision: 988543
URL: http://svn.apache.org/viewvc?rev=988543&view=rev
Log:
LUCENE-2598: more fixing tests to run with -Dtests.directory=SimpleFSDirectory
Modified:
lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/FSDirectory.java
lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java
lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java
lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockIndexOutputWrapper.java
lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/_TestUtil.java
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/FSDirectory.java?rev=988543&r1=988542&r2=988543&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/FSDirectory.java Tue Aug 24 13:56:41 2010
@@ -274,10 +274,12 @@ public abstract class FSDirectory extend
public long fileLength(String name) throws IOException {
ensureOpen();
File file = new File(directory, name);
- if (!file.exists()) {
+ final long len = file.length();
+ if (len == 0 && !file.exists()) {
throw new FileNotFoundException(name);
+ } else {
+ return len;
}
- return file.length();
}
/** Removes an existing file in the directory. */
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=988543&r1=988542&r2=988543&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java Tue Aug 24 13:56:41 2010
@@ -314,6 +314,7 @@ public class TestIndexWriter extends Luc
if (VERBOSE)
System.out.println("\ncycle: " + testName);
+ dir.setTrackDiskUsage(true);
dir.setMaxSizeInBytes(thisDiskFree);
dir.setRandomIOExceptionRate(rate, diskFree);
@@ -519,7 +520,7 @@ public class TestIndexWriter extends Luc
//_TestUtil.syncConcurrentMerges(ms);
- if (dir.listAll().length > 0) {
+ if (_TestUtil.anyFilesExceptWriteLock(dir)) {
assertNoUnreferencedFiles(dir, "after disk full during addDocument");
// Make sure reader can open the index:
@@ -661,6 +662,8 @@ public class TestIndexWriter extends Luc
}
dir.resetMaxUsedSizeInBytes();
+ dir.setTrackDiskUsage(true);
+
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer.optimize();
writer.close();
@@ -1027,6 +1030,7 @@ public class TestIndexWriter extends Luc
writer.close();
dir.resetMaxUsedSizeInBytes();
+ dir.setTrackDiskUsage(true);
long startDiskUsage = dir.getMaxUsedSizeInBytes();
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())
.setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(10).setMergeScheduler(
@@ -4377,7 +4381,6 @@ public class TestIndexWriter extends Luc
dir = newDirectory(random);
} catch (IOException e) { throw new RuntimeException(e); }
IndexWriter w = null;
- boolean first = true;
while(!finish) {
try {
@@ -4386,40 +4389,32 @@ public class TestIndexWriter extends Luc
w.close();
}
IndexWriterConfig conf = newIndexWriterConfig(random,
- TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2);
+ TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2);
((LogMergePolicy) conf.getMergePolicy()).setMergeFactor(2);
w = new IndexWriter(dir, conf);
- //((ConcurrentMergeScheduler) w.getMergeScheduler()).setSuppressExceptions();
- if (!first && !allowInterrupt) {
- // tell main thread it can interrupt us any time,
- // starting now
- allowInterrupt = true;
- }
-
Document doc = new Document();
doc.add(new Field("field", "some text contents", Field.Store.YES, Field.Index.ANALYZED));
for(int i=0;i<100;i++) {
w.addDocument(doc);
- w.commit();
+ if (i%10 == 0) {
+ w.commit();
+ }
}
w.close();
_TestUtil.checkIndex(dir);
IndexReader.open(dir, true).close();
- if (first && !allowInterrupt) {
- // Strangely, if we interrupt a thread before
- // all classes are loaded, the class loader
- // seems to do scary things with the interrupt
- // status. In java 1.5, it'll throw an
- // incorrect ClassNotFoundException. In java
- // 1.6, it'll silently clear the interrupt.
- // So, on first iteration through here we
- // don't open ourselves up for interrupts
- // until we've done the above loop.
- allowInterrupt = true;
- first = false;
- }
+ // Strangely, if we interrupt a thread before
+ // all classes are loaded, the class loader
+ // seems to do scary things with the interrupt
+ // status. In java 1.5, it'll throw an
+ // incorrect ClassNotFoundException. In java
+ // 1.6, it'll silently clear the interrupt.
+ // So, on first iteration through here we
+ // don't open ourselves up for interrupts
+ // until we've done the above loop.
+ allowInterrupt = true;
}
} catch (ThreadInterruptedException re) {
Throwable e = re.getCause();
@@ -4427,16 +4422,6 @@ public class TestIndexWriter extends Luc
if (finish) {
break;
}
-
- // Make sure IW cleared the interrupted bit
- // TODO: remove that false once test is fixed for real
- if (false && interrupted()) {
- System.out.println("FAILED; InterruptedException hit but thread.interrupted() was true");
- e.printStackTrace(System.out);
- failed = true;
- break;
- }
-
} catch (Throwable t) {
System.out.println("FAILED; unexpected exception");
t.printStackTrace(System.out);
@@ -4487,18 +4472,15 @@ public class TestIndexWriter extends Luc
// issue 100 interrupts to child thread
int i = 0;
while(i < 100) {
- Thread.sleep(1);
-
+ Thread.sleep(10);
if (t.allowInterrupt) {
i++;
- t.allowInterrupt = false;
t.interrupt();
}
if (!t.isAlive()) {
break;
}
}
- t.allowInterrupt = false;
t.finish = true;
t.join();
assertFalse(t.failed);
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java?rev=988543&r1=988542&r2=988543&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java Tue Aug 24 13:56:41 2010
@@ -44,6 +44,7 @@ public class MockDirectoryWrapper extend
Random randomState;
boolean noDeleteOpenFile = true;
boolean preventDoubleWrite = true;
+ boolean trackDiskUsage = false;
private Set<String> unSyncedFiles;
private Set<String> createdFiles;
volatile boolean crashed;
@@ -68,6 +69,10 @@ public class MockDirectoryWrapper extend
init();
}
+ public void setTrackDiskUsage(boolean v) {
+ trackDiskUsage = v;
+ }
+
/** If set to true, we throw an IOException if the same
* file is opened by createOutput, ever. */
public void setPreventDoubleWrite(boolean value) {
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockIndexOutputWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockIndexOutputWrapper.java?rev=988543&r1=988542&r2=988543&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockIndexOutputWrapper.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockIndexOutputWrapper.java Tue Aug 24 13:56:41 2010
@@ -18,7 +18,6 @@ package org.apache.lucene.store;
*/
import java.io.IOException;
-import java.util.Map;
/**
* Used by MockRAMDirectory to create an output stream that
@@ -46,11 +45,13 @@ public class MockIndexOutputWrapper exte
public void close() throws IOException {
dir.maybeThrowDeterministicException();
delegate.close();
- // Now compute actual disk usage & track the maxUsedSize
- // in the MockDirectoryWrapper:
- long size = dir.getRecomputedActualSizeInBytes();
- if (size > dir.maxUsedSize) {
- dir.maxUsedSize = size;
+ if (dir.trackDiskUsage) {
+ // Now compute actual disk usage & track the maxUsedSize
+ // in the MockDirectoryWrapper:
+ long size = dir.getRecomputedActualSizeInBytes();
+ if (size > dir.maxUsedSize) {
+ dir.maxUsedSize = size;
+ }
}
}
@@ -127,53 +128,6 @@ public class MockIndexOutputWrapper exte
delegate.setLength(length);
}
- /*
- @Override
- public void writeBytes(byte[] b, int length) throws IOException {
- delegate.writeBytes(b, length);
- }
-
- @Override
- public void writeInt(int i) throws IOException {
- delegate.writeInt(i);
- }
-
- @Override
- public void writeVInt(int i) throws IOException {
- delegate.writeVInt(i);
- }
-
- @Override
- public void writeLong(long i) throws IOException {
- delegate.writeLong(i);
- }
-
- @Override
- public void writeVLong(long i) throws IOException {
- delegate.writeVLong(i);
- }
-
- @Override
- public void writeString(String s) throws IOException {
- delegate.writeString(s);
- }
-
- @Override
- public void writeChars(String s, int start, int length) throws IOException {
- delegate.writeChars(s, start, length);
- }
-
- @Override
- public void writeChars(char[] s, int start, int length) throws IOException {
- delegate.writeChars(s, start, length);
- }
-
- @Override
- public void writeStringStringMap(Map<String,String> map) throws IOException {
- delegate.writeStringStringMap(map);
- }
- */
-
@Override
public void copyBytes(DataInput input, long numBytes) throws IOException {
delegate.copyBytes(input, numBytes);
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/_TestUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/_TestUtil.java?rev=988543&r1=988542&r2=988543&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/_TestUtil.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/_TestUtil.java Tue Aug 24 13:56:41 2010
@@ -210,4 +210,13 @@ public class _TestUtil {
public static CodecProvider alwaysCodec(final String codec) {
return alwaysCodec(CodecProvider.getDefault().lookup(codec));
}
+
+ public static boolean anyFilesExceptWriteLock(Directory dir) throws IOException {
+ String[] files = dir.listAll();
+ if (files.length > 1 || (files.length == 1 && !files[0].equals("write.lock"))) {
+ return true;
+ } else {
+ return false;
+ }
+ }
}