public class MockDirectoryWrapper extends BaseDirectoryWrapper
LuceneTestCase.newDirectory() are tracked
to ensure they are closed by the test.
| Modifier and Type | Class and Description |
|---|---|
static class |
MockDirectoryWrapper.Failure
Objects that represent fail-able conditions.
|
static class |
MockDirectoryWrapper.FakeIOException
Use this when throwing fake
IOException,
e.g. |
static class |
MockDirectoryWrapper.Throttling
Enum for controlling hard disk throttling.
|
isOpenin| Constructor and Description |
|---|
MockDirectoryWrapper(java.util.Random random,
Directory delegate) |
| Modifier and Type | Method and Description |
|---|---|
void |
clearCrash() |
void |
close()
Closes the store.
|
void |
copyFrom(Directory from,
java.lang.String src,
java.lang.String dest,
IOContext context)
Copies the file src in from to this directory under the new
file name dest.
|
void |
corruptFiles(java.util.Collection<java.lang.String> files) |
void |
corruptUnknownFiles() |
void |
crash()
Simulates a crash of OS or machine by overwriting
unsynced files.
|
IndexOutput |
createOutput(java.lang.String name,
IOContext context)
Creates a new, empty file in the directory with the given name.
|
IndexOutput |
createTempOutput(java.lang.String prefix,
java.lang.String suffix,
IOContext context)
Creates a new, empty file for writing in the directory, with a
temporary file name including prefix and suffix, ending with the
reserved extension
.tmp. |
void |
deleteFile(java.lang.String name)
Removes an existing file in the directory.
|
protected void |
ensureOpen() |
void |
failOn(MockDirectoryWrapper.Failure fail)
add a Failure object to the list of objects to be evaluated
at every potential failure point
|
long |
fileLength(java.lang.String name)
Returns the length of a file in the directory.
|
boolean |
getAssertNoDeleteOpenFile() |
long |
getFileHandleCount()
returns current open file handle count
|
int |
getInputCloneCount() |
long |
getMaxSizeInBytes() |
long |
getMaxUsedSizeInBytes()
Returns the peek actual storage used (bytes) in this
directory.
|
java.util.Set<java.lang.String> |
getOpenDeletedFiles() |
double |
getRandomIOExceptionRate() |
double |
getRandomIOExceptionRateOnOpen() |
long |
getRecomputedActualSizeInBytes()
Like getRecomputedSizeInBytes(), but, uses actual file
lengths rather than buffer allocations (which are
quantized up to nearest
RAMOutputStream.BUFFER_SIZE (now 1024) bytes.
|
long |
getRecomputedSizeInBytes()
Provided for testing purposes.
|
java.lang.String[] |
listAll()
Returns an array of strings, one for each entry in the directory, in sorted (UTF16, java's String.compare) order.
|
Lock |
obtainLock(java.lang.String name)
Returns an obtained
Lock. |
ChecksumIndexInput |
openChecksumInput(java.lang.String name,
IOContext context)
Returns a stream reading an existing file, computing checksum as it reads
|
IndexInput |
openInput(java.lang.String name,
IOContext context)
Returns a stream reading an existing file.
|
void |
removeIndexInput(IndexInput in,
java.lang.String name) |
void |
removeIndexOutput(IndexOutput out,
java.lang.String name) |
void |
rename(java.lang.String source,
java.lang.String dest)
Renames
source to dest as an atomic operation,
where dest does not yet exist in the directory. |
void |
resetMaxUsedSizeInBytes() |
void |
setAllowRandomFileNotFoundException(boolean value)
If set to true (the default), when we throw random
IOException on openInput or createOutput, we may
sometimes throw FileNotFoundException or
NoSuchFileException.
|
void |
setAllowReadingFilesStillOpenForWrite(boolean value)
If set to true, you can open an inputstream on a file
that is still open for writes.
|
void |
setAssertNoDeleteOpenFile(boolean value)
Trip a test assert if there is an attempt
to delete an open file.
|
void |
setAssertNoUnrefencedFilesOnClose(boolean v) |
void |
setFailOnCreateOutput(boolean v) |
void |
setFailOnOpenInput(boolean v) |
void |
setMaxSizeInBytes(long maxSize) |
void |
setRandomIOExceptionRate(double rate)
If 0.0, no exceptions will be thrown.
|
void |
setRandomIOExceptionRateOnOpen(double rate)
If 0.0, no exceptions will be thrown during openInput
and createOutput.
|
void |
setThrottling(MockDirectoryWrapper.Throttling throttling) |
void |
setTrackDiskUsage(boolean v) |
void |
setUseSlowOpenClosers(boolean v)
Add a rare small sleep to catch race conditions in open/close
|
void |
setVerboseClone(boolean v)
If set to true, we print a fake exception
with filename and stacktrace on every indexinput clone()
|
long |
sizeInBytes() |
void |
sync(java.util.Collection<java.lang.String> names)
Ensure that any writes to these files are moved to
stable storage.
|
void |
syncMetaData()
Ensure that directory metadata, such as recent file renames, are made
durable.
|
java.lang.String |
toString() |
getCheckIndexOnClose, getCrossCheckTermVectorsOnClose, isOpen, setCheckIndexOnClose, setCrossCheckTermVectorsOnClosegetDelegate, unwrappublic MockDirectoryWrapper(java.util.Random random,
Directory delegate)
public int getInputCloneCount()
public void setVerboseClone(boolean v)
public void setTrackDiskUsage(boolean v)
public void setAllowRandomFileNotFoundException(boolean value)
public void setAllowReadingFilesStillOpenForWrite(boolean value)
public void setThrottling(MockDirectoryWrapper.Throttling throttling)
public void setUseSlowOpenClosers(boolean v)
You can enable this if you need it.
public void sync(java.util.Collection<java.lang.String> names)
throws java.io.IOException
Directorysync in class FilterDirectoryjava.io.IOExceptionpublic void rename(java.lang.String source,
java.lang.String dest)
throws java.io.IOException
Directorysource to dest as an atomic operation,
where dest does not yet exist in the directory.
Notes: This method is used by IndexWriter to publish commits.
It is ok if this operation is not truly atomic, for example
both source and dest can be visible temporarily.
It is just important that the contents of dest appear
atomically, or an exception is thrown.
rename in class FilterDirectoryjava.io.IOExceptionpublic void syncMetaData()
throws java.io.IOException
DirectorysyncMetaData in class FilterDirectoryjava.io.IOExceptionpublic final long sizeInBytes()
throws java.io.IOException
java.io.IOExceptionpublic void corruptUnknownFiles()
throws java.io.IOException
java.io.IOExceptionpublic void corruptFiles(java.util.Collection<java.lang.String> files)
throws java.io.IOException
java.io.IOExceptionpublic void crash()
throws java.io.IOException
java.io.IOExceptionpublic void clearCrash()
public void setMaxSizeInBytes(long maxSize)
public long getMaxSizeInBytes()
public long getMaxUsedSizeInBytes()
public void resetMaxUsedSizeInBytes()
throws java.io.IOException
java.io.IOExceptionpublic void setAssertNoDeleteOpenFile(boolean value)
public boolean getAssertNoDeleteOpenFile()
public void setRandomIOExceptionRate(double rate)
public double getRandomIOExceptionRate()
public void setRandomIOExceptionRateOnOpen(double rate)
public double getRandomIOExceptionRateOnOpen()
public long getFileHandleCount()
public void deleteFile(java.lang.String name)
throws java.io.IOException
DirectorydeleteFile in class FilterDirectoryjava.io.IOExceptionpublic java.util.Set<java.lang.String> getOpenDeletedFiles()
public void setFailOnCreateOutput(boolean v)
public IndexOutput createOutput(java.lang.String name, IOContext context) throws java.io.IOException
DirectorycreateOutput in class FilterDirectoryjava.io.IOExceptionpublic IndexOutput createTempOutput(java.lang.String prefix, java.lang.String suffix, IOContext context) throws java.io.IOException
Directory.tmp. Use
IndexOutput.getName() to see what name was used.createTempOutput in class FilterDirectoryjava.io.IOExceptionpublic void setFailOnOpenInput(boolean v)
public IndexInput openInput(java.lang.String name, IOContext context) throws java.io.IOException
DirectoryThrows FileNotFoundException or NoSuchFileException
if the file does not exist.
openInput in class FilterDirectoryjava.io.IOExceptionpublic final long getRecomputedSizeInBytes()
throws java.io.IOException
java.io.IOExceptionpublic final long getRecomputedActualSizeInBytes()
throws java.io.IOException
java.io.IOExceptionpublic void setAssertNoUnrefencedFilesOnClose(boolean v)
public void close()
throws java.io.IOException
Directoryclose in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class BaseDirectoryWrapperjava.io.IOExceptionpublic void removeIndexOutput(IndexOutput out, java.lang.String name)
public void removeIndexInput(IndexInput in, java.lang.String name)
public void failOn(MockDirectoryWrapper.Failure fail)
public java.lang.String[] listAll()
throws java.io.IOException
DirectorylistAll in class FilterDirectoryjava.io.IOException - in case of IO errorpublic long fileLength(java.lang.String name)
throws java.io.IOException
DirectoryFileNotFoundException or NoSuchFileException
if the file does not exist.
fileLength in class FilterDirectoryname - the name of the file for which to return the length.java.io.IOException - if there was an IO error while retrieving the file's
length.public Lock obtainLock(java.lang.String name) throws java.io.IOException
DirectoryLock.obtainLock in class FilterDirectoryname - the name of the lock fileLockObtainFailedException - (optional specific exception) if the lock could
not be obtained because it is currently held elsewhere.java.io.IOException - if any i/o error occurs attempting to gain the lockpublic java.lang.String toString()
toString in class FilterDirectorypublic final ChecksumIndexInput openChecksumInput(java.lang.String name, IOContext context) throws java.io.IOException
DirectoryopenChecksumInput in class Directoryjava.io.IOExceptionpublic final void copyFrom(Directory from, java.lang.String src, java.lang.String dest, IOContext context) throws java.io.IOException
DirectoryIf you want to copy the entire source directory to the destination one, you can do so like this:
Directory to; // the directory to copy to
for (String file : dir.listAll()) {
to.copyFrom(dir, file, newFile, IOContext.DEFAULT); // newFile can be either file, or a new name
}
NOTE: this method does not check whether dest exist and will overwrite it if it does.
protected final void ensureOpen()
throws AlreadyClosedException
ensureOpen in class DirectoryAlreadyClosedException - if this Directory is closedCopyright © 2000–2018 The Apache Software Foundation. All rights reserved.