2022-03-03 03:30:42 +11:00
|
|
|
import pkg/chronos
|
|
|
|
import pkg/asynctest
|
|
|
|
import pkg/libp2p
|
|
|
|
import pkg/stew/byteutils
|
|
|
|
import pkg/questionable/results
|
2022-05-19 14:56:03 -05:00
|
|
|
import pkg/codex/stores/cachestore
|
2023-03-13 14:48:09 +01:00
|
|
|
import pkg/codex/stores/memorystore
|
2022-05-19 14:56:03 -05:00
|
|
|
import pkg/codex/chunker
|
2022-03-03 03:30:42 +11:00
|
|
|
|
2022-12-02 18:00:55 -06:00
|
|
|
import ./commonstoretests
|
2022-03-03 03:30:42 +11:00
|
|
|
import ../helpers
|
|
|
|
|
2022-07-22 18:38:49 -05:00
|
|
|
suite "Cache Store":
|
2022-03-03 03:30:42 +11:00
|
|
|
var
|
2023-03-13 14:48:09 +01:00
|
|
|
newBlock: Block
|
|
|
|
backingStore: MockBlockStore
|
2022-03-03 03:30:42 +11:00
|
|
|
store: CacheStore
|
|
|
|
|
|
|
|
setup:
|
2022-03-18 13:50:53 -06:00
|
|
|
newBlock = Block.new("New Kids on the Block".toBytes()).tryGet()
|
2023-03-13 14:48:09 +01:00
|
|
|
backingStore = MockBlockStore.new()
|
|
|
|
backingStore.getBlock = newBlock
|
|
|
|
store = CacheStore.new(backingStore)
|
2022-03-03 03:30:42 +11:00
|
|
|
|
|
|
|
test "constructor":
|
|
|
|
expect ValueError:
|
2023-03-13 14:48:09 +01:00
|
|
|
discard CacheStore.new(backingStore, cacheSize = 1, chunkSize = 2)
|
2022-03-03 03:30:42 +11:00
|
|
|
|
|
|
|
expect ValueError:
|
2023-03-13 14:48:09 +01:00
|
|
|
discard CacheStore.new(backingStore, cacheSize = 99, chunkSize = 100)
|
2022-03-03 03:30:42 +11:00
|
|
|
|
2023-03-13 14:48:09 +01:00
|
|
|
test "getBlock can return cached block":
|
|
|
|
let
|
|
|
|
received1 = (await store.getBlock(newBlock.cid)).tryGet()
|
|
|
|
received2 = (await store.getBlock(newBlock.cid)).tryGet()
|
2022-03-03 03:30:42 +11:00
|
|
|
|
|
|
|
check:
|
2023-03-13 14:48:09 +01:00
|
|
|
newBlock == received1
|
|
|
|
newBlock == received2
|
|
|
|
backingStore.numberOfGetCalls == 1
|
2022-03-03 03:30:42 +11:00
|
|
|
|
2022-12-02 18:00:55 -06:00
|
|
|
commonBlockStoreTests(
|
|
|
|
"Cache", proc: BlockStore =
|
2023-03-13 14:48:09 +01:00
|
|
|
BlockStore(CacheStore.new(MemoryStore.new())))
|