Copyright | (c) 2014 Edward L. Blake |
---|---|
License | BSD-style |
Maintainer | Edward L. Blake <edwardlblake@gmail.com> |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell98 |
TestSequence monad for testing caching behaviour.
{-# LANGUAGE OverloadedStrings #-} module TestSequenceExample where import Caching.ExpiringCacheMap.HashECM (newECMForM, lookupECM, CacheSettings(..), consistentDuration) import qualified Caching.ExpiringCacheMap.Utils.TestSequence as TestSeq import qualified Data.ByteString.Char8 as BS test = do (TestSeq.TestSequenceState (_, events, _), return_value) <- TestSeq.runTestSequence test' (putStrLn . show . reverse) events return () where test' = do filecache <- newECMForM (consistentDuration 100 -- Duration between access and expiry time of each item, no state needed. (\state _id -> do number <- TestSeq.readNumber return (state, number))) (TestSeq.getCurrentTime >>= return) 12000 -- Time check frequency: (accumulator `mod` this_number) == 0. (CacheWithLRUList 6 -- Expected size of key-value map when removing elements. 6 -- Size of list when to remove items from key-value map. 12 -- Size of list when to compact ) TestSeq.newTestSVar TestSeq.enterTestSVar TestSeq.readTestSVar -- Use lookupECM whenever the contents of "file1" is needed. b <- lookupECM filecache ("file1" :: BS.ByteString) TestSeq.haveNumber b b <- lookupECM filecache "file1" b <- lookupECM filecache "file2" TestSeq.haveNumber b return b
>>>
test
[GetVar 3,ReadNumber 4,GetTime 7,PutVar 11,HaveNumber 4,GetVar 14,PutVar 17, GetVar 19,ReadNumber 20,GetTime 23,PutVar 27,HaveNumber 20]
Documentation
runTestSequence :: Show a => TestSequence b a -> IO (TestSequenceState b, a) Source
newTestSVar :: a -> TestSequence a (TestSVar a) Source
enterTestSVar :: TestSVar a -> (a -> TestSequence a (a, b)) -> TestSequence a b Source
readTestSVar :: TestSVar a -> TestSequence a a Source
readNumber :: TestSequence a Int Source
haveNumber :: Int -> TestSequence a () Source
data TestSequenceEvents Source
newtype TestSequenceState b Source
Show (TestSequenceState ct) |
newtype TestSequence b a Source
TestSequence (TestSequenceState b -> (TestSequenceState b, a)) |
Monad (TestSequence a) |