def test_add_partition_to_topic(self): partition2 = Partition(self.topic, 1) self.topic.add_partition(partition2) assert len(self.topic.partitions) == 2 assert self.topic.partitions[1].topic == self.topic assert self.topic.partitions[1].num == 1 assert self.topic.partitions[1].replicas == [] assert self.topic.partitions[1].size == 0
def __init__(self, name, partitions): self.name = name self.partitions = [] self.cluster = None self.retention = 1 for i in range(partitions): self.add_partition(Partition(self, i))
def test_add_or_update_replica_swap(self): broker1 = Broker('host1.example.com', id=1, port=8031) broker2 = Broker('host2.example.com', id=101, port=8032) partition = Partition('topic1', 0) partition.add_replica(broker1) partition.add_replica(broker2) partition.add_or_update_replica(1, broker1) assert partition.replicas[1] == broker1
def __init__(self, name, partitions): self.name = name self.partitions = [] self.cluster = None self.internal = False self.retention = 1 self._last_updated = time.time() for i in range(partitions): self.add_partition(Partition(self, i))
def assure_has_partitions(self, target_count): """ Assure that the topic has only the specified number of partitions, adding or deleting as needed Args: target_count (int): the number of partitions to have """ while len(self.partitions) < target_count: partition = Partition(self.name, len(self.partitions)) self.add_partition(partition) # While Kafka doesn't support partition deletion (only topics), it's possible for a topic # to be deleted and recreated with a smaller partition count before we see that it's been # deleted. This would look like partition deletion, so we should support it. while len(self.partitions) > target_count: partition = self.partitions.pop() partition.delete_replicas(0)
def test_partition_inequality_on_partition_num(self): partition2 = Partition(self.topic, 1) assert self.topic.partitions[0] != partition2
def test_partition_equality_with_different_replicas(self): partition2 = Partition(self.topic, 0) broker = Broker('testhost1', id=1) partition2.replicas = [broker] assert self.topic.partitions[0] == partition2
def test_partition_equality(self): partition2 = Partition(self.topic, 0) assert self.topic.partitions[0] == partition2