git.iko.soy/typeable/bloodhound
on master help sign in
Fixed bulk tests
commitdd63d9c382ccc7691b6f6b372d7f694ad2490281 authorChris Allen <cma@bitemyapp.com> dateTue 6 Feb 2018, 22:05 (9 years ago) parent38ca931
2 files changed+22−5
src/Database/V5/Bloodhound/Client.hs+10−4 tests/V5/tests.hs+12−1
src/Database/V5/Bloodhound/Client.hs+10−4
@@ -215,6 +215,7 @@ dispatch dMethod url body = do
215215 $ setRequestIgnoreStatus
216216 $ initReq { method = dMethod
217217 , requestHeaders =
218+ -- "application/x-ndjson" for bulk
218219 ("Content-Type", "application/json") : requestHeaders initReq
219220 , requestBody = reqBody }
220221 -- req <- liftIO $ reqHook $ setRequestIgnoreStatus $ initReq { method = dMethod
@@ -856,7 +857,9 @@ deleteDocument (IndexName indexName)
856857-- >>> _ <- runBH' $ bulk stream
857858-- >>> _ <- runBH' $ refreshIndex testIndex
858859bulk :: MonadBH m => V.Vector BulkOperation -> m Reply
859−bulk bulkOps = bindM2 post url (return body)
860+bulk bulkOps = do
861+ liftIO $ print body
862+ bindM2 post url (return body)
860863 where url = joinPath ["_bulk"]
861864 body = Just $ encodeBulkOperations bulkOps
862865
@@ -868,9 +871,12 @@ bulk bulkOps = bindM2 post url (return body)
868871-- "\n{\"index\":{\"_type\":\"tweet\",\"_id\":\"2\",\"_index\":\"twitter\"}}\n{\"name\":\"blah\"}\n"
869872encodeBulkOperations :: V.Vector BulkOperation -> L.ByteString
870873encodeBulkOperations stream = collapsed where
871− blobs = fmap encodeBulkOperation stream
872− mashedTaters = mash (mempty :: Builder) blobs
873− collapsed = toLazyByteString $ mappend mashedTaters (byteString "\n")
874+ blobs =
875+ fmap encodeBulkOperation stream
876+ mashedTaters =
877+ mash (mempty :: Builder) blobs
878+ collapsed =
879+ toLazyByteString $ mappend mashedTaters (byteString "\n")
874880
875881mash :: Builder -> V.Vector L.ByteString -> Builder
876882mash = V.foldl' (\b x -> b `mappend` (byteString "\n") `mappend` (lazyByteString x))
tests/V5/tests.hs+12−1
@@ -435,7 +435,18 @@ withSnapshot srn sn = bracket_ alloc free
435435
436436newtype BulkTest =
437437 BulkTest { name :: Text }
438− deriving (Eq, Show, FromJSON, ToJSON)
438+ deriving (Eq, Show)
439+
440+instance ToJSON BulkTest where
441+ toJSON (BulkTest name) =
442+ object ["name" .= name]
443+
444+instance FromJSON BulkTest where
445+ parseJSON = withObject "BulkTest" parse
446+ where
447+ parse o = do
448+ t <- o .: "name"
449+ BulkTest <$> parseJSON t
439450
440451-- | Typeclass for "equal where it matters". Use this to specify
441452-- less-strict equivalence for things such as lists that can wind up