@@ -204,6 +204,91 @@ func (s *testRegionInfoSuite) TestRegionWriteRate(c *C) {
204
204
}
205
205
}
206
206
207
+ var _ = Suite (& testRegionGuideSuite {})
208
+
209
+ type testRegionGuideSuite struct {
210
+ RegionGuide RegionGuideFunc
211
+ }
212
+
213
+ func (s * testRegionGuideSuite ) SetUpSuite (c * C ) {
214
+ s .RegionGuide = GenerateRegionGuideFunc (false )
215
+ }
216
+
217
+ func (s * testRegionGuideSuite ) TestNeedSync (c * C ) {
218
+ meta := & metapb.Region {
219
+ Id : 1000 ,
220
+ StartKey : []byte ("a" ),
221
+ EndKey : []byte ("z" ),
222
+ RegionEpoch : & metapb.RegionEpoch {ConfVer : 100 , Version : 100 },
223
+ Peers : []* metapb.Peer {
224
+ {Id : 11 , StoreId : 1 , Role : metapb .PeerRole_Voter },
225
+ {Id : 12 , StoreId : 1 , Role : metapb .PeerRole_Voter },
226
+ {Id : 13 , StoreId : 1 , Role : metapb .PeerRole_Voter },
227
+ },
228
+ }
229
+ region := NewRegionInfo (meta , meta .Peers [0 ])
230
+
231
+ testcases := []struct {
232
+ optionsA []RegionCreateOption
233
+ optionsB []RegionCreateOption
234
+ needSync bool
235
+ }{
236
+ {
237
+ optionsB : []RegionCreateOption {WithLeader (nil )},
238
+ needSync : true ,
239
+ },
240
+ {
241
+ optionsB : []RegionCreateOption {WithLeader (meta .Peers [1 ])},
242
+ needSync : true ,
243
+ },
244
+ {
245
+ optionsB : []RegionCreateOption {WithPendingPeers (meta .Peers [1 :2 ])},
246
+ needSync : true ,
247
+ },
248
+ {
249
+ optionsB : []RegionCreateOption {WithDownPeers ([]* pdpb.PeerStats {{Peer : meta .Peers [1 ], DownSeconds : 600 }})},
250
+ needSync : true ,
251
+ },
252
+ {
253
+ optionsA : []RegionCreateOption {SetWrittenBytes (200 ), WithFlowRoundByDigit (2 )},
254
+ optionsB : []RegionCreateOption {SetWrittenBytes (300 ), WithFlowRoundByDigit (2 )},
255
+ needSync : true ,
256
+ },
257
+ {
258
+ optionsA : []RegionCreateOption {SetWrittenBytes (250 ), WithFlowRoundByDigit (2 )},
259
+ optionsB : []RegionCreateOption {SetWrittenBytes (349 ), WithFlowRoundByDigit (2 )},
260
+ needSync : false ,
261
+ },
262
+ {
263
+ optionsA : []RegionCreateOption {SetWrittenBytes (200 ), WithFlowRoundByDigit (4 )},
264
+ optionsB : []RegionCreateOption {SetWrittenBytes (300 ), WithFlowRoundByDigit (4 )},
265
+ needSync : false ,
266
+ },
267
+ {
268
+ optionsA : []RegionCreateOption {SetWrittenBytes (100000 ), WithFlowRoundByDigit (4 )},
269
+ optionsB : []RegionCreateOption {SetWrittenBytes (200 ), WithFlowRoundByDigit (2 )},
270
+ needSync : true ,
271
+ },
272
+ {
273
+ optionsA : []RegionCreateOption {SetWrittenBytes (100000 ), WithFlowRoundByDigit (127 )},
274
+ optionsB : []RegionCreateOption {SetWrittenBytes (0 ), WithFlowRoundByDigit (2 )},
275
+ needSync : false ,
276
+ },
277
+ {
278
+ optionsA : []RegionCreateOption {SetWrittenBytes (0 ), WithFlowRoundByDigit (2 )},
279
+ optionsB : []RegionCreateOption {SetWrittenBytes (100000 ), WithFlowRoundByDigit (127 )},
280
+ needSync : true ,
281
+ },
282
+ }
283
+
284
+ for _ , t := range testcases {
285
+ regionA := region .Clone (t .optionsA ... )
286
+ regionB := region .Clone (t .optionsB ... )
287
+ _ , _ , _ , needSync := s .RegionGuide (regionA , regionB )
288
+ c .Assert (needSync , Equals , t .needSync )
289
+ }
290
+ }
291
+
207
292
var _ = Suite (& testRegionMapSuite {})
208
293
209
294
type testRegionMapSuite struct {}
0 commit comments