@@ -281,6 +281,141 @@ def test_parse_cluster_node_reply_failure_flags
281281 assert_empty ( @test_node . send ( :parse_cluster_node_reply , info ) )
282282 end
283283
284+ def test_parse_cluster_slots_reply
285+ reply = [
286+ [
287+ 0 ,
288+ 5460 ,
289+ [ '10.10.1.6' , 6379 , '00c0d00f2a5eda22b2c8a8929ba27b454c4400fb' , { } ] ,
290+ [ '10.10.1.5' , 6379 , 'b60c0672f257c01d76f27eacded14b6e6f4f990e' , { } ]
291+ ] ,
292+ [
293+ 5461 ,
294+ 10_922 ,
295+ [ '10.10.1.4' , 6379 , '712b9a6656b38a5e002244903853fccb4d1eef4b' , { } ] ,
296+ [ '10.10.1.7' , 6379 , '7038691c545e7caa9147030ecfb4acf1eaad0552' , { } ]
297+ ] ,
298+ [
299+ 10_923 ,
300+ 16_383 ,
301+ [ '10.10.1.8' , 6379 , 'ba85d0807043bb40f72bb4e1e8352b029c6e0082' , { } ] ,
302+ [ '10.10.1.3' , 6379 , 'f2f36b472b187c577ccd93dd296e9045f473ae7a' , { } ]
303+ ]
304+ ]
305+
306+ want = [
307+ { id : '00c0d00f2a5eda22b2c8a8929ba27b454c4400fb' , node_key : '10.10.1.6:6379' , role : 'master' , primary_id : nil ,
308+ ping_sent : nil , pong_recv : nil , config_epoch : nil , link_state : nil , slots : [ [ 0 , 5460 ] ] } ,
309+ { id : 'b60c0672f257c01d76f27eacded14b6e6f4f990e' , node_key : '10.10.1.5:6379' , role : 'slave' , primary_id : '00c0d00f2a5eda22b2c8a8929ba27b454c4400fb' ,
310+ ping_sent : nil , pong_recv : nil , config_epoch : nil , link_state : nil , slots : [ ] } ,
311+ { id : '712b9a6656b38a5e002244903853fccb4d1eef4b' , node_key : '10.10.1.4:6379' , role : 'master' , primary_id : nil ,
312+ ping_sent : nil , pong_recv : nil , config_epoch : nil , link_state : nil , slots : [ [ 5461 , 10_922 ] ] } ,
313+ { id : '7038691c545e7caa9147030ecfb4acf1eaad0552' , node_key : '10.10.1.7:6379' , role : 'slave' , primary_id : '712b9a6656b38a5e002244903853fccb4d1eef4b' ,
314+ ping_sent : nil , pong_recv : nil , config_epoch : nil , link_state : nil , slots : [ ] } ,
315+ { id : 'ba85d0807043bb40f72bb4e1e8352b029c6e0082' , node_key : '10.10.1.8:6379' , role : 'master' , primary_id : nil ,
316+ ping_sent : nil , pong_recv : nil , config_epoch : nil , link_state : nil , slots : [ [ 10_923 , 16_383 ] ] } ,
317+ { id : 'f2f36b472b187c577ccd93dd296e9045f473ae7a' , node_key : '10.10.1.3:6379' , role : 'slave' , primary_id : 'ba85d0807043bb40f72bb4e1e8352b029c6e0082' ,
318+ ping_sent : nil , pong_recv : nil , config_epoch : nil , link_state : nil , slots : [ ] }
319+ ]
320+
321+ got = @test_node . send ( :parse_cluster_slots_reply , reply )
322+
323+ assert_equal ( want . sort_by { |e | e . fetch ( :id ) } , got . sort_by ( &:id ) . map ( &:to_h ) )
324+ end
325+
326+ def test_parse_cluster_shards_reply
327+ reply = [
328+ {
329+ 'slots' => [ 5461 , 10_922 ] ,
330+ 'nodes' => [
331+ {
332+ 'id' => '712b9a6656b38a5e002244903853fccb4d1eef4b' ,
333+ 'port' => 6379 ,
334+ 'ip' => '10.10.1.4' ,
335+ 'endpoint' => '10.10.1.4' ,
336+ 'role' => 'master' ,
337+ 'replication-offset' => 98 ,
338+ 'health' => 'online'
339+ } ,
340+ {
341+ 'id' => '7038691c545e7caa9147030ecfb4acf1eaad0552' ,
342+ 'port' => 6379 ,
343+ 'ip' => '10.10.1.7' ,
344+ 'endpoint' => '10.10.1.7' ,
345+ 'role' => 'replica' ,
346+ 'replication-offset' => 98 ,
347+ 'health' => 'online'
348+ }
349+ ]
350+ } ,
351+ {
352+ 'slots' => [ 10_923 , 16_383 ] ,
353+ 'nodes' => [
354+ {
355+ 'id' => 'ba85d0807043bb40f72bb4e1e8352b029c6e0082' ,
356+ 'port' => 6379 ,
357+ 'ip' => '10.10.1.8' ,
358+ 'endpoint' => '10.10.1.8' ,
359+ 'role' => 'master' ,
360+ 'replication-offset' => 98 ,
361+ 'health' => 'online'
362+ } ,
363+ {
364+ 'id' => 'f2f36b472b187c577ccd93dd296e9045f473ae7a' ,
365+ 'port' => 6379 ,
366+ 'ip' => '10.10.1.3' ,
367+ 'endpoint' => '10.10.1.3' ,
368+ 'role' => 'replica' ,
369+ 'replication-offset' => 98 ,
370+ 'health' => 'online'
371+ }
372+ ]
373+ } ,
374+ {
375+ 'slots' => [ 0 , 5460 ] ,
376+ 'nodes' => [
377+ {
378+ 'id' => '00c0d00f2a5eda22b2c8a8929ba27b454c4400fb' ,
379+ 'port' => 6379 ,
380+ 'ip' => '10.10.1.6' ,
381+ 'endpoint' => '10.10.1.6' ,
382+ 'role' => 'master' ,
383+ 'replication-offset' => 98 ,
384+ 'health' => 'online'
385+ } ,
386+ {
387+ 'id' => 'b60c0672f257c01d76f27eacded14b6e6f4f990e' ,
388+ 'port' => 6379 ,
389+ 'ip' => '10.10.1.5' ,
390+ 'endpoint' => '10.10.1.5' ,
391+ 'role' => 'replica' ,
392+ 'replication-offset' => 98 ,
393+ 'health' => 'online'
394+ }
395+ ]
396+ }
397+ ]
398+
399+ want = [
400+ { id : '00c0d00f2a5eda22b2c8a8929ba27b454c4400fb' , node_key : '10.10.1.6:6379' , role : 'master' , primary_id : nil ,
401+ ping_sent : nil , pong_recv : nil , config_epoch : nil , link_state : nil , slots : [ [ 0 , 5460 ] ] } ,
402+ { id : 'b60c0672f257c01d76f27eacded14b6e6f4f990e' , node_key : '10.10.1.5:6379' , role : 'slave' , primary_id : '00c0d00f2a5eda22b2c8a8929ba27b454c4400fb' ,
403+ ping_sent : nil , pong_recv : nil , config_epoch : nil , link_state : nil , slots : [ ] } ,
404+ { id : '712b9a6656b38a5e002244903853fccb4d1eef4b' , node_key : '10.10.1.4:6379' , role : 'master' , primary_id : nil ,
405+ ping_sent : nil , pong_recv : nil , config_epoch : nil , link_state : nil , slots : [ [ 5461 , 10_922 ] ] } ,
406+ { id : '7038691c545e7caa9147030ecfb4acf1eaad0552' , node_key : '10.10.1.7:6379' , role : 'slave' , primary_id : '712b9a6656b38a5e002244903853fccb4d1eef4b' ,
407+ ping_sent : nil , pong_recv : nil , config_epoch : nil , link_state : nil , slots : [ ] } ,
408+ { id : 'ba85d0807043bb40f72bb4e1e8352b029c6e0082' , node_key : '10.10.1.8:6379' , role : 'master' , primary_id : nil ,
409+ ping_sent : nil , pong_recv : nil , config_epoch : nil , link_state : nil , slots : [ [ 10_923 , 16_383 ] ] } ,
410+ { id : 'f2f36b472b187c577ccd93dd296e9045f473ae7a' , node_key : '10.10.1.3:6379' , role : 'slave' , primary_id : 'ba85d0807043bb40f72bb4e1e8352b029c6e0082' ,
411+ ping_sent : nil , pong_recv : nil , config_epoch : nil , link_state : nil , slots : [ ] }
412+ ]
413+
414+ got = @test_node . send ( :parse_cluster_shards_reply , reply )
415+
416+ assert_equal ( want . sort_by { |e | e . fetch ( :id ) } , got . sort_by ( &:id ) . map ( &:to_h ) )
417+ end
418+
284419 def test_inspect
285420 assert_match ( /^#<RedisClient::Cluster::Node [0-9., :]*>$/ , @test_node . inspect )
286421 end
0 commit comments