/
cluster_test.go
239 lines (210 loc) · 7.34 KB
/
cluster_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
package upax_go
// upax_go/cluster_test.go
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) TestCluster(c *C) {
rng := xr.MakeSimpleRNG()
s.doTestCluster(c, rng, xu.USING_SHA1)
s.doTestCluster(c, rng, xu.USING_SHA2)
s.doTestCluster(c, rng, xu.USING_SHA3)
}
/////////////////////////////////////////////////////////////////////
// BEFORE RUNNING THIS TEST, BE SURE THAT YOU HAVE
// * IF NECESSARY
// * STOPPED ANY OLD INSTANCE OF xlReg
// * REBUILT AND INSTALLED xlReg
// * STARTED xlReg RUNNING
// * AND INVOKVED ./updateRegCred
//
// In other words, the local version of regCred.dat must match the
// one in /var/app/xlReg; that in turn must correspond to the current
// build of xlReg; and an instance of that build must be running.
/////////////////////////////////////////////////////////////////////
func (s *XLSuite) doTestCluster(c *C, rng *xr.PRNG, whichSHA int) {
if VERBOSITY > 0 {
fmt.Printf("TEST_CLUSTER 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)
for {
if _, err = os.Stat(clusterPath); os.IsNotExist(err) {
break
}
clusterName = rng.NextFileName(8)
clusterPath = filepath.Join("tmp", clusterName)
}
err = xf.CheckLFS(clusterPath, 0750)
c.Assert(err, IsNil)
// DEBUG
fmt.Printf("CLUSTER %s\n", clusterName)
fmt.Printf("CLUSTER_PATH %s\n", clusterPath)
// END
// Set the test size in various senses --------------------------
// K1 is the number of servers, and so the cluster size. K2 is
// the number of clients, M the number of messages sent (items to
// be added to the Upax store), LMin and LMax message lengths.
K1 := uint32(3 + rng.Intn(5)) // so 3..7
K2 := uint32(2 + rng.Intn(4)) // so 2..5
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()
<-an.DoneCh
clusterID := an.ClusterID // a NodeID, not []byte
if clusterID == nil {
fmt.Println("NIL CLUSTER ID: is xlReg running??")
}
c.Assert(clusterID, NotNil)
clusterSize := an.ClusterMaxSize
c.Assert(clusterSize, Equals, uint32(K1))
epCount := an.EPCount
c.Assert(epCount, Equals, uint32(EP_COUNT))
// Create names and LFSs for the K1 members ---------------------
// We create a distinct tmp/clusterName/serverName for each
// server as its local file system (LFS).
memberNames := make([]string, K1)
memberPaths := make([]string, K1)
ckPriv := make([]*rsa.PrivateKey, K1)
skPriv := make([]*rsa.PrivateKey, K1)
for i := uint32(0); i < K1; i++ {
var found bool
memberNames[i] = rng.NextFileName(8)
memberPaths[i] = filepath.Join(clusterPath, memberNames[i])
found, err = xf.PathExists(memberPaths[i])
c.Assert(err, IsNil)
for found {
memberNames[i] = rng.NextFileName(8)
memberPaths[i] = filepath.Join(clusterPath, memberNames[i])
found, err = xf.PathExists(memberPaths[i])
c.Assert(err, IsNil)
}
// DEBUG
fmt.Printf("MEMBER_PATH[%d]: %s\n", i, memberPaths[i])
// END
err = os.MkdirAll(memberPaths[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 client nodes ---------------------------------------
uc := make([]*reg.UserMember, K1)
for i := uint32(0); i < K1; i++ {
var ep1, ep2 *xt.TcpEndPoint
ep1, err = xt.NewTcpEndPoint("127.0.0.1:0")
ep2, err = xt.NewTcpEndPoint("127.0.0.1:0")
c.Assert(err, IsNil)
e := []xt.EndPointI{ep1, ep2}
uc[i], err = reg.NewUserMember(memberNames[i], memberPaths[i],
ckPriv[i], skPriv[i],
regServerName, regServerID, regServerEnd, regServerCK, regServerSK,
clusterName, an.ClusterAttrs, an.ClusterID,
K1, EP_COUNT, e)
c.Assert(err, IsNil)
c.Assert(uc[i], NotNil)
c.Assert(uc[i].ClusterID, NotNil)
c.Assert(uc[i].MemberMaker.DoneCh, NotNil)
}
// Start the K1 client nodes running ----------------------------
for i := uint32(0); i < K1; i++ {
uc[i].Start()
}
fmt.Println("ALL CLIENTS STARTED")
// wait until all clientNodes are done --------------------------
for i := uint32(0); i < K1; i++ {
err = <-uc[i].MemberMaker.DoneCh
c.Assert(err, IsNil)
// nodeID := uc[i].clientID
}
fmt.Println("ALL CLIENTS DONE") // XXX NOT SEEN
// verify that all clientNodes have meaningful baseNodes --------
// XXX THESE TESTS ALWAYS FAIL
//for i := 0; i < K1; i++ {
// c.Assert(uc[i].GetName(), Equals, memberNames[i])
// c.Assert(uc[i].GetNodeID(), NotNil)
// c.Assert(uc[i].GetCommsPublicKey(), NotNil)
// c.Assert(uc[i].GetSigPublicKey(), NotNil)
//}
// convert the client nodes to UpaxServers ----------------------
us := make([]*UpaxServer, K1)
for i := uint32(0); i < K1; i++ {
err = uc[i].PersistClusterMember()
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("all servers have sent first DONE")
// END
// When all UpaxServers are ready, create K2 clients.--
// Each client creates K3 separate datums of differnt
// 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 all servers--
// have a copy of each and every datum.
// XXX STUB
_, _, _, _ = K2, M, LMin, LMax
}