MCPcopy
hub / github.com/olric-data/olric / AddMember

Method AddMember

internal/testcluster/testcluster.go:121–172  ·  view source on GitHub ↗
(e *environment.Environment)

Source from the content-addressed store, hash-verified

119}
120
121func (t *TestCluster) AddMember(e *environment.Environment) service.Service {
122 t.mu.Lock()
123 defer t.mu.Unlock()
124
125 if e == nil {
126 e = NewEnvironment(nil)
127 }
128 c := e.Get("config").(*config.Config)
129 partitions.SetHashFunc(c.Hasher)
130
131 port, err := testutil.GetFreePort()
132 if err != nil {
133 panic(fmt.Sprintf("failed to a random port: %v", err))
134 }
135 c.MemberlistConfig.BindPort = port
136
137 var peers []string
138 for _, peerPort := range t.memberPorts {
139 peers = append(peers, net.JoinHostPort("127.0.0.1", strconv.Itoa(peerPort)))
140 }
141 c.Peers = peers
142
143 s := t.newService(e)
144 rt := e.Get("routingtable").(*routingtable.RoutingTable)
145 err = rt.Join()
146 if err != nil {
147 panic(fmt.Sprintf("failed to join the Olric cluster: %v", err))
148 }
149 err = rt.Start()
150 if err != nil {
151 panic(fmt.Sprintf("failed to start the routing table: %v", err))
152 }
153
154 t.errGr.Go(func() error {
155 <-t.ctx.Done()
156 return rt.Shutdown(context.Background())
157 })
158
159 t.errGr.Go(func() error {
160 return s.Start()
161 })
162
163 t.errGr.Go(func() error {
164 <-t.ctx.Done()
165 return s.Shutdown(context.Background())
166 })
167
168 t.environments = append(t.environments, e)
169 t.memberPorts = append(t.memberPorts, port)
170 t.syncCluster()
171 return s
172}
173
174func (t *TestCluster) Shutdown() {
175 t.cancel()

Callers 15

TestDMap_Get_GetResponseFunction · 0.80
TestDMapServiceFunction · 0.80
TestDMap_Put_StandaloneFunction · 0.80
TestDMap_Put_ClusterFunction · 0.80
TestDMap_Put_WriteQuorumFunction · 0.80
TestDMap_Put_PXFunction · 0.80
TestDMap_Put_NXFunction · 0.80
TestDMap_Put_XXFunction · 0.80
TestDMap_Put_EXFunction · 0.80
TestDMap_Put_EXATFunction · 0.80
TestDMap_Put_PXATFunction · 0.80

Calls 12

newServiceMethod · 0.95
ShutdownMethod · 0.95
syncClusterMethod · 0.95
SetHashFuncFunction · 0.92
GetFreePortFunction · 0.92
NewEnvironmentFunction · 0.85
LockMethod · 0.65
UnlockMethod · 0.65
GetMethod · 0.65
StartMethod · 0.65
ShutdownMethod · 0.65
JoinMethod · 0.45

Tested by 15

TestDMap_Get_GetResponseFunction · 0.64
TestDMapServiceFunction · 0.64
TestDMap_Put_StandaloneFunction · 0.64
TestDMap_Put_ClusterFunction · 0.64
TestDMap_Put_WriteQuorumFunction · 0.64
TestDMap_Put_PXFunction · 0.64
TestDMap_Put_NXFunction · 0.64
TestDMap_Put_XXFunction · 0.64
TestDMap_Put_EXFunction · 0.64
TestDMap_Put_EXATFunction · 0.64
TestDMap_Put_PXATFunction · 0.64