MockDirectoryWrapper
This is a Directory Wrapper that adds methods intended to be used only by unit tests. It also adds a number of features useful for testing:
Instances created by LuceneTestCase.newDirectory are tracked to ensure they are closed by the test.
When a MockDirectoryWrapper is closed, it will throw an exception if it has any open files against it (with a stacktrace indicating where they were opened from).
When a MockDirectoryWrapper is closed, it runs CheckIndex to test if the index was corrupted.
MockDirectoryWrapper simulates some "features" of Windows, such as refusing to write/delete to open files.
Types
Objects that represent fail-able conditions. Objects of a derived class are created and registered with the mock directory. After register, each object will be invoked once for each first write of a file, giving the object a chance to throw an IOException.
Use this when throwing fake IOException, e.g. from [ ].
Enum for controlling hard disk throttling. Set via #setThrottling(Throttling)
Properties
Trip a test assert if there is an attempt to delete an open file.
whether checkIndex should run on close
level passed to checkIndex when closing
Returns the peek actual storage used (bytes) in this directory.
If 0.0, no exceptions will be thrown. Else this should be a double 0.0 - 1.0. We will randomly throw an IOException on the first write to an OutputStream based on this probability.
If 0.0, no exceptions will be thrown during openInput and createOutput. Else this should be a double 0.0 - 1.0 and we will randomly throw an IOException in openInput and createOutput with this probability.
Functions
add a Failure object to the list of objects to be evaluated at every potential failure point
Iterate through the failures list, giving each object a chance to throw an IOE
Add a rare small sleep to catch race conditions in open/close