java.lang.Object
com.aoapps.io.filesystems.FileSystemWrapper
com.aoapps.io.filesystems.RandomFailFileSystem
- All Implemented Interfaces:
FileSystem
A file system implementation that randomly fails, this is used by test
suites to verify correct behavior under expected failure modes.
- Author:
- AO Industries, Inc.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceProvides the failure probabilities.static classThrown when a failure occurs randomly.Nested classes/interfaces inherited from class com.aoapps.io.filesystems.FileSystemWrapper
FileSystemWrapper.PathIteratorWrapper, FileSystemWrapper.PathWrapper -
Field Summary
Fields inherited from class com.aoapps.io.filesystems.FileSystemWrapper
wrappedFileSystem -
Constructor Summary
ConstructorsConstructorDescriptionRandomFailFileSystem(FileSystem wrappedFileSystem) Uses default probabilities and a default fast pseudo-random number generator for non-cryptographic purposes.RandomFailFileSystem(FileSystem wrappedFileSystem, RandomFailFileSystem.FailureProbabilities failureProbabilities, Random fastRandom) Creates a new random-fail filesystem, wrapping the given filesystem. -
Method Summary
Modifier and TypeMethodDescriptioncreateDirectory(Path path) Atomically creates a directory (must not have already existed).createFile(Path path) Atomically creates an empty file (must not have already existed).voidDeletes the file system object at the given path.Random chance of fail on list as well as list iteration.Locks a file in exclusive mode.protected voidrandomFail(float probability) longGets the size of the file system object at the given path.Methods inherited from class com.aoapps.io.filesystems.FileSystemWrapper
checkSubPath, join, parsePath, unwrapPath, wrapPath, wrapSubPath
-
Constructor Details
-
RandomFailFileSystem
public RandomFailFileSystem(FileSystem wrappedFileSystem, RandomFailFileSystem.FailureProbabilities failureProbabilities, Random fastRandom) Creates a new random-fail filesystem, wrapping the given filesystem.- Parameters:
fastRandom- A fast pseudo-random number generator for non-cryptographic purposes.
-
RandomFailFileSystem
Uses default probabilities and a default fast pseudo-random number generator for non-cryptographic purposes.
-
-
Method Details
-
randomFail
-
list
Random chance of fail on list as well as list iteration.- Specified by:
listin interfaceFileSystem- Overrides:
listin classFileSystemWrapper- Parameters:
path- Must be from this file system.- Returns:
- a read-only iterator of children
- Throws:
IOException- if an underlying I/O error occurs.RandomFailFileSystem.RandomFailIOException
-
delete
Description copied from interface:FileSystemDeletes the file system object at the given path.- Specified by:
deletein interfaceFileSystem- Overrides:
deletein classFileSystemWrapper- Parameters:
path- Must be from this file system.- Throws:
IOException- if an underlying I/O error occurs.
-
size
Description copied from interface:FileSystemGets the size of the file system object at the given path.- Specified by:
sizein interfaceFileSystem- Overrides:
sizein classFileSystemWrapper- Parameters:
path- Must be from this file system.- Throws:
IOException- if an underlying I/O error occurs.
-
createFile
Description copied from interface:FileSystemAtomically creates an empty file (must not have already existed).- Specified by:
createFilein interfaceFileSystem- Overrides:
createFilein classFileSystemWrapper- Returns:
- returns the path
- Throws:
IOException- if an underlying I/O error occurs.
-
createDirectory
Description copied from interface:FileSystemAtomically creates a directory (must not have already existed).- Specified by:
createDirectoryin interfaceFileSystem- Overrides:
createDirectoryin classFileSystemWrapper- Returns:
- returns the path
- Throws:
IOException- if an underlying I/O error occurs.
-
lock
Description copied from interface:FileSystemLocks a file in exclusive mode. File range and shared locks not currently supported. The lock must be closed to unlock, usually in a try/finally or try-with-resources block. The locks are not reentrant, attempting to obtain the lock from the same thread will result in deadlock.- Specified by:
lockin interfaceFileSystem- Overrides:
lockin classFileSystemWrapper- Throws:
IOException- if an underlying I/O error occurs.- See Also:
-
