Index: lucene/src/test/org/apache/lucene/store/MockIndexOutputWrapper.java =================================================================== --- lucene/src/test/org/apache/lucene/store/MockIndexOutputWrapper.java (revision 1026400) +++ lucene/src/test/org/apache/lucene/store/MockIndexOutputWrapper.java (working copy) @@ -131,8 +131,36 @@ @Override public void copyBytes(DataInput input, long numBytes) throws IOException { - delegate.copyBytes(input, numBytes); - // TODO: we may need to check disk full here as well + // TODO: somehow factor this hairy disk-full stuff with writeBytes() + long freeSpace = dir.maxSize == 0 ? 0 : dir.maxSize - dir.sizeInBytes(); + long realUsage = 0; + + // If MockRAMDir crashed since we were opened, then + // don't write anything: + if (dir.crashed) + throw new IOException("MockRAMDirectory was crashed; cannot copy to " + name); + + // Enforce disk full: + if (dir.maxSize != 0 && freeSpace <= numBytes) { + // Compute the real disk free. This will greatly slow + // down our test but makes it more accurate: + realUsage = dir.getRecomputedActualSizeInBytes(); + freeSpace = dir.maxSize - realUsage; + } + + if (dir.maxSize != 0 && freeSpace <= numBytes) { + if (freeSpace > 0 && freeSpace < numBytes) { + realUsage += freeSpace; + delegate.copyBytes(input, (int) freeSpace); + } + if (realUsage > dir.maxUsedSize) { + dir.maxUsedSize = realUsage; + } + throw new IOException("fake disk full at " + dir.getRecomputedActualSizeInBytes() + " bytes when copying " + name); + } else { + delegate.copyBytes(input, numBytes); + } + dir.maybeThrowDeterministicException(); } }