|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.lucene.store.Directory org.apache.lucene.store.FilterDirectory org.apache.lucene.store.BaseDirectoryWrapper org.apache.lucene.store.MockDirectoryWrapper
public class 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:
LuceneTestCase.newDirectory()
are tracked
to ensure they are closed by the test.
Nested Class Summary | |
---|---|
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. |
Nested classes/interfaces inherited from class org.apache.lucene.store.Directory |
---|
Directory.IndexInputSlicer |
Field Summary | |
---|---|
protected LockFactory |
lockFactory
|
Fields inherited from class org.apache.lucene.store.BaseDirectoryWrapper |
---|
isOpen |
Fields inherited from class org.apache.lucene.store.FilterDirectory |
---|
in |
Constructor Summary | |
---|---|
MockDirectoryWrapper(Random random,
Directory delegate)
|
Method Summary | |
---|---|
void |
clearCrash()
|
void |
clearLock(String name)
|
void |
close()
|
void |
copy(Directory to,
String src,
String dest,
IOContext context)
|
void |
crash()
Simulates a crash of OS or machine by overwriting unsynced files. |
IndexOutput |
createOutput(String name,
IOContext context)
|
Directory.IndexInputSlicer |
createSlicer(String name,
IOContext context)
|
void |
deleteFile(String name)
|
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)
|
long |
fileLength(String name)
|
boolean |
getAssertNoDeleteOpenFile()
|
int |
getInputCloneCount()
|
LockFactory |
getLockFactory()
|
String |
getLockID()
|
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()
|
Lock |
makeLock(String name)
|
IndexInput |
openInput(String name,
IOContext context)
|
void |
removeIndexInput(IndexInput in,
String name)
|
void |
removeIndexOutput(IndexOutput out,
String name)
|
void |
resetMaxUsedSizeInBytes()
|
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 |
setLockFactory(LockFactory lockFactory)
|
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 |
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)
|
Methods inherited from class org.apache.lucene.store.BaseDirectoryWrapper |
---|
getCheckIndexOnClose, getCrossCheckTermVectorsOnClose, isOpen, setCheckIndexOnClose, setCrossCheckTermVectorsOnClose |
Methods inherited from class org.apache.lucene.store.FilterDirectory |
---|
getDelegate, toString |
Methods inherited from class org.apache.lucene.store.Directory |
---|
ensureOpen |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected LockFactory lockFactory
Constructor Detail |
---|
public MockDirectoryWrapper(Random random, Directory delegate)
Method Detail |
---|
public int getInputCloneCount()
public void setTrackDiskUsage(boolean v)
public void setPreventDoubleWrite(boolean value)
public void setThrottling(MockDirectoryWrapper.Throttling throttling)
public void sync(Collection<String> names) throws IOException
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
deleteFile
in class FilterDirectory
IOException
public Set<String> getOpenDeletedFiles()
public void setFailOnCreateOutput(boolean v)
public IndexOutput createOutput(String name, IOContext context) throws IOException
createOutput
in class FilterDirectory
IOException
public void setFailOnOpenInput(boolean v)
public IndexInput openInput(String name, IOContext context) throws IOException
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
close
in interface Closeable
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
listAll
in class FilterDirectory
IOException
public boolean fileExists(String name) throws IOException
fileExists
in class FilterDirectory
IOException
public long fileLength(String name) throws IOException
fileLength
in class FilterDirectory
IOException
public Lock makeLock(String name)
makeLock
in class FilterDirectory
public void clearLock(String name) throws IOException
clearLock
in class FilterDirectory
IOException
public void setLockFactory(LockFactory lockFactory) throws IOException
setLockFactory
in class FilterDirectory
IOException
public LockFactory getLockFactory()
getLockFactory
in class FilterDirectory
public String getLockID()
getLockID
in class FilterDirectory
public void copy(Directory to, String src, String dest, IOContext context) throws IOException
copy
in class BaseDirectoryWrapper
IOException
public Directory.IndexInputSlicer createSlicer(String name, IOContext context) throws IOException
createSlicer
in class BaseDirectoryWrapper
IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |