class ReplicaElectionTests(unittest.TestCase): def setUp(self): self.topic = Topic('testTopic', 10) self.broker = Broker(1, 'brokerhost1.example.com') for i in range(10): self.topic.partitions[i].replicas = [self.broker] self.replica_election = ReplicaElection(self.topic.partitions, pause_time=0) def test_replica_election_create(self): assert self.replica_election is not None def test_replica_election_repr(self): t_repr = json.loads(repr(self.replica_election)) expect_repr = {'partitions': []} for i in range(10): expect_repr['partitions'].append({'topic': 'testTopic', 'partition': i}) assert t_repr == expect_repr def test_replica_election_dict(self): t_repr = self.replica_election.dict_for_replica_election() expect_repr = {'partitions': []} for i in range(10): expect_repr['partitions'].append({'topic': 'testTopic', 'partition': i}) assert t_repr == expect_repr @patch('kafka.tools.assigner.models.replica_election.subprocess.call') def test_replica_election_execute(self, mock_call): self.replica_election.execute(1, 1, 'zk_connect_string', '/path/to/tools', plugins=[], dry_run=False) mock_call.assert_called_once_with(['/path/to/tools/kafka-preferred-replica-election.sh', '--zookeeper', 'zk_connect_string', '--path-to-json-file', ANY], stderr=ANY, stdout=ANY)
def test_ple(self, mock_execute, mock_sleep): cluster = set_up_cluster() args = argparse.Namespace(ple_wait=0, zookeeper='zkconnect', tools_path='/path/to/tools') batches = [ReplicaElection(cluster.brokers[1].partitions, args.ple_wait), ReplicaElection(cluster.brokers[2].partitions, args.ple_wait)] run_preferred_replica_elections(batches, args, args.tools_path, [], False) mock_sleep.assert_called_once_with(0) mock_execute.assert_has_calls([call(1, 2, 'zkconnect', '/path/to/tools', [], False), call(2, 2, 'zkconnect', '/path/to/tools', [], False)])
def setUp(self): self.topic = Topic('testTopic', 10) self.broker = Broker(1, 'brokerhost1.example.com') for i in range(10): self.topic.partitions[i].replicas = [self.broker] self.replica_election = ReplicaElection(self.topic.partitions, pause_time=0)