/
eph_server_test.go
212 lines (181 loc) · 6.05 KB
/
eph_server_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
package reg
// xlReg_go/eph_server_test.go
// replaces mock_server_test.go AKA old_server_test.go
// BEING MODIFIED to follow the new approach, whereby
// 1. we create an ephemeral registry using NewEphServer()
// 2. we generate a random cluster name and size
// 3. run an AdminClient to register the cluster with the registry (which
// gives us a cluster ID), and then
// 4. create the appropriate number K of UserMembers
// 5. do test run in which the K clients exchange details through the registry
import (
"fmt"
xr "github.com/jddixon/rnglib_go"
xt "github.com/jddixon/xlTransport_go"
xf "github.com/jddixon/xlUtil_go/lfs"
. "gopkg.in/check.v1"
"os"
"path"
"strings"
)
func (s *XLSuite) TestEphServer(c *C) {
if VERBOSITY > 0 {
fmt.Println("\nTEST_EPH_SERVER")
}
rng := xr.MakeSimpleRNG()
// 1. create a new ephemeral server ----------------------------
es, err := NewEphServer()
c.Assert(err, IsNil)
c.Assert(es, NotNil)
server := es.Server
c.Assert(&server.RegNode.ckPriv.PublicKey,
DeepEquals, server.GetCommsPublicKey())
serverName := server.GetName()
serverID := server.GetNodeID()
serverEnd := server.GetEndPoint(0)
serverCK := server.GetCommsPublicKey()
serverSK := server.GetSigPublicKey()
c.Assert(serverEnd, NotNil)
// start the ephemeral server -------------------------
err = es.Start()
c.Assert(err, IsNil)
defer es.Stop() // stop the server, closing its acceptor
// DEBUG
fmt.Printf("TestEphServer: server acc %s\n", server.GetAcceptor().String())
fmt.Printf(" serverEnd %s\n", server.GetEndPoint(0).String())
// END
// verify Bloom filter is running
reg := es.Server.Registry
c.Assert(reg, NotNil)
regID := reg.GetNodeID()
c.Assert(reg.IDCount(), Equals, uint(1)) // the registry's own ID
found, err := reg.ContainsID(regID)
c.Assert(found, Equals, true)
c.Assert(reg.IDCount(), Equals, uint(1))
// 2. create a random cluster name, size, scratch directory -----
clusterName := rng.NextFileName(8)
clusterDir := path.Join("tmp", clusterName)
for {
if _, err = os.Stat(clusterDir); os.IsNotExist(err) {
break
}
clusterName = rng.NextFileName(8)
clusterDir = path.Join("tmp", clusterName)
}
err = xf.CheckLFS(clusterDir, 0750)
c.Assert(err, IsNil)
// DEBUG
fmt.Printf("CLUSTER NAME: %s\n", clusterName)
// END
clusterAttrs := uint64(rng.Int63())
K := uint32(2 + rng.Intn(6)) // so the size is 2 .. 7
// 3. create an AdminClient, use it to get the clusterID
// DEBUG
fmt.Printf("\neph_server_test: creating ADMIN client\n")
// END
an, err := NewAdminClient(serverName, serverID, serverEnd,
serverCK, serverSK, clusterName, clusterAttrs, K, uint32(1), nil)
c.Assert(err, IsNil)
an.Start()
err = <-an.DoneCh
c.Assert(err, IsNil)
anID := an.ClusterMember.Node.GetNodeID()
// DEBUG
fmt.Println("\nADMIN CLIENT GETS:")
fmt.Printf(" regID %s\n", regID.String())
fmt.Printf(" anID %s\n", anID.String())
if an.ClusterID == nil {
fmt.Printf(" ClusterID NIL\n")
} else {
fmt.Printf(" ClusterID %s\n", an.ClusterID.String())
}
// END
c.Check(reg.IDCount(), Equals, uint(3))
c.Assert(an.ClusterID, NotNil) // the purpose of the exercise
c.Assert(an.EPCount, Equals, uint32(1))
found, err = reg.ContainsID(regID)
c.Assert(err, IsNil)
c.Assert(found, Equals, true)
found, err = reg.ContainsID(anID)
c.Assert(err, IsNil)
c.Check(found, Equals, true)
found, err = reg.ContainsID(an.ClusterID)
c.Assert(err, IsNil)
c.Check(found, Equals, true)
c.Check(reg.IDCount(), Equals, uint(3)) // regID + anID + clusterID
// 4. create K members ------------------------------------------
// DEBUG
fmt.Printf("\nCREATING %d MEMBERS\n", K)
// END
uc := make([]*UserMember, K)
ucNames := make([]string, K)
namesInUse := make(map[string]bool)
epCount := uint32(2)
for i := uint32(0); i < K; i++ {
var endPoints []xt.EndPointI
for j := uint32(0); j < epCount; j++ {
var ep *xt.TcpEndPoint
ep, err = xt.NewTcpEndPoint("127.0.0.1:0")
c.Assert(err, IsNil)
endPoints = append(endPoints, ep)
}
newName := rng.NextFileName(8)
_, ok := namesInUse[newName]
for ok {
newName = rng.NextFileName(8)
_, ok = namesInUse[newName]
}
namesInUse[newName] = true
ucNames[i] = newName // guaranteed to be LOCALLY unique
lfs := path.Join(clusterDir, newName)
uc[i], err = NewUserMember(ucNames[i], lfs,
nil, nil, // private RSA keys are generated if nil
serverName, serverID, serverEnd, serverCK, serverSK,
clusterName, an.ClusterAttrs, an.ClusterID,
K, epCount, endPoints)
c.Assert(err, IsNil)
c.Assert(uc[i], NotNil)
c.Assert(uc[i].ClusterID, NotNil)
}
// 5. initialize the K members, each in a separate goroutine ----
for i := uint32(0); i < K; i++ {
uc[i].Start()
}
// wait until all members are initialized -----------------------
for i := uint32(0); i < K; i++ {
doneErr := <-uc[i].MemberMaker.DoneCh
c.Assert(doneErr, IsNil)
// among other things, the Persist makes the nodes start listening
uc[i].MemberMaker.PersistClusterMember()
nodeID := uc[i].MemberMaker.GetNodeID()
c.Assert(nodeID, NotNil)
found, err := reg.ContainsID(nodeID)
c.Assert(err, IsNil)
c.Check(found, Equals, true)
}
c.Assert(reg.IDCount(), Equals, uint(3+K)) // regID + anID + clusterID + K
// 6. verify that the nodes are live ----------------------------
for i := uint32(0); i < K; i++ {
mn := uc[i].MemberMaker
cm := mn.ClusterMember
node := cm.Node
mnEPCount := uint32(node.SizeEndPoints())
c.Assert(mnEPCount, Equals, epCount)
actualEPCount := uint32(mn.SizeEndPoints())
c.Assert(actualEPCount, Equals, epCount)
actualAccCount := uint32(mn.SizeAcceptors())
c.Assert(actualAccCount, Equals, epCount)
for j := uint32(0); j < epCount; j++ {
nodeEP := cm.GetEndPoint(int(j)).String()
nodeAcc := cm.GetAcceptor(int(j)).String()
c.Assert(strings.HasSuffix(nodeEP, ":0"), Equals, false)
c.Assert(strings.HasSuffix(nodeAcc, nodeEP), Equals, true)
// DEBUG
fmt.Printf("node %d: endPoint %d is %s\n",
i, j, cm.GetEndPoint(int(j)).String())
// END
}
}
// verify that results are as expected --------------------------
// XXX STUB XXX
}