-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3294 from ipfs/kevina/dup-prov-cache-fix
Create a write-through block service
- Loading branch information
Showing
14 changed files
with
149 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package blockservice | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ipfs/go-ipfs/blocks" | ||
"github.com/ipfs/go-ipfs/blocks/blockstore" | ||
butil "github.com/ipfs/go-ipfs/blocks/blocksutil" | ||
offline "github.com/ipfs/go-ipfs/exchange/offline" | ||
|
||
ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore" | ||
dssync "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync" | ||
) | ||
|
||
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.Fatal("Put should have called again, should be 2 is: %d", bstore.PutCounter) | ||
} | ||
} | ||
|
||
var _ blockstore.GCBlockstore = (*PutCountingBlockstore)(nil) | ||
|
||
type PutCountingBlockstore struct { | ||
blockstore.GCBlockstore | ||
PutCounter int | ||
} | ||
|
||
func (bs *PutCountingBlockstore) Put(block blocks.Block) error { | ||
bs.PutCounter++ | ||
return bs.GCBlockstore.Put(block) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.