bloodhound-1.0.0.0: tests/Test/ScanScrollSpec.hs
module Test.ScanScrollSpec (spec) where
import Database.Bloodhound.Client qualified as Client (clearScroll, getInitialScroll)
import TestsUtils.Common
import TestsUtils.Import
import Prelude
spec :: Spec
spec =
describe "Scan & Scroll API" $ do
it "returns documents using the scan&scroll API" $
withTestEnv $ do
_ <- insertData
_ <- insertOther
let search =
( mkSearch
(Just $ MatchAllQuery Nothing)
Nothing
)
{ size = Size 1
}
regular_search <- searchTweet search
scan_search' <- scanSearch testIndex search :: BH IO [Hit Tweet]
let scan_search = map hitSource scan_search'
liftIO $
regular_search `shouldBe` Right exampleTweet -- Check that the size restrtiction is being honored
liftIO $
scan_search `shouldMatchList` [Just exampleTweet, Just otherTweet]
it "clearScroll frees a scroll context without error" $
withTestEnv $ do
_ <- insertData
_ <- insertOther
let search =
( mkSearch
(Just $ MatchAllQuery Nothing)
Nothing
)
{ size = Size 1
}
initial <- Client.getInitialScroll testIndex search :: BH IO (ParsedEsResponse (SearchResult Tweet))
case initial of
Left e ->
liftIO $
expectationFailure ("getInitialScroll failed: " <> show e)
Right SearchResult {scrollId = Just sid} -> do
resp <- Client.clearScroll sid
liftIO $ do
clearScrollSucceeded resp `shouldBe` True
clearScrollNumFreed resp `shouldSatisfy` (>= 1)
Right _ ->
liftIO $
expectationFailure "getInitialScroll returned no scrollId"