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.
|
isOpen
in
Constructor and Description |
---|
MockDirectoryWrapper(java.util.Random random,
Directory delegate) |
Modifier and Type | Method and Description |
---|---|
void |
clearCrash() |
void |
close()
Closes the directory.
|
void |
copyFrom(Directory from,
java.lang.String src,
java.lang.String dest,
IOContext context)
Copies an existing
src file from directory from
to a non-existent file dest in this directory. |
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 and returns an
IndexOutput
instance for appending data to this file. |
IndexOutput |
createTempOutput(java.lang.String prefix,
java.lang.String suffix,
IOContext context)
Creates a new, empty, temporary file in the directory and returns an
IndexOutput
instance for appending data to this file. |
void |
deleteFile(java.lang.String name)
Removes an existing file in the directory.
|
protected void |
ensureOpen()
Ensures this directory is still open.
|
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 byte 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 names of all files stored in this directory.
|
Lock |
obtainLock(java.lang.String name)
Acquires and returns a
Lock for a file with the given name. |
ChecksumIndexInput |
openChecksumInput(java.lang.String name,
IOContext context)
Opens a checksum-computing stream for reading an existing file.
|
IndexInput |
openInput(java.lang.String name,
IOContext context)
Opens a stream for 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 file to dest file where
dest must not already 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)
Ensures that any writes to these files are moved to
stable storage (made durable).
|
void |
syncMetaData()
Ensures that directory metadata, such as recent file renames, are moved to stable
storage.
|
java.lang.String |
toString() |
getCheckIndexOnClose, getCrossCheckTermVectorsOnClose, isOpen, setCheckIndexOnClose, setCrossCheckTermVectorsOnClose
getDelegate, getPendingDeletions, unwrap
public 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
Directory
sync
in class FilterDirectory
java.io.IOException
Directory.syncMetaData()
public void rename(java.lang.String source, java.lang.String dest) throws java.io.IOException
Directory
source
file to dest
file where
dest
must not already exist in the directory.
It is permitted for this operation to not be truly atomic, for example
both source
and dest
can be visible temporarily in Directory.listAll()
.
However, the implementation of this method must ensure the content of
dest
appears as the entire source
atomically. So once
dest
is visible for readers, the entire content of previous source
is visible.
This method is used by IndexWriter to publish commits.rename
in class FilterDirectory
java.io.IOException
public void syncMetaData() throws java.io.IOException
Directory
syncMetaData
in class FilterDirectory
java.io.IOException
Directory.sync(Collection)
public final long sizeInBytes() throws java.io.IOException
java.io.IOException
public void corruptUnknownFiles() throws java.io.IOException
java.io.IOException
public void corruptFiles(java.util.Collection<java.lang.String> files) throws java.io.IOException
java.io.IOException
public void crash() throws java.io.IOException
java.io.IOException
public void clearCrash()
public void setMaxSizeInBytes(long maxSize)
public long getMaxSizeInBytes()
public long getMaxUsedSizeInBytes()
public void resetMaxUsedSizeInBytes() throws java.io.IOException
java.io.IOException
public 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
Directory
NoSuchFileException
or FileNotFoundException
if name
points to a non-existing file.deleteFile
in class FilterDirectory
name
- the name of an existing file.java.io.IOException
- in case of I/O errorpublic 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
Directory
IndexOutput
instance for appending data to this file.
This method must throw FileAlreadyExistsException
if the file
already exists.createOutput
in class FilterDirectory
name
- the name of the file to create.java.io.IOException
- in case of I/O errorpublic IndexOutput createTempOutput(java.lang.String prefix, java.lang.String suffix, IOContext context) throws java.io.IOException
Directory
IndexOutput
instance for appending data to this file.
The temporary file name (accessible via IndexOutput.getName()
) will start with
prefix
, end with suffix
and have a reserved file extension .tmp
.createTempOutput
in class FilterDirectory
java.io.IOException
public void setFailOnOpenInput(boolean v)
public IndexInput openInput(java.lang.String name, IOContext context) throws java.io.IOException
Directory
NoSuchFileException
or FileNotFoundException
if name
points to a non-existing file.openInput
in class FilterDirectory
name
- the name of an existing file.java.io.IOException
- in case of I/O errorpublic final long getRecomputedSizeInBytes() throws java.io.IOException
java.io.IOException
public final long getRecomputedActualSizeInBytes() throws java.io.IOException
java.io.IOException
public void setAssertNoUnrefencedFilesOnClose(boolean v)
public void close() throws java.io.IOException
Directory
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class BaseDirectoryWrapper
java.io.IOException
public 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
Directory
String.compareTo(java.lang.String)
) order.listAll
in class FilterDirectory
java.io.IOException
- in case of I/O errorpublic long fileLength(java.lang.String name) throws java.io.IOException
Directory
NoSuchFileException
or FileNotFoundException
if name
points to a non-existing file.fileLength
in class FilterDirectory
name
- the name of an existing file.java.io.IOException
- in case of I/O errorpublic Lock obtainLock(java.lang.String name) throws java.io.IOException
Directory
Lock
for a file with the given name.obtainLock
in class FilterDirectory
name
- 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 FilterDirectory
public final ChecksumIndexInput openChecksumInput(java.lang.String name, IOContext context) throws java.io.IOException
Directory
NoSuchFileException
or FileNotFoundException
if name
points to a non-existing file.openChecksumInput
in class Directory
name
- the name of an existing file.java.io.IOException
- in case of I/O errorpublic final void copyFrom(Directory from, java.lang.String src, java.lang.String dest, IOContext context) throws java.io.IOException
Directory
src
file from directory from
to a non-existent file dest
in this directory.protected final void ensureOpen() throws AlreadyClosedException
Directory
ensureOpen
in class Directory
AlreadyClosedException
- if this directory is closed.Copyright © 2000–2019 The Apache Software Foundation. All rights reserved.