-
-
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.
add a test to blockservice to demonstate GetBlocks failure.
- Loading branch information
1 parent
efb2ca4
commit 1e89de8
Showing
4 changed files
with
146 additions
and
104 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
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,101 @@ | ||
package bitswap | ||
|
||
import ( | ||
"code.google.com/p/go.net/context" | ||
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore" | ||
ds_sync "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync" | ||
"github.com/jbenet/go-ipfs/blocks" | ||
"github.com/jbenet/go-ipfs/blocks/blockstore" | ||
"github.com/jbenet/go-ipfs/exchange" | ||
tn "github.com/jbenet/go-ipfs/exchange/bitswap/testnet" | ||
"github.com/jbenet/go-ipfs/peer" | ||
"github.com/jbenet/go-ipfs/routing/mock" | ||
) | ||
|
||
/* | ||
TODO: This whole file needs somewhere better to live. | ||
The issue is that its very difficult to move it somewhere else | ||
without creating circular dependencies. | ||
Additional thought required. | ||
*/ | ||
|
||
func NewBlockGenerator() BlockGenerator { | ||
return BlockGenerator{} | ||
} | ||
|
||
type BlockGenerator struct { | ||
seq int | ||
} | ||
|
||
func (bg *BlockGenerator) Next() *blocks.Block { | ||
bg.seq++ | ||
return blocks.NewBlock([]byte(string(bg.seq))) | ||
} | ||
|
||
func (bg *BlockGenerator) Blocks(n int) []*blocks.Block { | ||
blocks := make([]*blocks.Block, 0) | ||
for i := 0; i < n; i++ { | ||
b := bg.Next() | ||
blocks = append(blocks, b) | ||
} | ||
return blocks | ||
} | ||
|
||
func NewSessionGenerator( | ||
net tn.Network, rs mock.RoutingServer) SessionGenerator { | ||
return SessionGenerator{ | ||
net: net, | ||
rs: rs, | ||
seq: 0, | ||
} | ||
} | ||
|
||
type SessionGenerator struct { | ||
seq int | ||
net tn.Network | ||
rs mock.RoutingServer | ||
} | ||
|
||
func (g *SessionGenerator) Next() Instance { | ||
g.seq++ | ||
return session(g.net, g.rs, []byte(string(g.seq))) | ||
} | ||
|
||
func (g *SessionGenerator) Instances(n int) []Instance { | ||
instances := make([]Instance, 0) | ||
for j := 0; j < n; j++ { | ||
inst := g.Next() | ||
instances = append(instances, inst) | ||
} | ||
return instances | ||
} | ||
|
||
type Instance struct { | ||
Peer peer.Peer | ||
Exchange exchange.Interface | ||
Blockstore blockstore.Blockstore | ||
} | ||
|
||
// session creates a test bitswap session. | ||
// | ||
// NB: It's easy make mistakes by providing the same peer ID to two different | ||
// sessions. To safeguard, use the SessionGenerator to generate sessions. It's | ||
// just a much better idea. | ||
func session(net tn.Network, rs mock.RoutingServer, id peer.ID) Instance { | ||
p := peer.WithID(id) | ||
|
||
adapter := net.Adapter(p) | ||
htc := rs.Client(p) | ||
bstore := blockstore.NewBlockstore(ds_sync.MutexWrap(ds.NewMapDatastore())) | ||
|
||
const alwaysSendToPeer = true | ||
ctx := context.TODO() | ||
|
||
bs := New(ctx, p, adapter, htc, bstore, alwaysSendToPeer) | ||
|
||
return Instance{ | ||
Peer: p, | ||
Exchange: bs, | ||
Blockstore: bstore, | ||
} | ||
} |
1e89de8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A word of caution. This commit causes compilation errors.
For easy bisection, we are attempting to ensure that all commits merged into master compile successfully. Discussion at #373 (comment)
The compilation errors are fixed two commits ahead leaving a couple broken spots. dfda464