Skip to content

Commit c3afbe0

Browse files
committed
Use the unified class instead of the Normal class in class-based tests
Having renamed the relevant module in the previous commit, we now switch to using the unified class instead of the `Normal` class.
1 parent f41803c commit c3afbe0

File tree

2 files changed

+44
-41
lines changed

2 files changed

+44
-41
lines changed

test/Database/LSMTree/Class.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Data.Kind (Constraint, Type)
1717
import Data.Typeable (Proxy (..))
1818
import qualified Data.Vector as V
1919
import Database.LSMTree as Types (LookupResult (..), QueryResult (..),
20-
ResolveValue, Update (..))
20+
ResolveAsFirst (..), ResolveValue, Update (..))
2121
import qualified Database.LSMTree as R
2222
import Database.LSMTree.Class.Common as Common
2323

test/Test/Database/LSMTree/Class.hs

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ import qualified Data.Proxy as Proxy
1818
import qualified Data.Vector as V
1919
import qualified Data.Vector.Algorithms.Merge as VA
2020
import Data.Word (Word64)
21-
import Database.LSMTree.Class.Normal hiding (withTableDuplicate,
22-
withTableFromSnapshot, withTableNew)
23-
import qualified Database.LSMTree.Class.Normal as Class
21+
import qualified Database.LSMTree as R
22+
import Database.LSMTree.Class
2423
import Database.LSMTree.Common (mkSnapshotName)
2524
import Database.LSMTree.Extras.Generators ()
26-
import qualified Database.LSMTree.Model.IO.Normal as ModelIO
27-
import qualified Database.LSMTree.Normal as R
25+
import qualified Database.LSMTree.Model.IO as ModelIO
2826
import qualified System.FS.API as FS
2927
import Test.QuickCheck.Monadic (monadicIO, monitor, run)
3028
import Test.Tasty (TestName, TestTree, testGroup)
@@ -33,7 +31,7 @@ import Test.Tasty.QuickCheck hiding (label)
3331
import qualified Test.Util.FS as FS
3432

3533
tests :: TestTree
36-
tests = testGroup "Test.Database.LSMTree.Class.Normal"
34+
tests = testGroup "Test.Database.LSMTree.Class"
3735
[ testGroup "Model" $ zipWith ($) (props tbl1) expectFailures1
3836
, testGroup "Real" $ zipWith ($) (props tbl2) expectFailures2
3937
]
@@ -98,7 +96,8 @@ type Blob = BS.ByteString
9896

9997
newtype Value = Value BS.ByteString
10098
deriving stock (Eq, Show)
101-
deriving newtype (Arbitrary, R.SerialiseValue)
99+
deriving newtype (Arbitrary, SerialiseValue)
100+
deriving ResolveValue via ResolveAsFirst Value
102101

103102
label :: SnapshotLabel
104103
label = SnapshotLabel "Word64 ByteString ByteString"
@@ -111,18 +110,18 @@ data Setup h m = Setup {
111110
}
112111

113112
-- | create session, table, and populate it with some data.
114-
withTableNew :: forall h m a.
113+
withSessionAndTableNew :: forall h m a.
115114
( IsTable h
116115
, IOLike m
117116
)
118117
=> Setup h m
119118
-> [(Key, Update Value Blob)]
120119
-> (Session h m -> h m Key Value Blob -> m a)
121120
-> m a
122-
withTableNew Setup{..} ups action =
121+
withSessionAndTableNew Setup{..} ups action =
123122
testWithSessionArgs $ \args ->
124123
withSession args $ \sesh ->
125-
Class.withTableNew sesh testTableConfig $ \table -> do
124+
withTableNew sesh testTableConfig $ \table -> do
126125
updates table (V.fromList ups)
127126
action sesh table
128127

@@ -153,6 +152,7 @@ lookupsWithBlobs :: forall h m k v b.
153152
, SerialiseKey k
154153
, SerialiseValue v
155154
, SerialiseValue b
155+
, ResolveValue v
156156
, C k v b
157157
)
158158
=> h m k v b
@@ -169,6 +169,7 @@ rangeLookupWithBlobs :: forall h m k v b.
169169
, SerialiseKey k
170170
, SerialiseValue v
171171
, SerialiseValue b
172+
, ResolveValue v
172173
, C k v b
173174
)
174175
=> h m k v b
@@ -185,6 +186,7 @@ readCursorWithBlobs :: forall h m k v b proxy.
185186
, SerialiseKey k
186187
, SerialiseValue v
187188
, SerialiseValue b
189+
, ResolveValue v
188190
, C k v b
189191
)
190192
=> proxy h
@@ -202,6 +204,7 @@ readCursorAllWithBlobs :: forall h m k v b proxy.
202204
, SerialiseKey k
203205
, SerialiseValue v
204206
, SerialiseValue b
207+
, ResolveValue v
205208
, C k v b
206209
)
207210
=> proxy h
@@ -233,7 +236,7 @@ prop_lookupInsert ::
233236
=> Proxy h -> [(Key, Update Value Blob)]
234237
-> Key -> Value -> Property
235238
prop_lookupInsert h ups k v = ioProperty $ do
236-
withTableNew h ups $ \ses hdl -> do
239+
withSessionAndTableNew h ups $ \ses hdl -> do
237240

238241
-- the main dish
239242
inserts hdl (V.singleton (k, v, Nothing))
@@ -247,7 +250,7 @@ prop_lookupInsertElse ::
247250
=> Proxy h -> [(Key, Update Value Blob)]
248251
-> Key -> Value -> [Key] -> Property
249252
prop_lookupInsertElse h ups k v testKeys = ioProperty $ do
250-
withTableNew h ups $ \ses hdl -> do
253+
withSessionAndTableNew h ups $ \ses hdl -> do
251254

252255
let testKeys' = V.fromList $ filter (/= k) testKeys
253256
res1 <- lookupsWithBlobs hdl ses testKeys'
@@ -262,7 +265,7 @@ prop_lookupDelete ::
262265
=> Proxy h -> [(Key, Update Value Blob)]
263266
-> Key -> Property
264267
prop_lookupDelete h ups k = ioProperty $ do
265-
withTableNew h ups $ \ses hdl -> do
268+
withSessionAndTableNew h ups $ \ses hdl -> do
266269
deletes hdl (V.singleton k)
267270
res <- lookupsWithBlobs hdl ses (V.singleton k)
268271
return $ res === V.singleton NotFound
@@ -273,7 +276,7 @@ prop_lookupDeleteElse ::
273276
=> Proxy h -> [(Key, Update Value Blob)]
274277
-> Key -> [Key] -> Property
275278
prop_lookupDeleteElse h ups k testKeys = ioProperty $ do
276-
withTableNew h ups $ \ses hdl -> do
279+
withSessionAndTableNew h ups $ \ses hdl -> do
277280

278281
let testKeys' = V.fromList $ filter (/= k) testKeys
279282
res1 <- lookupsWithBlobs hdl ses testKeys'
@@ -288,7 +291,7 @@ prop_insertInsert ::
288291
=> Proxy h -> [(Key, Update Value Blob)]
289292
-> Key -> Value -> Value -> Property
290293
prop_insertInsert h ups k v1 v2 = ioProperty $ do
291-
withTableNew h ups $ \ses hdl -> do
294+
withSessionAndTableNew h ups $ \ses hdl -> do
292295
inserts hdl (V.fromList [(k, v1, Nothing), (k, v2, Nothing)])
293296
res <- lookupsWithBlobs hdl ses (V.singleton k)
294297
return $ res === V.singleton (Found v2)
@@ -299,7 +302,7 @@ prop_insertCommutes ::
299302
=> Proxy h -> [(Key, Update Value Blob)]
300303
-> Key -> Value -> Key -> Value -> Property
301304
prop_insertCommutes h ups k1 v1 k2 v2 = k1 /= k2 ==> ioProperty do
302-
withTableNew h ups $ \ses hdl -> do
305+
withSessionAndTableNew h ups $ \ses hdl -> do
303306
inserts hdl (V.fromList [(k1, v1, Nothing), (k2, v2, Nothing)])
304307

305308
res <- lookupsWithBlobs hdl ses (V.fromList [k1,k2])
@@ -317,7 +320,7 @@ prop_readCursorSorted ::
317320
-> CursorReadSchedule
318321
-> Property
319322
prop_readCursorSorted h ups offset ns = ioProperty $ do
320-
withTableNew h ups $ \ses hdl -> do
323+
withSessionAndTableNew h ups $ \ses hdl -> do
321324
res <- withCursor offset hdl $ \cursor -> do
322325
V.concat <$> readCursorAllWithBlobs (Proxy.Proxy @h) ses cursor ns
323326
let keys = map queryResultKey (V.toList res)
@@ -331,7 +334,7 @@ prop_readCursorNumResults ::
331334
-> CursorReadSchedule
332335
-> Property
333336
prop_readCursorNumResults h ups offset ns = ioProperty $ do
334-
withTableNew h ups $ \ses hdl -> do
337+
withSessionAndTableNew h ups $ \ses hdl -> do
335338
res <- withCursor offset hdl $ \cursor -> do
336339
readCursorAllWithBlobs (Proxy.Proxy @h) ses cursor ns
337340
let elemsRead = map V.length res
@@ -347,7 +350,7 @@ prop_readCursorInsert ::
347350
-> CursorReadSchedule
348351
-> Key -> Value -> Property
349352
prop_readCursorInsert h ups ns k v = ioProperty $ do
350-
withTableNew h ups $ \ses hdl -> do
353+
withSessionAndTableNew h ups $ \ses hdl -> do
351354
inserts hdl (V.singleton (k, v, Nothing))
352355
res <- withCursor Nothing hdl $ \cursor ->
353356
V.concat <$> readCursorAllWithBlobs (Proxy.Proxy @h) ses cursor ns
@@ -361,7 +364,7 @@ prop_readCursorDelete ::
361364
-> CursorReadSchedule
362365
-> Key -> Property
363366
prop_readCursorDelete h ups ns k = ioProperty $ do
364-
withTableNew h ups $ \ses hdl -> do
367+
withSessionAndTableNew h ups $ \ses hdl -> do
365368
deletes hdl (V.singleton k)
366369
res <- withCursor Nothing hdl $ \cursor -> do
367370
V.concat <$> readCursorAllWithBlobs (Proxy.Proxy @h) ses cursor ns
@@ -375,7 +378,7 @@ prop_readCursorDeleteElse ::
375378
-> CursorReadSchedule
376379
-> [(Key, Update Value Blob)] -> Property
377380
prop_readCursorDeleteElse h ups offset ns ups2 = ioProperty $ do
378-
withTableNew h ups $ \ses hdl -> do
381+
withSessionAndTableNew h ups $ \ses hdl -> do
379382
res1 <- withCursor offset hdl $ \cursor -> do
380383
V.concat <$> readCursorAllWithBlobs (Proxy.Proxy @h) ses cursor ns
381384
updates hdl (V.fromList ups2)
@@ -393,7 +396,7 @@ prop_readCursorStableView ::
393396
-> CursorReadSchedule
394397
-> [(Key, Update Value Blob)] -> Property
395398
prop_readCursorStableView h ups offset ns ups2 = ioProperty $ do
396-
withTableNew h ups $ \ses hdl -> do
399+
withSessionAndTableNew h ups $ \ses hdl -> do
397400
res1 <- withCursor offset hdl $ \cursor -> do
398401
readCursorAllWithBlobs (Proxy.Proxy @h) ses cursor ns
399402
res2 <- withCursor offset hdl $ \cursor -> do
@@ -409,7 +412,7 @@ prop_readCursorOffset ::
409412
-> CursorReadSchedule
410413
-> Property
411414
prop_readCursorOffset h ups offset ns = ioProperty $ do
412-
withTableNew h ups $ \ses hdl -> do
415+
withSessionAndTableNew h ups $ \ses hdl -> do
413416
res1 <- withCursor (Just offset) hdl $ \cursor -> do
414417
V.concat <$> readCursorAllWithBlobs (Proxy.Proxy @h) ses cursor ns
415418
res2 <- withCursor Nothing hdl $ \cursor -> do
@@ -441,7 +444,7 @@ prop_lookupRangeLikeLookups ::
441444
-> Range Key
442445
-> Property
443446
prop_lookupRangeLikeLookups h ups r = ioProperty $ do
444-
withTableNew h ups $ \ses hdl -> do
447+
withSessionAndTableNew h ups $ \ses hdl -> do
445448
res1 <- rangeLookupWithBlobs hdl ses r
446449

447450
let testKeys = V.fromList $ nubSort $ filter (evalRange r) $ map fst ups
@@ -459,7 +462,7 @@ prop_insertLookupRange ::
459462
=> Proxy h -> [(Key, Update Value Blob)]
460463
-> Key -> Value -> Range Key -> Property
461464
prop_insertLookupRange h ups k v r = ioProperty $ do
462-
withTableNew h ups $ \ses hdl -> do
465+
withSessionAndTableNew h ups $ \ses hdl -> do
463466

464467
res <- rangeLookupWithBlobs hdl ses r
465468

@@ -490,7 +493,7 @@ prop_lookupInsertBlob ::
490493
=> Proxy h -> [(Key, Update Value Blob)]
491494
-> Key -> Value -> Blob -> Property
492495
prop_lookupInsertBlob h ups k v blob = ioProperty $ do
493-
withTableNew h ups $ \ses hdl -> do
496+
withSessionAndTableNew h ups $ \ses hdl -> do
494497

495498
-- the main dish
496499
inserts hdl (V.singleton (k, v, Just blob))
@@ -504,7 +507,7 @@ prop_insertInsertBlob ::
504507
=> Proxy h -> [(Key, Update Value Blob)]
505508
-> Key -> Value -> Value -> Maybe Blob -> Maybe Blob -> Property
506509
prop_insertInsertBlob h ups k v1 v2 mblob1 mblob2 = ioProperty $ do
507-
withTableNew h ups $ \ses hdl -> do
510+
withSessionAndTableNew h ups $ \ses hdl -> do
508511
inserts hdl (V.fromList [(k, v1, mblob1), (k, v2, mblob2)])
509512
res <- lookupsWithBlobs hdl ses (V.singleton k)
510513
return $ res === case mblob2 of
@@ -518,7 +521,7 @@ prop_insertCommutesBlob ::
518521
-> Key -> Value -> Maybe Blob
519522
-> Key -> Value -> Maybe Blob -> Property
520523
prop_insertCommutesBlob h ups k1 v1 mblob1 k2 v2 mblob2 = k1 /= k2 ==> ioProperty do
521-
withTableNew h ups $ \ses hdl -> do
524+
withSessionAndTableNew h ups $ \ses hdl -> do
522525
inserts hdl (V.fromList [(k1, v1, mblob1), (k2, v2, mblob2)])
523526

524527
res <- lookupsWithBlobs hdl ses $ V.fromList [k1,k2]
@@ -537,7 +540,7 @@ prop_updatesMayInvalidateBlobRefs ::
537540
-> Property
538541
prop_updatesMayInvalidateBlobRefs h ups k1 v1 blob1 ups' = monadicIO $ do
539542
(res, blobs, res') <- run $ do
540-
withTableNew h ups $ \ses hdl -> do
543+
withSessionAndTableNew h ups $ \ses hdl -> do
541544
inserts hdl (V.singleton (k1, v1, Just blob1))
542545
res <- lookups hdl (V.singleton k1)
543546
blobs <- getCompose <$> retrieveBlobsTrav (Proxy.Proxy @h) ses (Compose res)
@@ -575,7 +578,7 @@ prop_snapshotNoChanges :: forall h.
575578
=> Proxy h -> [(Key, Update Value Blob)]
576579
-> [(Key, Update Value Blob)] -> [Key] -> Property
577580
prop_snapshotNoChanges h ups ups' testKeys = ioProperty $ do
578-
withTableNew h ups $ \ses hdl1 -> do
581+
withSessionAndTableNew h ups $ \ses hdl1 -> do
579582

580583
res <- lookupsWithBlobs hdl1 ses $ V.fromList testKeys
581584

@@ -584,7 +587,7 @@ prop_snapshotNoChanges h ups ups' testKeys = ioProperty $ do
584587
createSnapshot label name hdl1
585588
updates hdl1 (V.fromList ups')
586589

587-
Class.withTableFromSnapshot @h ses label name$ \hdl2 -> do
590+
withTableFromSnapshot @h ses label name$ \hdl2 -> do
588591

589592
res' <- lookupsWithBlobs hdl2 ses $ V.fromList testKeys
590593

@@ -597,12 +600,12 @@ prop_snapshotNoChanges2 :: forall h.
597600
=> Proxy h -> [(Key, Update Value Blob)]
598601
-> [(Key, Update Value Blob)] -> [Key] -> Property
599602
prop_snapshotNoChanges2 h ups ups' testKeys = ioProperty $ do
600-
withTableNew h ups $ \sess hdl0 -> do
603+
withSessionAndTableNew h ups $ \sess hdl0 -> do
601604
let name = fromMaybe (error "invalid name") $ mkSnapshotName "foo"
602605
createSnapshot label name hdl0
603606

604-
Class.withTableFromSnapshot @h sess label name $ \hdl1 ->
605-
Class.withTableFromSnapshot @h sess label name $ \hdl2 -> do
607+
withTableFromSnapshot @h sess label name $ \hdl1 ->
608+
withTableFromSnapshot @h sess label name $ \hdl2 -> do
606609

607610
res <- lookupsWithBlobs hdl1 sess $ V.fromList testKeys
608611
updates hdl1 (V.fromList ups')
@@ -623,8 +626,8 @@ prop_dupInsertInsert ::
623626
=> Proxy h -> [(Key, Update Value Blob)]
624627
-> Key -> Value -> Value -> [Key] -> Property
625628
prop_dupInsertInsert h ups k v1 v2 testKeys = ioProperty $ do
626-
withTableNew h ups $ \sess hdl1 -> do
627-
Class.withTableDuplicate hdl1 $ \hdl2 -> do
629+
withSessionAndTableNew h ups $ \sess hdl1 -> do
630+
withTableDuplicate hdl1 $ \hdl2 -> do
628631

629632
inserts hdl1 (V.fromList [(k, v1, Nothing), (k, v2, Nothing)])
630633
inserts hdl2 (V.fromList [(k, v2, Nothing)])
@@ -639,8 +642,8 @@ prop_dupInsertCommutes ::
639642
=> Proxy h -> [(Key, Update Value Blob)]
640643
-> Key -> Value -> Key -> Value -> [Key] -> Property
641644
prop_dupInsertCommutes h ups k1 v1 k2 v2 testKeys = k1 /= k2 ==> ioProperty do
642-
withTableNew h ups $ \sess hdl1 -> do
643-
Class.withTableDuplicate hdl1 $ \hdl2 -> do
645+
withSessionAndTableNew h ups $ \sess hdl1 -> do
646+
withTableDuplicate hdl1 $ \hdl2 -> do
644647

645648
inserts hdl1 (V.fromList [(k1, v1, Nothing), (k2, v2, Nothing)])
646649
inserts hdl2 (V.fromList [(k2, v2, Nothing), (k1, v1, Nothing)])
@@ -655,11 +658,11 @@ prop_dupNoChanges ::
655658
=> Proxy h -> [(Key, Update Value Blob)]
656659
-> [(Key, Update Value Blob)] -> [Key] -> Property
657660
prop_dupNoChanges h ups ups' testKeys = ioProperty $ do
658-
withTableNew h ups $ \sess hdl1 -> do
661+
withSessionAndTableNew h ups $ \sess hdl1 -> do
659662

660663
res <- lookupsWithBlobs hdl1 sess $ V.fromList testKeys
661664

662-
Class.withTableDuplicate hdl1 $ \hdl2 -> do
665+
withTableDuplicate hdl1 $ \hdl2 -> do
663666
updates hdl2 (V.fromList ups')
664667

665668
-- lookup hdl1 again.

0 commit comments

Comments
 (0)