mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-23 19:37:46 +08:00
This extracts the blocks/blockstore package and renames the blocks/blockstore/util package to /blocks/blockstoreutil (because util depends on Pin and I don't plan to extract Pin and its depedencies). The history of blocks/blockstore has been preserved. It has been gx'ed and imported. Imports have been rewritten accordingly and re-ordered. License: MIT Signed-off-by: Hector Sanjuan <hector@protocol.ai>
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package blockservice
|
|
|
|
import (
|
|
"testing"
|
|
|
|
butil "github.com/ipfs/go-ipfs/blocks/blocksutil"
|
|
offline "github.com/ipfs/go-ipfs/exchange/offline"
|
|
|
|
ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
|
|
dssync "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
|
|
blockstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
|
|
blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
|
|
)
|
|
|
|
func TestWriteThroughWorks(t *testing.T) {
|
|
bstore := &PutCountingBlockstore{
|
|
blockstore.NewBlockstore(dssync.MutexWrap(ds.NewMapDatastore())),
|
|
0,
|
|
}
|
|
bstore2 := blockstore.NewBlockstore(dssync.MutexWrap(ds.NewMapDatastore()))
|
|
exch := offline.Exchange(bstore2)
|
|
bserv := NewWriteThrough(bstore, exch)
|
|
bgen := butil.NewBlockGenerator()
|
|
|
|
block := bgen.Next()
|
|
|
|
t.Logf("PutCounter: %d", bstore.PutCounter)
|
|
bserv.AddBlock(block)
|
|
if bstore.PutCounter != 1 {
|
|
t.Fatalf("expected just one Put call, have: %d", bstore.PutCounter)
|
|
}
|
|
|
|
bserv.AddBlock(block)
|
|
if bstore.PutCounter != 2 {
|
|
t.Fatalf("Put should have called again, should be 2 is: %d", bstore.PutCounter)
|
|
}
|
|
}
|
|
|
|
var _ blockstore.Blockstore = (*PutCountingBlockstore)(nil)
|
|
|
|
type PutCountingBlockstore struct {
|
|
blockstore.Blockstore
|
|
PutCounter int
|
|
}
|
|
|
|
func (bs *PutCountingBlockstore) Put(block blocks.Block) error {
|
|
bs.PutCounter++
|
|
return bs.Blockstore.Put(block)
|
|
}
|