I changed the check to freeSpace < len, but then the test failed to trip disk-full the second time, unless I call out.flush() in between. Debugging tells me that RAMOutputStream sets RAMFile.length only on flush(), therefore even if I attempt to write a 2K byte (with maxSize=2), the test doesn't fail.
Seems like getRecomputedActualSizeInBytes is not very accurate. It only returns the size of the flushed files (even for FSDir). This may be ok, dunno. It just felt wrong for RAMDirectory, since there is no real buffering happening.
Anyway, I guess we'll have to live with that. Disk-full is anyway a best effort, so in this test, I'll just call flush(). In real tests that want to trip disk-full, usually indexing happens and therefore files get flushed, and the size measure is closer.