|
6 | 6 | use super::*;
|
7 | 7 | use std::collections::HashSet;
|
8 | 8 | use std::time::Duration;
|
9 |
| -use kafka::client::{KafkaClient, FetchPartition, ProduceMessage, RequiredAcks}; |
| 9 | +use kafka::client::{KafkaClient, PartitionOffset, FetchPartition, ProduceMessage, RequiredAcks}; |
10 | 10 | use kafka::client::fetch::Response;
|
11 | 11 |
|
12 | 12 | fn flatten_fetched_messages(resps: &Vec<Response>) -> Vec<(&str, i32, &[u8])> {
|
@@ -65,9 +65,7 @@ fn test_kafka_client_load_metadata() {
|
65 | 65 |
|
66 | 66 | #[test]
|
67 | 67 | fn test_produce_fetch_messages() {
|
68 |
| - let hosts = vec![LOCAL_KAFKA_BOOTSTRAP_HOST.to_owned()]; |
69 |
| - let mut client = KafkaClient::new(hosts.clone()); |
70 |
| - client.load_metadata_all().unwrap(); |
| 68 | + let mut client = new_ready_kafka_client(); |
71 | 69 |
|
72 | 70 | // first send the messages and verify correct confirmation responses
|
73 | 71 | // from kafka
|
@@ -124,3 +122,35 @@ fn test_produce_fetch_messages() {
|
124 | 122 | .into_iter()
|
125 | 123 | .all(|c_msg| messages.contains(&c_msg)));
|
126 | 124 | }
|
| 125 | + |
| 126 | +#[test] |
| 127 | +fn test_commit_offset() { |
| 128 | + let mut client = new_ready_kafka_client(); |
| 129 | + |
| 130 | + for &(partition, offset) in |
| 131 | + &[(TEST_TOPIC_PARTITIONS[0], 100), |
| 132 | + (TEST_TOPIC_PARTITIONS[1], 200), |
| 133 | + (TEST_TOPIC_PARTITIONS[0], 300), |
| 134 | + (TEST_TOPIC_PARTITIONS[1], 400), |
| 135 | + (TEST_TOPIC_PARTITIONS[0], 500), |
| 136 | + (TEST_TOPIC_PARTITIONS[1], 600)] { |
| 137 | + |
| 138 | + |
| 139 | + client |
| 140 | + .commit_offset(TEST_GROUP_NAME, TEST_TOPIC_NAME, partition, offset) |
| 141 | + .unwrap(); |
| 142 | + |
| 143 | + let partition_offsets: HashSet<PartitionOffset> = client |
| 144 | + .fetch_group_topic_offsets(TEST_GROUP_NAME, TEST_TOPIC_NAME) |
| 145 | + .unwrap() |
| 146 | + .into_iter() |
| 147 | + .collect(); |
| 148 | + |
| 149 | + let correct_partition_offset = PartitionOffset { |
| 150 | + partition: partition, |
| 151 | + offset: offset, |
| 152 | + }; |
| 153 | + |
| 154 | + assert!(partition_offsets.contains(&correct_partition_offset)); |
| 155 | + } |
| 156 | +} |
0 commit comments