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.
|
Modifier and Type | Field and Description |
---|---|
protected LockFactory |
lockFactory |
isOpen
in
Constructor and Description |
---|
MockDirectoryWrapper(Random random,
Directory delegate) |
Modifier and Type | Method and Description |
---|---|
void |
clearCrash() |
void |
clearLock(String name)
Attempt to clear (forcefully unlock and remove) the
specified lock.
|
void |
close()
Closes the store.
|
void |
copy(Directory to,
String src,
String dest,
IOContext context)
Copies the file src to
Directory to under the new
file name dest. |
void |
crash()
Simulates a crash of OS or machine by overwriting
unsynced files.
|
IndexOutput |
createOutput(String name,
IOContext context)
Creates a new, empty file in the directory with the given name.
|
void |
deleteFile(String name)
Removes an existing file in the directory.
|
boolean |
didTryToDelete(String fileName)
Returns true if
deleteFile(java.lang.String) was called with this
fileName, but the virus checker prevented the deletion. |
void |
failOn(MockDirectoryWrapper.Failure fail)
add a Failure object to the list of objects to be evaluated
at every potential failure point
|
boolean |
fileExists(String name)
Returns true iff a file with the given name exists.
|
long |
fileLength(String name)
Returns the length of a file in the directory.
|
boolean |
getAssertNoDeleteOpenFile() |
boolean |
getEnableVirusScanner()
Returns true if the virus scanner is enabled
|
int |
getInputCloneCount() |
LockFactory |
getLockFactory()
Get the LockFactory that this Directory instance is
using for its locking implementation.
|
String |
getLockID()
Return a string identifier that uniquely differentiates
this Directory instance from other Directory instances.
|
long |
getMaxSizeInBytes() |
long |
getMaxUsedSizeInBytes()
Returns the peek actual storage used (bytes) in this
directory.
|
boolean |
getNoDeleteOpenFile() |
Set<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.
|
String[] |
listAll()
Returns an array of strings, one for each file in the directory.
|
Lock |
makeLock(String name)
Construct a
Lock . |
IndexInput |
openInput(String name,
IOContext context)
Returns a stream reading an existing file, with the
specified read buffer size.
|
void |
removeIndexInput(IndexInput in,
String name) |
void |
removeIndexOutput(IndexOutput out,
String name) |
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 |
setEnableVirusScanner(boolean value)
If set to true (the default), deleteFile sometimes
fails because a virus scanner is open.
|
void |
setFailOnCreateOutput(boolean v) |
void |
setFailOnOpenInput(boolean v) |
void |
setLockFactory(LockFactory lockFactory)
Set the LockFactory that this Directory instance should
use for its locking implementation.
|
void |
setMaxSizeInBytes(long maxSize) |
void |
setNoDeleteOpenFile(boolean value)
Emulate windows whereby deleting an open file is not
allowed (raise IOException).
|
void |
setPreventDoubleWrite(boolean value)
If set to true, we throw an IOException if the same
file is opened by createOutput, ever.
|
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)
By default, opening and closing has a rare small sleep to catch race conditions
|
void |
setWrapLockFactory(boolean v)
Set to false if you want to return the pure lockfactory
and not wrap it with MockLockFactoryWrapper.
|
long |
sizeInBytes() |
void |
sync(Collection<String> names)
Ensure that any writes to these files are moved to
stable storage.
|
getCheckIndexOnClose, getCrossCheckTermVectorsOnClose, isOpen, setCheckIndexOnClose, setCrossCheckTermVectorsOnClose
getDelegate, toString
ensureOpen, openChecksumInput
protected LockFactory lockFactory
public int getInputCloneCount()
public void setTrackDiskUsage(boolean v)
public void setPreventDoubleWrite(boolean value)
public void setAllowRandomFileNotFoundException(boolean value)
public void setAllowReadingFilesStillOpenForWrite(boolean value)
public boolean getEnableVirusScanner()
public void setEnableVirusScanner(boolean value)
public void setThrottling(MockDirectoryWrapper.Throttling throttling)
public void setUseSlowOpenClosers(boolean v)
You can disable this if you dont need it
public void sync(Collection<String> names) throws IOException
Directory
sync
in class FilterDirectory
IOException
public final long sizeInBytes() throws IOException
IOException
public void crash() throws IOException
IOException
public void clearCrash()
public void setMaxSizeInBytes(long maxSize)
public long getMaxSizeInBytes()
public long getMaxUsedSizeInBytes()
public void resetMaxUsedSizeInBytes() throws IOException
IOException
public void setNoDeleteOpenFile(boolean value)
public boolean getNoDeleteOpenFile()
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 void deleteFile(String name) throws IOException
Directory
deleteFile
in class FilterDirectory
IOException
public boolean didTryToDelete(String fileName)
deleteFile(java.lang.String)
was called with this
fileName, but the virus checker prevented the deletion.public void setFailOnCreateOutput(boolean v)
public IndexOutput createOutput(String name, IOContext context) throws IOException
Directory
createOutput
in class FilterDirectory
IOException
public void setFailOnOpenInput(boolean v)
public IndexInput openInput(String name, IOContext context) throws IOException
Directory
FSDirectory
and CompoundFileDirectory
.
Throws FileNotFoundException
or NoSuchFileException
if the file does not exist.
openInput
in class FilterDirectory
IOException
public final long getRecomputedSizeInBytes() throws IOException
IOException
public final long getRecomputedActualSizeInBytes() throws IOException
IOException
public void setAssertNoUnrefencedFilesOnClose(boolean v)
public void setWrapLockFactory(boolean v)
Be careful if you turn this off: MockDirectoryWrapper might no longer be able to detect if you forget to close an IndexWriter, and spit out horribly scary confusing exceptions instead of simply telling you that.
public void close() throws IOException
Directory
close
in interface Closeable
close
in interface AutoCloseable
close
in class BaseDirectoryWrapper
IOException
public void removeIndexOutput(IndexOutput out, String name)
public void removeIndexInput(IndexInput in, String name)
public void failOn(MockDirectoryWrapper.Failure fail)
public String[] listAll() throws IOException
Directory
listAll
in class FilterDirectory
NoSuchDirectoryException
- if the directory is not prepared for any
write operations (such as Directory.createOutput(String, IOContext)
).IOException
- in case of other IO errorspublic boolean fileExists(String name) throws IOException
Directory
fileExists
in class FilterDirectory
IOException
public long fileLength(String name) throws IOException
Directory
FileNotFoundException
or NoSuchFileException
if the file does not exist.
fileLength
in class FilterDirectory
name
- the name of the file for which to return the length.IOException
- if there was an IO error while retrieving the file's
length.public Lock makeLock(String name)
Directory
Lock
.makeLock
in class FilterDirectory
name
- the name of the lock filepublic void clearLock(String name) throws IOException
Directory
clearLock
in class FilterDirectory
name
- name of the lock to be cleared.IOException
public void setLockFactory(LockFactory lockFactory) throws IOException
Directory
setLockFactory
in class FilterDirectory
lockFactory
- instance of LockFactory
.IOException
public LockFactory getLockFactory()
Directory
getLockFactory
in class FilterDirectory
public String getLockID()
Directory
getLockID
in class FilterDirectory
public void copy(Directory to, String src, String dest, IOContext context) throws IOException
Directory
Directory
to under the new
file name dest.
If 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()) { dir.copy(to, 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.
copy
in class BaseDirectoryWrapper
IOException
Copyright © 2000–2018 The Apache Software Foundation. All rights reserved.