test(gc) with 10 node integration test
Brian Tiger Chow committed
Jan 30, 2015 at 01:30 UTC
b34fee4ede928192bfec2b2ef65bbe581f44fa6e
1 file changed
+134
test/integration/grandcentral_test.go
new
+134
@@ -0,0 +1,134 @@
1
+package integrationtest
2
+
3
+import (
4
+ "bytes"
5
+ "io"
6
+ "math"
7
+ "testing"
8
+
9
+ context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
10
+ "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
11
+ syncds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
12
+ core "github.com/jbenet/go-ipfs/core"
13
+ "github.com/jbenet/go-ipfs/core/corerouting"
14
+ "github.com/jbenet/go-ipfs/core/coreunix"
15
+ mocknet "github.com/jbenet/go-ipfs/p2p/net/mock"
16
+ "github.com/jbenet/go-ipfs/p2p/peer"
17
+ "github.com/jbenet/go-ipfs/thirdparty/iter"
18
+ "github.com/jbenet/go-ipfs/thirdparty/unit"
19
+ ds2 "github.com/jbenet/go-ipfs/util/datastore2"
20
+ errors "github.com/jbenet/go-ipfs/util/debugerror"
21
+ testutil "github.com/jbenet/go-ipfs/util/testutil"
22
+)
23
+
24
+func TestGrandcentralBootstrappedAddCat(t *testing.T) {
25
+ // create 8 grandcentral bootstrap nodes
26
+ // create 2 grandcentral clients both bootstrapped to the bootstrap nodes
27
+ // let the bootstrap nodes share a single datastore
28
+ // add a large file on one node then cat the file from the other
29
+ conf := testutil.LatencyConfig{
30
+ NetworkLatency: 0,
31
+ RoutingLatency: 0,
32
+ BlockstoreLatency: 0,
33
+ }
34
+ if err := RunGrandcentralBootstrappedAddCat(RandomBytes(100*unit.MB), conf); err != nil {
35
+ t.Fatal(err)
36
+ }
37
+}
38
+
39
+func RunGrandcentralBootstrappedAddCat(data []byte, conf testutil.LatencyConfig) error {
40
+ ctx, cancel := context.WithCancel(context.Background())
41
+ defer cancel()
42
+
43
+ servers, clients, err := InitializeGrandCentralNetwork(ctx, 8, 2, conf)
44
+ if err != nil {
45
+ return err
46
+ }
47
+ for _, n := range append(servers, clients...) {
48
+ defer n.Close()
49
+ }
50
+
51
+ adder := clients[0]
52
+ catter := clients[1]
53
+
54
+ log.Critical("adder is", adder.Identity)
55
+ log.Critical("catter is", catter.Identity)
56
+
57
+ keyAdded, err := coreunix.Add(adder, bytes.NewReader(data))
58
+ if err != nil {
59
+ return err
60
+ }
61
+
62
+ readerCatted, err := coreunix.Cat(catter, keyAdded)
63
+ if err != nil {
64
+ return err
65
+ }
66
+
67
+ // verify
68
+ var bufout bytes.Buffer
69
+ io.Copy(&bufout, readerCatted)
70
+ if 0 != bytes.Compare(bufout.Bytes(), data) {
71
+ return errors.New("catted data does not match added data")
72
+ }
73
+ return nil
74
+}
75
+
76
+func InitializeGrandCentralNetwork(
77
+ ctx context.Context,
78
+ numServers, numClients int,
79
+ conf testutil.LatencyConfig) ([]*core.IpfsNode, []*core.IpfsNode, error) {
80
+
81
+ // create network
82
+ mn, err := mocknet.FullMeshLinked(ctx, numServers+numClients)
83
+ if err != nil {
84
+ return nil, nil, errors.Wrap(err)
85
+ }
86
+
87
+ mn.SetLinkDefaults(mocknet.LinkOptions{
88
+ Latency: conf.NetworkLatency,
89
+ Bandwidth: math.MaxInt32,
90
+ })
91
+
92
+ peers := mn.Peers()
93
+ if len(peers) < numServers+numClients {
94
+ return nil, nil, errors.New("test initialization error")
95
+ }
96
+ clientPeers, serverPeers := peers[0:numClients], peers[numClients:]
97
+
98
+ routingDatastore := ds2.CloserWrap(syncds.MutexWrap(datastore.NewMapDatastore()))
99
+ var servers []*core.IpfsNode
100
+ for i := range iter.N(numServers) {
101
+ p := serverPeers[i]
102
+ bootstrap, err := core.NewIPFSNode(ctx, MocknetTestRepo(p, mn.Host(p), conf,
103
+ corerouting.GrandCentralServer(routingDatastore)))
104
+ if err != nil {
105
+ return nil, nil, err
106
+ }
107
+ servers = append(servers, bootstrap)
108
+ }
109
+
110
+ var bootstrapInfos []peer.PeerInfo
111
+ for _, n := range servers {
112
+ info := n.Peerstore.PeerInfo(n.PeerHost.ID())
113
+ bootstrapInfos = append(bootstrapInfos, info)
114
+ }
115
+
116
+ var clients []*core.IpfsNode
117
+ for i := range iter.N(numClients) {
118
+ p := clientPeers[i]
119
+ n, err := core.NewIPFSNode(ctx, MocknetTestRepo(p, mn.Host(p), conf,
120
+ corerouting.GrandCentralClient(bootstrapInfos...)))
121
+ if err != nil {
122
+ return nil, nil, err
123
+ }
124
+ clients = append(clients, n)
125
+ }
126
+
127
+ bcfg := core.BootstrapConfigWithPeers(bootstrapInfos)
128
+ for _, n := range clients {
129
+ if err := n.Bootstrap(bcfg); err != nil {
130
+ return nil, nil, err
131
+ }
132
+ }
133
+ return servers, clients, nil
134
+}