/
pair_test.go
243 lines (213 loc) · 7.55 KB
/
pair_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
package upax_go
// upax_go/pair_test.go
// This is a simplified version of cluster_test.go. We start a single
// server and then a single client. The client generates a number of
// dummy files, loads them into the server, and then checks to see
// whether they are there.
import (
"crypto/rand"
"crypto/rsa"
"fmt"
xr "github.com/jddixon/rnglib_go"
reg "github.com/jddixon/xlReg_go"
xt "github.com/jddixon/xlTransport_go"
xu "github.com/jddixon/xlUtil_go"
xf "github.com/jddixon/xlUtil_go/lfs"
. "gopkg.in/check.v1"
"io/ioutil"
"os"
"path/filepath"
"time"
)
var _ = fmt.Print
func (s *XLSuite) TestPair(c *C) {
rng := xr.MakeSimpleRNG()
s.doTestPair(c, rng, xu.USING_SHA1)
s.doTestPair(c, rng, xu.USING_SHA2)
s.doTestPair(c, rng, xu.USING_SHA3)
}
// This was copied from cluster_test.go and minimal changes have been
// made.
//
func (s *XLSuite) doTestPair(c *C, rng *xr.PRNG, whichSHA int) {
if VERBOSITY > 0 {
fmt.Printf("TEST_PAIR whichSHA = %v\n", whichSHA)
}
// read regCred.dat to get keys etc for a registry --------------
dat, err := ioutil.ReadFile("regCred.dat")
c.Assert(err, IsNil)
regCred, err := reg.ParseRegCred(string(dat))
c.Assert(err, IsNil)
regServerName := regCred.Name
regServerID := regCred.ID
regServerEnd := regCred.EndPoints[0]
regServerCK := regCred.CommsPubKey
regServerSK := regCred.SigPubKey
// Devise a unique cluster name. We rely on the convention -----
// that in Upax tests, the local file system for Upax servers is
// tmp/CLUSTER-NAME/SERVER-NAME.
clusterName := rng.NextFileName(8)
clusterPath := filepath.Join("tmp", clusterName)
found, err := xf.PathExists(clusterPath)
c.Assert(err, IsNil)
for found {
clusterName = rng.NextFileName(8)
clusterPath = filepath.Join("tmp", clusterName)
found, err = xf.PathExists(clusterPath)
c.Assert(err, IsNil)
}
// Set the test size in various senses --------------------------
// K1 is the number of upax servers, and so the cluster size. K2 is
// the number of upax clients, M the number of messages sent (items to
// be added to the Upax store), LMin and LMax message lengths.
K1 := uint32(2)
K2 := 1
M := 16 + rng.Intn(16) // 16..31
LMin := 64 + rng.Intn(64)
LMax := 128 + rng.Intn(128)
// Use an admin client to get a clusterID for this clusterName --
const EP_COUNT = 2
an, err := reg.NewAdminClient(regServerName, regServerID, regServerEnd,
regServerCK, regServerSK, clusterName, uint64(0), K1, EP_COUNT, nil)
c.Assert(err, IsNil)
an.Start()
cn := &an.MemberMaker
<-cn.DoneCh
clusterID := cn.ClusterID
if clusterID == nil {
fmt.Println("NIL CLUSTER ID: is xlReg running??")
}
c.Assert(clusterID, NotNil) // FAILS 2016-11-13
clusterSize := cn.ClusterMaxSize
c.Assert(clusterSize, Equals, uint32(K1))
epCount := cn.EPCount
c.Assert(epCount, Equals, uint32(EP_COUNT))
// DEBUG
// fmt.Printf("cluster %s: %s\n", clusterName, clusterID.String())
// END
// Create names and LFSs for the K1 servers ---------------------
// We create a distinct tmp/clusterName/serverName for each
// server as its local file system (LFS).
serverNames := make([]string, K1)
serverPaths := make([]string, K1)
ckPriv := make([]*rsa.PrivateKey, K1)
skPriv := make([]*rsa.PrivateKey, K1)
for i := uint32(0); i < K1; i++ {
serverNames[i] = rng.NextFileName(8)
serverPaths[i] = filepath.Join(clusterPath, serverNames[i])
found, err = xf.PathExists(serverPaths[i])
c.Assert(err, IsNil)
for found {
serverNames[i] = rng.NextFileName(8)
serverPaths[i] = filepath.Join(clusterPath, serverNames[i])
found, err = xf.PathExists(serverPaths[i])
c.Assert(err, IsNil)
}
err = os.MkdirAll(serverPaths[i], 0750)
c.Assert(err, IsNil)
ckPriv[i], err = rsa.GenerateKey(rand.Reader, 1024) // cheap keys
c.Assert(err, IsNil)
c.Assert(ckPriv[i], NotNil)
skPriv[i], err = rsa.GenerateKey(rand.Reader, 1024) // cheap keys
c.Assert(err, IsNil)
c.Assert(skPriv[i], NotNil)
}
// create K1 reg client nodes -----------------------------------
uc := make([]*reg.UserMember, K1)
for i := uint32(0); i < K1; i++ {
var ep *xt.TcpEndPoint
ep, err = xt.NewTcpEndPoint("127.0.0.1:0")
c.Assert(err, IsNil)
e := []xt.EndPointI{ep}
uc[i], err = reg.NewUserMember(serverNames[i], serverPaths[i],
ckPriv[i], skPriv[i],
regServerName, regServerID, regServerEnd, regServerCK, regServerSK,
clusterName, cn.ClusterAttrs, cn.ClusterID,
K1, EP_COUNT, e)
c.Assert(err, IsNil)
c.Assert(uc[i], NotNil)
c.Assert(uc[i].ClusterID, NotNil)
}
// Start the K1 reg client nodes running ------------------------
for i := uint32(0); i < K1; i++ {
uc[i].Start()
}
// wait until all reg clientNodes are done ----------------------
for i := uint32(0); i < K1; i++ {
err := <-uc[i].MemberMaker.DoneCh
c.Assert(err, IsNil)
}
// verify that all clientNodes have meaningful baseNodes --------
//for i := 0; i < K1; i++ {
// c.Assert(uc[i].GetName(), Equals, serverNames[i])
// c.Assert(uc[i].GetNodeID(), NotNil)
// c.Assert(uc[i].GetCommsPublicKey(), NotNil)
// c.Assert(uc[i].GetSigPublicKey(), NotNil)
//}
// verify that all clientNode members have meaningful baseNodes -
for i := uint32(0); i < K1; i++ {
// fmt.Printf(" server %s\n", serverNames[i]) // DEBUG
memberCount := uint32(len(uc[i].Members))
c.Assert(memberCount, Equals, K1)
for j := uint32(0); j < memberCount; j++ {
c.Assert(uc[i].Members[j], NotNil)
// DEBUG
// fmt.Printf(" other server[%d] is %s\n", j, serverNames[j])
// END
// doesn't work because reg server does not necessarily see
// members in serverName order.
// c.Assert(uc[i].Members[j].GetName(), Equals, serverNames[j])
c.Assert(uc[i].Members[j].Peer.GetName() == "", Equals, false)
c.Assert(uc[i].Members[j].Peer.GetNodeID(), NotNil)
c.Assert(uc[i].Members[j].Peer.GetCommsPublicKey(), NotNil)
c.Assert(uc[i].Members[j].Peer.GetSigPublicKey(), NotNil)
}
}
// convert the reg client nodes to UpaxServers ------------------
us := make([]*UpaxServer, K1)
for i := uint32(0); i < K1; i++ {
err = uc[i].PersistClusterMember() // sometimes panics
c.Assert(err, IsNil)
us[i], err = NewUpaxServer(
ckPriv[i], skPriv[i], &uc[i].ClusterMember, whichSHA)
c.Assert(err, IsNil)
c.Assert(us[i], NotNil)
}
// verify files are present and then start the servers ----------
// 11-07 TODO, modified:
// Run() causes each server to send ItsMe to all other servers;
// as each gets its Ack, it starts the KeepAlive/Ack cycle running
// at a 50 ms interval specified as a Run() argument and then sends
// on DoneCh. Second parameter is lifetime of the server in
// keep-alives, say 20 (so 1 sec in total). When this time has
// passed, the server will send again on DoneCh, and then shut down.
// XXX STUB
for i := uint32(0); i < K1; i++ {
err = us[i].Run(10*time.Millisecond, 20)
c.Assert(err, IsNil)
}
// Verify servers are running -------------------------
// 11-18: we wait for the first done from each server.
//
// XXX STUB
for i := uint32(0); i < K1; i++ {
<-us[i].DoneCh
}
// DEBUG
fmt.Println("pair_test: both servers have sent first DONE")
// END
// When all UpaxServers are ready, create K2 clients.--
// Each upax client creates K3 separate datums of different
// length (L1..L2) and content. Each client signals
// when done.
// XXX STUB
// Verify for each of the K2 clients ------------------
// that its data is present on the selected server. We
// do this by an Exists() call on uDir for the server's
// LFS/U for each item posted.
// XXX STUB
// After a reasonable deltaT, verify that both servers--
// have a copy of each and every datum.
// XXX STUB
_, _, _, _ = K2, M, LMin, LMax
}