def test__elect_dest_broker_partition_conflict(self, create_partition): p1 = create_partition('t1', 0) p2 = create_partition('t2', 0) p3 = create_partition('t1', 1) b1 = create_broker('b1', [p1, p2, p3]) # b1 -> t1: {0,1}, t2: 0 rg = ReplicationGroup('test_rg', set([b1])) # p1 already exists in b1 # This should never happen and we expect the application to fail badly victim_partition = p1 assert None is rg._elect_dest_broker(victim_partition)
def test__elect_dest_broker_partition_conflict(self, create_partition): p1 = create_partition('t1', 0) p2 = create_partition('t2', 0) p3 = create_partition('t1', 1) b1 = create_broker('b1', [p1, p2, p3]) # b1 -> t1: {0,1}, t2: 0 rg = ReplicationGroup('test_rg', set([b1])) # p1 already exists in b1 # This should never happen and we expect the application to fail badly victim_partition = p1 assert None is rg._elect_dest_broker(victim_partition)
def test__elect_dest_broker(self, create_partition): p10 = create_partition('t1', 0) p11 = create_partition('t1', 1) p20 = create_partition('t2', 0) p30 = create_partition('t3', 0) b1 = create_broker('b1', [p10, p20, p11]) # b1 -> t1: {0,1}, t2: 0 b2 = create_broker('b2', [p10, p30]) # b2 -> t1: 0, t3: 0 rg = ReplicationGroup('test_rg', set([b1, b2])) # Since p30 is already in b2 so the preferred destination will be b1 # although b2 has less partitions. victim_partition = p30 actual = rg._elect_dest_broker(victim_partition) assert actual == b1
def test__elect_dest_broker(self, create_partition): p10 = create_partition('t1', 0) p11 = create_partition('t1', 1) p20 = create_partition('t2', 0) p30 = create_partition('t3', 0) b1 = create_broker('b1', [p10, p20, p11]) # b1 -> t1: {0,1}, t2: 0 b2 = create_broker('b2', [p10, p30]) # b2 -> t1: 0, t3: 0 rg = ReplicationGroup('test_rg', set([b1, b2])) # Since p30 is already in b2 so the preferred destination will be b1 # although b2 has less partitions. victim_partition = p30 actual = rg._elect_dest_broker(victim_partition) assert actual == b1
def test__elect_dest_broker_prefer_less_siblings(self, create_partition): p10 = create_partition('t1', 0) p11 = create_partition('t1', 1) p20 = create_partition('t2', 0) b1 = create_broker('b1', [p10, p11, p20]) # b1 -> t1: {0,1}, t2: 0 p30 = create_partition('t3', 0) p31 = create_partition('t3', 1) p32 = create_partition('t3', 2) b2 = create_broker('b2', [p10, p30, p31, p32]) # b2 -> t1: 0, t3: 0 rg = ReplicationGroup('test_rg', set([b1, b2])) # Since t1 has two partitions in b1 but only one in b2, # the preferred destination should be b2 victim_partition_p12 = create_partition('t1', 2) actual = rg._elect_dest_broker(victim_partition_p12) assert actual == b2
def test__elect_dest_broker_prefer_less_siblings(self, create_partition): p10 = create_partition('t1', 0) p11 = create_partition('t1', 1) p20 = create_partition('t2', 0) b1 = create_broker('b1', [p10, p11, p20]) # b1 -> t1: {0,1}, t2: 0 p30 = create_partition('t3', 0) p31 = create_partition('t3', 1) p32 = create_partition('t3', 2) b2 = create_broker('b2', [p10, p30, p31, p32]) # b2 -> t1: 0, t3: 0 rg = ReplicationGroup('test_rg', set([b1, b2])) # Since t1 has two partitions in b1 but only one in b2, # the preferred destination should be b2 victim_partition_p12 = create_partition('t1', 2) actual = rg._elect_dest_broker(victim_partition_p12) assert actual == b2