def test_get_target_brokers_3(self, create_partition): p10 = create_partition('topic1', 0) p11 = create_partition('topic1', 1) p12 = create_partition('topic1', 2) p20 = create_partition('topic2', 0) p21 = create_partition('topic2', 1) p30 = create_partition('topic3', 0) p31 = create_partition('topic3', 1) b1 = create_broker('b1', [p10, p11, p20]) b2 = create_broker('b2', [p12, p21, p30, p31]) b3 = create_broker('b3', []) rg = ReplicationGroup('rg', set([b1, b2, b3])) over_loaded = [b1, b2] under_loaded = [b3] target = rg._get_target_brokers( over_loaded, under_loaded, rg.generate_sibling_distance(), ) # b3 is the best broker fit because of number of partition # Both p10 and p11 are a good fit. p20 can't be considered because it is # already in b3. assert target == (b2, b3, p30) or target == (b2, b3, p31)
def test__get_target_brokers_1(self, create_partition): p10 = create_partition('topic1', 0, replication_factor=2) p11 = create_partition('topic1', 1, replication_factor=2) p20 = create_partition('topic2', 0, replication_factor=2) p30 = create_partition('topic3', 0) b1 = create_broker('b1', [p10, p11, p20, p30]) b2 = create_broker('b2', [p10, p20]) rg = ReplicationGroup('rg', set([b1, b2])) over_loaded = [b1] under_loaded = [b2] target = rg._get_target_brokers( over_loaded, under_loaded, rg.generate_sibling_distance(), ) # p30 is the best fit because topic3 doesn't have any partition in # broker 2 assert target == (b1, b2, p30) or target == (b1, b2, p11)