diff -r f6527e454ef3 lucene/src/java/org/apache/lucene/store/FSDirectory.java --- a/lucene/src/java/org/apache/lucene/store/FSDirectory.java Mon Aug 23 22:54:26 2010 +0000 +++ b/lucene/src/java/org/apache/lucene/store/FSDirectory.java Tue Aug 24 09:18:36 2010 -0400 @@ -274,10 +274,12 @@ 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. */ diff -r f6527e454ef3 lucene/src/test/org/apache/lucene/index/TestIndexWriter.java --- a/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java Mon Aug 23 22:54:26 2010 +0000 +++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java Tue Aug 24 09:18:36 2010 -0400 @@ -314,6 +314,7 @@ if (VERBOSE) System.out.println("\ncycle: " + testName); + dir.setTrackDiskUsage(true); dir.setMaxSizeInBytes(thisDiskFree); dir.setRandomIOExceptionRate(rate, diskFree); @@ -661,6 +662,8 @@ } 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 @@ 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 @@ dir = newDirectory(random); } catch (IOException e) { throw new RuntimeException(e); } IndexWriter w = null; - boolean first = true; while(!finish) { try { @@ -4386,40 +4389,32 @@ 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 @@ 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 @@ // 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); diff -r f6527e454ef3 lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java --- a/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java Mon Aug 23 22:54:26 2010 +0000 +++ b/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java Tue Aug 24 09:18:36 2010 -0400 @@ -44,6 +44,7 @@ Random randomState; boolean noDeleteOpenFile = true; boolean preventDoubleWrite = true; + boolean trackDiskUsage = false; private Set unSyncedFiles; private Set createdFiles; volatile boolean crashed; @@ -68,6 +69,10 @@ 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) { diff -r f6527e454ef3 lucene/src/test/org/apache/lucene/store/MockIndexOutputWrapper.java --- a/lucene/src/test/org/apache/lucene/store/MockIndexOutputWrapper.java Mon Aug 23 22:54:26 2010 +0000 +++ b/lucene/src/test/org/apache/lucene/store/MockIndexOutputWrapper.java Tue Aug 24 09:18:36 2010 -0400 @@ -18,7 +18,6 @@ */ import java.io.IOException; -import java.util.Map; /** * Used by MockRAMDirectory to create an output stream that @@ -46,11 +45,13 @@ 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 @@ 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 map) throws IOException { - delegate.writeStringStringMap(map); - } - */ - @Override public void copyBytes(DataInput input, long numBytes) throws IOException { delegate.copyBytes(input, numBytes);