Fixed bulk tests

This commit is contained in:
Chris Allen 2018-02-06 22:05:48 -06:00
parent 38ca931dd9
commit dd63d9c382
2 changed files with 22 additions and 5 deletions

View File

@ -215,6 +215,7 @@ dispatch dMethod url body = do
$ setRequestIgnoreStatus
$ initReq { method = dMethod
, requestHeaders =
-- "application/x-ndjson" for bulk
("Content-Type", "application/json") : requestHeaders initReq
, requestBody = reqBody }
-- req <- liftIO $ reqHook $ setRequestIgnoreStatus $ initReq { method = dMethod
@ -856,7 +857,9 @@ deleteDocument (IndexName indexName)
-- >>> _ <- runBH' $ bulk stream
-- >>> _ <- runBH' $ refreshIndex testIndex
bulk :: MonadBH m => V.Vector BulkOperation -> m Reply
bulk bulkOps = bindM2 post url (return body)
bulk bulkOps = do
liftIO $ print body
bindM2 post url (return body)
where url = joinPath ["_bulk"]
body = Just $ encodeBulkOperations bulkOps
@ -868,9 +871,12 @@ bulk bulkOps = bindM2 post url (return body)
-- "\n{\"index\":{\"_type\":\"tweet\",\"_id\":\"2\",\"_index\":\"twitter\"}}\n{\"name\":\"blah\"}\n"
encodeBulkOperations :: V.Vector BulkOperation -> L.ByteString
encodeBulkOperations stream = collapsed where
blobs = fmap encodeBulkOperation stream
mashedTaters = mash (mempty :: Builder) blobs
collapsed = toLazyByteString $ mappend mashedTaters (byteString "\n")
blobs =
fmap encodeBulkOperation stream
mashedTaters =
mash (mempty :: Builder) blobs
collapsed =
toLazyByteString $ mappend mashedTaters (byteString "\n")
mash :: Builder -> V.Vector L.ByteString -> Builder
mash = V.foldl' (\b x -> b `mappend` (byteString "\n") `mappend` (lazyByteString x))

View File

@ -435,7 +435,18 @@ withSnapshot srn sn = bracket_ alloc free
newtype BulkTest =
BulkTest { name :: Text }
deriving (Eq, Show, FromJSON, ToJSON)
deriving (Eq, Show)
instance ToJSON BulkTest where
toJSON (BulkTest name) =
object ["name" .= name]
instance FromJSON BulkTest where
parseJSON = withObject "BulkTest" parse
where
parse o = do
t <- o .: "name"
BulkTest <$> parseJSON t
-- | Typeclass for "equal where it matters". Use this to specify
-- less-strict equivalence for things such as lists that can wind up