MCPcopy
hub / github.com/CodisLabs/codis / TestGroupPromote

Function TestGroupPromote

pkg/topom/topom_group_test.go:137–200  ·  view source on GitHub ↗
(x *testing.T)

Source from the content-addressed store, hash-verified

135}
136
137func TestGroupPromote(x *testing.T) {
138 t := openTopom()
139 defer t.Close()
140
141 s := newFakeServer()
142 defer s.Close()
143
144 const sid = 100
145 const gid = 200
146 const server1 = "server1:port"
147 server2 := s.Addr
148
149 reset := func() {
150 g := &models.Group{Id: gid}
151 g.Servers = []*models.GroupServer{
152 &models.GroupServer{Addr: server1},
153 &models.GroupServer{Addr: server2},
154 }
155 contextUpdateGroup(t, g)
156 }
157
158 reset()
159
160 assert.Must(t.GroupPromoteServer(gid, server1) != nil)
161 g1 := getGroup(t, gid)
162 assert.Must(g1.Promoting.State == models.ActionNothing)
163 assert.Must(len(g1.Servers) == 2)
164 assert.Must(g1.Servers[0].Addr == server1)
165 assert.Must(g1.Servers[1].Addr == server2)
166
167 reset()
168
169 assert.MustNoError(t.GroupPromoteServer(gid, server2))
170 g2 := getGroup(t, gid)
171 assert.Must(g2.Promoting.State == models.ActionNothing)
172 assert.Must(len(g2.Servers) == 2)
173 assert.Must(g2.Servers[0].Addr == server2)
174 assert.Must(g2.Servers[1].Addr == server1)
175
176 reset()
177
178 m := &models.SlotMapping{Id: sid}
179 m.Action.State = models.ActionMigrating
180 m.Action.TargetId = gid
181 contextUpdateSlotMapping(t, m)
182
183 p, c := openProxy()
184 defer c.Shutdown()
185
186 contextCreateProxy(t, p)
187 assert.MustNoError(c.Shutdown())
188
189 assert.Must(t.GroupPromoteServer(gid, server2) != nil)
190
191 g3 := getGroup(t, gid)
192 assert.Must(g3.Promoting.State == models.ActionPreparing)
193 contextRemoveProxy(t, p)
194 assert.MustNoError(t.GroupPromoteServer(gid, server2))

Callers

nothing calls this directly

Calls 11

openTopomFunction · 0.85
newFakeServerFunction · 0.85
contextUpdateGroupFunction · 0.85
getGroupFunction · 0.85
contextUpdateSlotMappingFunction · 0.85
contextCreateProxyFunction · 0.85
contextRemoveProxyFunction · 0.85
openProxyFunction · 0.70
CloseMethod · 0.65
GroupPromoteServerMethod · 0.45
ShutdownMethod · 0.45

Tested by

no test coverage detected