blobsets/tests/test_http.nim

72 lines
1.8 KiB
Nim
Raw Normal View History

2019-01-20 17:14:32 +01:00
import std/asyncdispatch, std/net, std/random, std/strutils, std/unittest
import ../src/blobsets, ../src/blobsets/filestores, ../src/blobsets/httpstores, ../src/blobsets/httpservers
2019-02-15 21:56:21 +01:00
let
port = (Port)rand(1 shl 15)
store = newFileStore("/tmp/store")
server = newHttpStoreServer(store)
asyncCheck server.serve(port)
2019-01-20 17:14:32 +01:00
2019-02-15 21:56:21 +01:00
let
url = "http://127.0.0.1:$1/" % $port
client = newHttpStore url
2019-01-20 17:14:32 +01:00
2019-02-15 21:56:21 +01:00
suite "Http store":
randomize()
2019-01-20 17:14:32 +01:00
var
blob: BlobId
size: BiggestInt
test "ingest":
2019-02-15 21:56:21 +01:00
(blob, size) = waitFor client.ingestFile("tests/test_http.nim")
2019-01-20 17:14:32 +01:00
test "dump":
for chunk in store.dumpBlob(blob):
2019-02-15 21:56:21 +01:00
discard chunk
test "ingest":
(blob, size) = waitFor client.ingestFile("tests/test_http.nim")
suite "store":
var
setId: SetId
bs: BlobSet
2019-02-15 21:56:21 +01:00
const count = 64
2019-02-15 21:56:21 +01:00
test "commit":
bs = newBlobSet()
2019-02-15 21:56:21 +01:00
for i in 1..count:
let
name = $i
blob = waitFor client.ingest(newString(i))
echo "insert ", blob, " ", i
2019-02-16 12:48:08 +01:00
bs = insert(bs, name, blob, i)
2019-02-15 21:56:21 +01:00
setId = commit(client, bs).setId
test "load":
bs = load(client, setId)
2019-02-15 21:56:21 +01:00
for i in 1..count:
let
name = $i
blob = blobHash newString(i)
2019-02-15 21:56:21 +01:00
other = bs.search(name)
#doAssert(other == blob)
2019-02-15 21:56:21 +01:00
for i in 1..count:
let
i = i and 0x8000
name = $i
apply(client, bs, name) do (id: BlobId; size: BiggestInt):
echo "inserted ", name, " - ", name.toKey
echo "applied ", name, " - ", ($(i xor 0x8000)).toKey
raiseAssert("apply succedded for a key not inserted")
test "random":
2019-02-16 12:48:08 +01:00
for i in 1..count:
store.randomApply(bs, i) do (id: BlobId; size: BiggestInt):
echo "randomApply: ", id, " ", size
let stream = store.openBlobStream(id, size, dataBlob)
close stream