Example #1
0
 def list_topics(self, topic: str) -> ClusterMetadata:
     meta = ClusterMetadata()
     topic_meta = TopicMetadata()
     topic_meta.topic = topic
     topic_meta.partitions = {0: PartitionMetadata()}
     meta.topics = {topic: topic_meta}
     return meta
Example #2
0
def generate_value_for_list_topics(binary_messages: List[BinaryMessage],
                                   topic_id: str) -> ClusterMetadata:
    cluster_meta = ClusterMetadata()
    topic_meta = TopicMetadata()
    topic_meta.partitions = {msg.partition: None for msg in binary_messages}
    cluster_meta.topics = {topic_id: topic_meta}
    return cluster_meta
Example #3
0
def create_cluster_metadata(topic_partitions):
    """Create ClusterMetada out of a dict structure for easier mocking.

    topic_partitions should be in the format of {'topic1': [partition1, partition2], 'topic2': [partition3]...}
    """
    cluster_metadata = ClusterMetadata()
    topics_dict = {}
    for topic in topic_partitions.keys():
        topic_metadata = TopicMetadata()
        partitions = topic_partitions[topic]
        partitions_dict = {}
        for partition in partitions:
            partition_metadata = PartitionMetadata()
            partition_metadata.id = partition
            partitions_dict.update({partition: partition_metadata})
        topic_metadata.partitions = partitions_dict
        topic_metadata.topic = topic
        topics_dict.update({topic: topic_metadata})
    cluster_metadata.topics = topics_dict
    return cluster_metadata
Example #4
0
    def list_topics(self, timeout=-1):
        '''
        Mock AdminClient returns a description of
        topic from test_data/test_metadata_one_topic.json
        '''
        test_topic_metadata = TopicMetadata()
        test_topic_metadata.partitions = {
            0: PartitionMetadata(),
            1: PartitionMetadata(),
            2: PartitionMetadata()
        }

        raw_metadata = ClusterMetadata()
        raw_metadata.topics = {
            "temperature": test_topic_metadata,
            "__consumer_offsets": test_topic_metadata
        }
        raw_metadata.cluster_id = "1234"
        raw_metadata.brokers = {
            "testBroker0": BrokerMetadata(),
            "testBroker1": BrokerMetadata()
        }
        return raw_metadata
def topic(name, partitions=[]):
    tm = TopicMetadata()
    tm.topic = name
    tm.partitions = {p.partition: p for p in partitions}
    return tm