|
| 1 | +use assert_matches::assert_matches; |
1 | 2 | use rskafka::{
|
2 | 3 | client::{
|
3 | 4 | error::{Error as ClientError, ProtocolError},
|
@@ -157,6 +158,63 @@ async fn test_produce_empty() {
|
157 | 158 | .unwrap();
|
158 | 159 | }
|
159 | 160 |
|
| 161 | +#[tokio::test] |
| 162 | +async fn test_consume_empty() { |
| 163 | + maybe_start_logging(); |
| 164 | + |
| 165 | + let connection = maybe_skip_kafka_integration!(); |
| 166 | + let topic_name = random_topic_name(); |
| 167 | + let n_partitions = 2; |
| 168 | + |
| 169 | + let client = ClientBuilder::new(vec![connection]).build().await.unwrap(); |
| 170 | + let controller_client = client.controller_client().await.unwrap(); |
| 171 | + controller_client |
| 172 | + .create_topic(&topic_name, n_partitions, 1, 5_000) |
| 173 | + .await |
| 174 | + .unwrap(); |
| 175 | + |
| 176 | + let partition_client = client.partition_client(&topic_name, 1).await.unwrap(); |
| 177 | + let (records, watermark) = partition_client |
| 178 | + .fetch_records(0, 1..10_000, 1_000) |
| 179 | + .await |
| 180 | + .unwrap(); |
| 181 | + assert!(records.is_empty()); |
| 182 | + assert_eq!(watermark, 0); |
| 183 | +} |
| 184 | + |
| 185 | +#[tokio::test] |
| 186 | +async fn test_consume_offset_out_of_range() { |
| 187 | + maybe_start_logging(); |
| 188 | + |
| 189 | + let connection = maybe_skip_kafka_integration!(); |
| 190 | + let topic_name = random_topic_name(); |
| 191 | + let n_partitions = 2; |
| 192 | + |
| 193 | + let client = ClientBuilder::new(vec![connection]).build().await.unwrap(); |
| 194 | + let controller_client = client.controller_client().await.unwrap(); |
| 195 | + controller_client |
| 196 | + .create_topic(&topic_name, n_partitions, 1, 5_000) |
| 197 | + .await |
| 198 | + .unwrap(); |
| 199 | + |
| 200 | + let partition_client = client.partition_client(&topic_name, 1).await.unwrap(); |
| 201 | + let record = record(); |
| 202 | + let offsets = partition_client |
| 203 | + .produce(vec![record], Compression::NoCompression) |
| 204 | + .await |
| 205 | + .unwrap(); |
| 206 | + let offset = offsets[0]; |
| 207 | + |
| 208 | + let err = partition_client |
| 209 | + .fetch_records(offset + 2, 1..10_000, 1_000) |
| 210 | + .await |
| 211 | + .unwrap_err(); |
| 212 | + assert_matches!( |
| 213 | + err, |
| 214 | + ClientError::ServerError(ProtocolError::OffsetOutOfRange, _) |
| 215 | + ); |
| 216 | +} |
| 217 | + |
160 | 218 | #[tokio::test]
|
161 | 219 | async fn test_get_high_watermark() {
|
162 | 220 | maybe_start_logging();
|
|
0 commit comments