<commit_before>//! Test metadata fetch, group membership, consumer metadata.
extern crate env_logger;
extern crate futures;
extern crate rand;
extern crate rdkafka;

use futures::*;

use rdkafka::consumer::Consumer;
use rdkafka::topic_partition_list::TopicPartitionList;

mod utils;
use utils::*;


#[test]
fn test_metadata() {
    let _r = env_logger::init();

    let topic_name = rand_test_topic();
    populate_topic(&topic_name, 1, &value_fn, &key_fn, Some(0), None);
    populate_topic(&topic_name, 1, &value_fn, &key_fn, Some(1), None);
    populate_topic(&topic_name, 1, &value_fn, &key_fn, Some(2), None);
    let consumer = create_stream_consumer(&rand_test_group(), None);

    let metadata = consumer.fetch_metadata(None, 5000).unwrap();
    assert_eq!(metadata.orig_broker_id(), -1);
    assert_eq!(metadata.orig_broker_name(), "localhost:9092/bootstrap");

    let broker_metadata = metadata.brokers();
    assert_eq!(broker_metadata.len(), 1);
    assert_eq!(broker_metadata[0].id(), 0);
    assert!(broker_metadata[0].host().len() > 0);
    assert_eq!(broker_metadata[0].port(), 9092);

    let topic_metadata = metadata.topics().iter()
        .find(|m| m.name() == topic_name).unwrap();

    let mut ids = topic_metadata.partitions().iter()
        .map(|p| {
            assert_eq!(p.error(), None);
            p.id()
        })
        .collect::<Vec<_>>();
    ids.sort();

    assert_eq!(ids, vec![0, 1, 2]);
    assert_eq!(topic_metadata.error(), None);
    assert_eq!(topic_metadata.partitions().len(), 3);
    assert_eq!(topic_metadata.partitions()[0].leader(), 0);
    assert_eq!(topic_metadata.partitions()[1].leader(), 0);
    assert_eq!(topic_metadata.partitions()[2].leader(), 0);
    assert_eq!(topic_metadata.partitions()[0].replicas(), &[0]);
    assert_eq!(topic_metadata.partitions()[0].isr(), &[0]);

    let metadata_one_topic = consumer.fetch_metadata(Some(&topic_name), 5000).unwrap();
    assert_eq!(metadata_one_topic.topics().len(), 1);
}<commit_msg>Fix test<commit_after>//! Test metadata fetch, group membership, consumer metadata.
extern crate env_logger;
extern crate futures;
extern crate rand;
extern crate rdkafka;

use futures::*;

use rdkafka::consumer::Consumer;
use rdkafka::topic_partition_list::TopicPartitionList;

mod utils;
use utils::*;


#[test]
fn test_metadata() {
    let _r = env_logger::init();

    let topic_name = rand_test_topic();
    populate_topic(&topic_name, 1, &value_fn, &key_fn, Some(0), None);
    populate_topic(&topic_name, 1, &value_fn, &key_fn, Some(1), None);
    populate_topic(&topic_name, 1, &value_fn, &key_fn, Some(2), None);
    let consumer = create_stream_consumer(&rand_test_group(), None);

    let metadata = consumer.fetch_metadata(None, 5000).unwrap();
    assert_eq!(metadata.orig_broker_id(), -1);
    assert!(metadata.orig_broker_name().len() > 0);

    let broker_metadata = metadata.brokers();
    assert_eq!(broker_metadata.len(), 1);
    assert_eq!(broker_metadata[0].id(), 0);
    assert!(broker_metadata[0].host().len() > 0);
    assert_eq!(broker_metadata[0].port(), 9092);

    let topic_metadata = metadata.topics().iter()
        .find(|m| m.name() == topic_name).unwrap();

    let mut ids = topic_metadata.partitions().iter()
        .map(|p| {
            assert_eq!(p.error(), None);
            p.id()
        })
        .collect::<Vec<_>>();
    ids.sort();

    assert_eq!(ids, vec![0, 1, 2]);
    assert_eq!(topic_metadata.error(), None);
    assert_eq!(topic_metadata.partitions().len(), 3);
    assert_eq!(topic_metadata.partitions()[0].leader(), 0);
    assert_eq!(topic_metadata.partitions()[1].leader(), 0);
    assert_eq!(topic_metadata.partitions()[2].leader(), 0);
    assert_eq!(topic_metadata.partitions()[0].replicas(), &[0]);
    assert_eq!(topic_metadata.partitions()[0].isr(), &[0]);

    let metadata_one_topic = consumer.fetch_metadata(Some(&topic_name), 5000).unwrap();
    assert_eq!(metadata_one_topic.topics().len(), 1);
}
{'fraction_non_alphanumeric': 0.17904040404040403, 'fraction_numerical': 0.021464646464646464, 'mean_word_length': 4.586741889985896, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7021716', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1315, 'n_words': 241}