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
Modifier and TypeClassDescriptionstatic interface
Provides the failure probabilities.static class
Thrown 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
ConstructorDescriptionRandomFailFileSystem
(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).void
Deletes 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 void
randomFail
(float probability) long
Gets 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:
list
in interfaceFileSystem
- Overrides:
list
in 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:FileSystem
Deletes the file system object at the given path.- Specified by:
delete
in interfaceFileSystem
- Overrides:
delete
in classFileSystemWrapper
- Parameters:
path
- Must be from this file system.- Throws:
IOException
- if an underlying I/O error occurs.
-
size
Description copied from interface:FileSystem
Gets the size of the file system object at the given path.- Specified by:
size
in interfaceFileSystem
- Overrides:
size
in classFileSystemWrapper
- Parameters:
path
- Must be from this file system.- Throws:
IOException
- if an underlying I/O error occurs.
-
createFile
Description copied from interface:FileSystem
Atomically creates an empty file (must not have already existed).- Specified by:
createFile
in interfaceFileSystem
- Overrides:
createFile
in classFileSystemWrapper
- Returns:
- returns the path
- Throws:
IOException
- if an underlying I/O error occurs.
-
createDirectory
Description copied from interface:FileSystem
Atomically creates a directory (must not have already existed).- Specified by:
createDirectory
in interfaceFileSystem
- Overrides:
createDirectory
in classFileSystemWrapper
- Returns:
- returns the path
- Throws:
IOException
- if an underlying I/O error occurs.
-
lock
Description copied from interface:FileSystem
Locks 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:
lock
in interfaceFileSystem
- Overrides:
lock
in classFileSystemWrapper
- Throws:
IOException
- if an underlying I/O error occurs.- See Also:
-