Skip to content

Commit

Permalink
Adapt tests to new haskey-btree api
Browse files Browse the repository at this point in the history
  • Loading branch information
hverr committed Apr 8, 2018
1 parent cda0e86 commit 7f7eea0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions example/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import Control.Concurrent.Async (async, wait)
import Control.Monad (void, replicateM)
import Control.Monad.Catch (bracket_, finally)

import Data.BTree.Impure (Tree, toList, insertTree)
import Data.BTree.Impure (Tree)
import Data.ByteString (ByteString)
import Data.Int (Int32)
import Data.Text.Encoding (encodeUtf8)
import qualified Data.BTree.Impure as Tree
import qualified Data.BTree.Impure as B
import qualified Data.Text as Text

import Database.Haskey.Alloc.Concurrent (ConcurrentDb,
Expand Down Expand Up @@ -64,22 +64,22 @@ inMemoryMain root = do
where
bs = encodeUtf8 $ Text.pack (show i)

tx tree = insertTree i bs tree >>= commit_
tx tree = B.insert i bs tree >>= commit_

reader :: MemoryFiles FilePath
-> ConcurrentDb Root
-> Int
-> IO ()
reader files db delay = void $ replicateM 10 $ do
threadDelay delay
runDatabase files $ transactReadOnly toList db
runDatabase files $ transactReadOnly B.toList db

openOrCreate :: MemoryFiles FilePath
-> IO (ConcurrentDb Root)
openOrCreate store = runDatabase store $ do
maybeDb <- openConcurrentDb handles
case maybeDb of
Nothing -> createConcurrentDb handles Tree.empty
Nothing -> createConcurrentDb handles B.empty
Just db -> return db

runDatabase :: MemoryFiles FilePath
Expand Down Expand Up @@ -111,20 +111,20 @@ fileMain root = bracket_ (runDatabase $ lockConcurrentDb handles)
where
bs = encodeUtf8 $ Text.pack (show i)

tx tree = insertTree i bs tree >>= commit_
tx tree = B.insert i bs tree >>= commit_

reader :: ConcurrentDb Root
-> Int
-> IO ()
reader db delay = void $ replicateM 10 $ do
threadDelay delay
runDatabase $ transactReadOnly toList db
runDatabase $ transactReadOnly B.toList db

openOrCreate :: IO (ConcurrentDb Root)
openOrCreate = runDatabase $ do
maybeDb <- openConcurrentDb handles
case maybeDb of
Nothing -> createConcurrentDb handles Tree.empty
Nothing -> createConcurrentDb handles B.empty
Just db -> return db

runDatabase :: Monad m
Expand Down
14 changes: 7 additions & 7 deletions tests/Integration/WriteOpenRead/Concurrent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import System.IO.Temp (createTempDirectory)
import Data.BTree.Alloc.Class
import Data.BTree.Impure
import Data.BTree.Primitives
import qualified Data.BTree.Impure as Tree
import qualified Data.BTree.Impure as B

import Database.Haskey.Alloc.Concurrent
import Database.Haskey.Store.File
Expand Down Expand Up @@ -90,7 +90,7 @@ prop_memory_backend = forAllM (genTestSequence False) $ \(TestSequence txs) -> d
++ "\n got: " ++ show read'

create :: MemoryFiles String -> IO (ConcurrentDb Root')
create = runMemoryStoreT (createConcurrentDb hnds Tree.empty) config
create = runMemoryStoreT (createConcurrentDb hnds B.empty) config
where
hnds = concurrentHandles ""

Expand Down Expand Up @@ -140,7 +140,7 @@ prop_file_backend = forAllM (genTestSequence True) $ \(TestSequence txs) -> do

create :: ConcurrentHandles
-> IO (ConcurrentDb Root')
create hnds = runFileStoreT (createConcurrentDb hnds Tree.empty) config
create hnds = runFileStoreT (createConcurrentDb hnds B.empty) config


openAndRead :: ConcurrentDb Root'
Expand All @@ -164,9 +164,9 @@ writeTransaction :: (MonadIO m, MonadMask m, ConcurrentMetaStoreM m, Key k, Valu
writeTransaction (TestTransaction txType actions) =
transaction
where
writeAction (Insert k v) = insertTree k v
writeAction (Replace k v) = insertTree k v
writeAction (Delete k) = deleteTree k
writeAction (Insert k v) = B.insert k v
writeAction (Replace k v) = B.insert k v
writeAction (Delete k) = B.delete k
writeAction ThrowException = const (throwM TestException)

transaction = transact_ $
Expand All @@ -181,7 +181,7 @@ writeTransaction (TestTransaction txType actions) =
readAll :: (MonadIO m, MonadMask m, ConcurrentMetaStoreM m, Key k, Value v)
=> ConcurrentDb (Tree k v)
-> m [(k, v)]
readAll = transactReadOnly Tree.toList
readAll = transactReadOnly B.toList

--------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion tests/Properties/Store/Page.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import qualified Data.ByteString.Lazy as BL
import qualified Data.Map as M
import qualified Data.Vector as V

import Data.BTree.Impure.Structures
import Data.BTree.Impure.Internal.Structures
import Data.BTree.Primitives

import Database.Haskey.Store.Page
Expand Down

0 comments on commit 7f7eea0

Please sign in to comment.