blockio-0.1.0.1: Perform batches of disk I/O operations.
Safe HaskellSafe-Inferred
LanguageGHC2021

System.FS.BlockIO.Sim

Description

Simulated instances of HasBlockIO and HasFS.

Synopsis

Implementation details

We include below some documentation about the effects of calling the interface functions on the simulated instance of the HasBlockIO interface.

IO context
For uniform behaviour across implementations, the simulation creates and stores a mocked IO context that has the open/closed behaviour that is specified by the interface.
close
Close the mocked context
submitIO
Submit a batch of I/O operations using serial I/O using a HasFS
hSetNoCache
No-op
hAdvise
No-op
hAllocate
No-op
tryLockFile
Simulate a lock by putting the lock state into the file contents
hSynchronise
No-op
synchroniseDirectory
No-op
createHardLink
Copy all file contents from the source path to the target path. Therefore, this is currently only correctly simulating hard links for immutable files.

Runners

runSimHasBlockIO :: (MonadSTM m, PrimMonad m, MonadCatch m, MonadMVar m) => MockFS -> (HasFS m HandleMock -> HasBlockIO m HandleMock -> m a) -> m (a, MockFS) Source #

runSimHasBlockIO mockFS action runs an action using a pair of simulated HasFS and HasBlockIO.

The pair of interfaces share the same mocked file system. The initial state of the mocked file system is set to mockFs. The final state of the mocked file system is returned with the result of action.

If you want to have access to the current state of the mocked file system, use simHasBlockIO instead.

runSimErrorHasBlockIO :: (MonadSTM m, PrimMonad m, MonadCatch m, MonadMVar m) => MockFS -> Errors -> (HasFS m HandleMock -> HasBlockIO m HandleMock -> m a) -> m (a, MockFS, Errors) Source #

runSimErrorHasBlockIO mockFS errors action runs an action using a pair of simulated HasFS and HasBlockIO that allow fault injection.

The pair of interfaces share the same mocked file system. The initial state of the mocked file system is set to mockFs. The final state of the mocked file system is returned with the result of action.

The pair of interfaces share the same stream of errors. The initial state of the stream of errors is set to errors. The final state of the stream of errors is returned with the result of action.

If you want to have access to the current state of the mocked file system or stream of errors, use simErrorHasBlockIO instead.

Initialisation

simHasBlockIO :: (MonadCatch m, MonadMVar m, PrimMonad m, MonadSTM m) => StrictTMVar m MockFS -> m (HasFS m HandleMock, HasBlockIO m HandleMock) Source #

simHasBlockIO mockFsVar creates a pair of simulated HasFS and HasBlockIO.

The pair of interfaces share the same mocked file system, which is stored in mockFsVar. The current state of the mocked file system can be accessed by the user by reading mockFsVar, but note that the user should not leave mockFsVar empty.

simHasBlockIO' :: (MonadCatch m, MonadMVar m, PrimMonad m, MonadSTM m) => MockFS -> m (HasFS m HandleMock, HasBlockIO m HandleMock) Source #

simHasBlockIO mockFs creates a pair of simulated HasFS and HasBlockIO that allow fault injection.

The pair of interfaces share the same mocked file system. The initial state of the mocked file system is set to mockFs.

If you want to have access to the current state of the mocked file system, use simHasBlockIO instead.

simErrorHasBlockIO :: forall m. (MonadCatch m, MonadMVar m, PrimMonad m, MonadSTM m) => StrictTMVar m MockFS -> StrictTVar m Errors -> m (HasFS m HandleMock, HasBlockIO m HandleMock) Source #

simErrorHasBlockIO mockFsVar errorsVar creates a pair of simulated HasFS and HasBlockIO that allow fault injection.

The pair of interfaces share the same mocked file system, which is stored in mockFsVar. The current state of the mocked file system can be accessed by the user by reading mockFsVar, but note that the user should not leave mockFsVar empty.

The pair of interfaces share the same stream of errors, which is stored in errorsVar. The current state of the stream of errors can be accessed by the user by reading errorsVar.

simErrorHasBlockIO' :: (MonadCatch m, MonadMVar m, PrimMonad m, MonadSTM m) => MockFS -> Errors -> m (HasFS m HandleMock, HasBlockIO m HandleMock) Source #

simErrorHasBlockIO mockFs errors creates a pair of simulated HasFS and HasBlockIO that allow fault injection.

The pair of interfaces share the same mocked file system. The initial state of the mocked file system is set to mockFs.

The pair of interfaces share the same stream of errors. The initial state of the stream of errors is set to errors.

If you want to have access to the current state of the mocked file system or stream of errors, use simErrorHasBlockIO instead.

Unsafe

unsafeFromHasFS :: forall m. (MonadCatch m, MonadMVar m, PrimMonad m) => HasFS m HandleMock -> m (HasBlockIO m HandleMock) Source #

Simulate a HasBlockIO using the given HasFS.

Unsafe

You will probably want to use one of the safe functions like runSimHasBlockIO or simErrorHasBlockIO instead.

Only a simulated HasFS, like the simHasFS and simErrorHasFS simulations, should be passed to unsafeFromHasFS. Technically, one could pass a HasFS for the real file system, but then the resulting HasBlockIO would contain a mix of simulated functions and real functions, which is probably not what you want.