def test_try_pick_swap_partition_full(self, mock_check): action = ActionBalanceRackAware(self.args, self.cluster) small_partitions = [ self.cluster.topics['testTopic1'].partitions[0], self.cluster.topics['testTopic1'].partitions[1] ] large_partitions = [self.cluster.topics['testTopic2'].partitions[0]] p = self.cluster.topics['testTopic2'].partitions[1] small_partitions[0].size = 1000 small_partitions[1].size = 2000 large_partitions[0].size = 4000 p.size = 3000 mock_check.side_effect = [False, False, True] target = action._try_pick_swap_partition(p, 0, small_partitions, large_partitions) b1 = self.cluster.brokers[1] b2 = self.cluster.brokers[2] mock_check.assert_has_calls([ call([b1, b2], [b2, b1], 0), call([b1, b2], [b2, b1], 0), call([b1, b2], [b1, b2], 0) ]) assert target == self.cluster.topics['testTopic1'].partitions[0]
def test_try_pick_swap_partitions_nolarge(self, mock_check): action = ActionBalanceRackAware(self.args, self.cluster) large_partitions = [] small_partitions = [self.cluster.topics['testTopic2'].partitions[0]] p = self.cluster.topics['testTopic2'].partitions[1] small_partitions[0].size = 1000 p.size = 3000 mock_check.return_value = True assert action._try_pick_swap_partition(p, 0, small_partitions, large_partitions) == self.cluster.topics['testTopic2'].partitions[0]
def test_try_pick_swap_partition_none(self): action = ActionBalanceRackAware(self.args, self.cluster) small_partitions = [self.cluster.topics['testTopic1'].partitions[0], self.cluster.topics['testTopic1'].partitions[1]] large_partitions = [self.cluster.topics['testTopic2'].partitions[0]] p = self.cluster.topics['testTopic2'].partitions[1] small_partitions[0].size = 1000 small_partitions[1].size = 2000 large_partitions[0].size = 4000 p.size = 3000 assert action._try_pick_swap_partition(p, 0, small_partitions, large_partitions) is None
def test_try_pick_swap_partitions_nolarge(self, mock_check): action = ActionBalanceRackAware(self.args, self.cluster) large_partitions = [] small_partitions = [self.cluster.topics['testTopic2'].partitions[0]] p = self.cluster.topics['testTopic2'].partitions[1] small_partitions[0].size = 1000 p.size = 3000 mock_check.return_value = True assert action._try_pick_swap_partition( p, 0, small_partitions, large_partitions ) == self.cluster.topics['testTopic2'].partitions[0]
def test_try_pick_swap_partition_none(self): action = ActionBalanceRackAware(self.args, self.cluster) small_partitions = [ self.cluster.topics['testTopic1'].partitions[0], self.cluster.topics['testTopic1'].partitions[1] ] large_partitions = [self.cluster.topics['testTopic2'].partitions[0]] p = self.cluster.topics['testTopic2'].partitions[1] small_partitions[0].size = 1000 small_partitions[1].size = 2000 large_partitions[0].size = 4000 p.size = 3000 assert action._try_pick_swap_partition(p, 0, small_partitions, large_partitions) is None
def test_try_pick_swap_partition_full(self, mock_check): action = ActionBalanceRackAware(self.args, self.cluster) small_partitions = [self.cluster.topics['testTopic1'].partitions[0], self.cluster.topics['testTopic1'].partitions[1]] large_partitions = [self.cluster.topics['testTopic2'].partitions[0]] p = self.cluster.topics['testTopic2'].partitions[1] small_partitions[0].size = 1000 small_partitions[1].size = 2000 large_partitions[0].size = 4000 p.size = 3000 mock_check.side_effect = [False, False, True] target = action._try_pick_swap_partition(p, 0, small_partitions, large_partitions) b1 = self.cluster.brokers[1] b2 = self.cluster.brokers[2] mock_check.assert_has_calls([call([b1, b2], [b2, b1], 0), call([b1, b2], [b2, b1], 0), call([b1, b2], [b1, b2], 0)]) assert target == self.cluster.topics['testTopic1'].partitions[0]