33
44module Test.Database.LSMTree.UnitTests (tests ) where
55
6+ import Control.Exception (Exception , bracket , try )
7+ import Control.Monad (void )
68import Control.Tracer (nullTracer )
79import Data.ByteString (ByteString )
810import qualified Data.ByteString.Char8 as BS
@@ -11,13 +13,10 @@ import Data.List.NonEmpty (NonEmpty (..))
1113import qualified Data.Map as Map
1214import qualified Data.Vector as V
1315import Data.Word
14- import qualified System.FS.API as FS
15-
1616import Database.LSMTree as R
17-
18- import Control.Exception (Exception , bracket , try )
1917import Database.LSMTree.Extras.Generators ()
2018import Database.LSMTree.Internal.Serialise (SerialisedKey )
19+ import qualified System.FS.API as FS
2120import qualified Test.QuickCheck.Arbitrary as QC
2221import qualified Test.QuickCheck.Gen as QC
2322import Test.Tasty (TestTree , testGroup )
@@ -222,24 +221,20 @@ unit_union_credit_0 =
222221unit_union_blobref_invalidation :: Assertion
223222unit_union_blobref_invalidation =
224223 withTempIOHasBlockIO " test" $ \ hfs hbio ->
225- withOpenSession nullTracer hfs hbio testSalt (FS. mkFsPath [] ) $ \ sess -> do
226- t1 <- newTableWith @ _ @ Key1 @ Value1 @ Blob1 config sess
224+ withOpenSession nullTracer hfs hbio testSalt (FS. mkFsPath [] ) $ \ sess ->
225+ withTableWith config sess $ \ t1 -> do
227226 for_ ([0 .. 99 ] :: [Word64 ]) $ \ i ->
228227 inserts t1 [(Key1 i, Value1 i, Just (Blob1 i))]
229- t2 <- t1 `union` t1
230-
231- -- do lookups on the union table (the result contains blob refs)
232- res <- lookups t2 (Key1 <$> [0 .. 99 ])
228+ withUnion t1 t1 $ \ t2 -> do
229+ -- do lookups on the union table (the result contains blob refs)
230+ res <- lookups t2 (Key1 <$> [0 .. 99 ])
233231
234- -- progress original table (supplying merge credits would be most direct),
235- -- so merges complete
236- inserts t1 (fmap (\ i -> (Key1 i, Value1 i, Nothing )) [1000 .. 2000 ])
237- -- closeTable it, so it doesn't hold open extra references
238- closeTable t1
232+ -- progress original table (supplying merge credits would be most direct),
233+ -- so merges complete
234+ inserts t1 (fmap (\ i -> (Key1 i, Value1 i, Nothing )) [1000 .. 2000 ])
239235
240- -- try to resolve the blob refs we obtained earlier
241- _blobs <- retrieveBlobs sess (V. mapMaybe R. getBlob res)
242- pure ()
236+ -- try to resolve the blob refs we obtained earlier
237+ void $ retrieveBlobs sess (V. mapMaybe R. getBlob res)
243238 where
244239 config = defaultTableConfig {
245240 confWriteBufferAlloc = AllocNumEntries 4
0 commit comments