@@ -338,6 +338,55 @@ async fn test_produce_consume_size_cutoff() {
338
338
assert ! ( is_kafka ^ is_redpanda) ;
339
339
}
340
340
341
+ #[ tokio:: test]
342
+ async fn test_consume_midbatch ( ) {
343
+ maybe_start_logging ( ) ;
344
+
345
+ let connection = maybe_skip_kafka_integration ! ( ) ;
346
+ let topic_name = random_topic_name ( ) ;
347
+
348
+ let client = ClientBuilder :: new ( vec ! [ connection] ) . build ( ) . await . unwrap ( ) ;
349
+ let controller_client = client. controller_client ( ) . await . unwrap ( ) ;
350
+ controller_client
351
+ . create_topic ( & topic_name, 1 , 1 , 5_000 )
352
+ . await
353
+ . unwrap ( ) ;
354
+
355
+ let partition_client = client. partition_client ( & topic_name, 0 ) . await . unwrap ( ) ;
356
+
357
+ // produce two records into a single batch
358
+ let record_1 = record ( ) ;
359
+ let record_2 = Record {
360
+ value : Some ( b"x" . to_vec ( ) ) ,
361
+ timestamp : now ( ) ,
362
+ ..record_1. clone ( )
363
+ } ;
364
+
365
+ let offsets = partition_client
366
+ . produce (
367
+ vec ! [ record_1. clone( ) , record_2. clone( ) ] ,
368
+ Compression :: NoCompression ,
369
+ )
370
+ . await
371
+ . unwrap ( ) ;
372
+ let _offset_1 = offsets[ 0 ] ;
373
+ let offset_2 = offsets[ 1 ] ;
374
+
375
+ // when fetching from the middle of the record batch, the server will return both records but we should filter out
376
+ // the first one on the client side
377
+ let ( records, _watermark) = partition_client
378
+ . fetch_records ( offset_2, 1 ..10_000 , 1_000 )
379
+ . await
380
+ . unwrap ( ) ;
381
+ assert_eq ! (
382
+ records,
383
+ vec![ RecordAndOffset {
384
+ record: record_2,
385
+ offset: offset_2
386
+ } , ] ,
387
+ ) ;
388
+ }
389
+
341
390
#[ tokio:: test]
342
391
async fn test_delete_records ( ) {
343
392
maybe_start_logging ( ) ;
@@ -429,18 +478,15 @@ async fn test_delete_records() {
429
478
ClientError :: ServerError ( ProtocolError :: OffsetOutOfRange , _)
430
479
) ;
431
480
432
- // fetching untouched records still works, however the middle record batch is NOT half-deleted and still contains record_2
481
+ // fetching untouched records still works, however the middle record batch is NOT half-deleted and still contains
482
+ // record_2. `fetch_records` should filter this however.
433
483
let ( records, _watermark) = partition_client
434
484
. fetch_records ( offset_3, 1 ..10_000 , 1_000 )
435
485
. await
436
486
. unwrap ( ) ;
437
487
assert_eq ! (
438
488
records,
439
489
vec![
440
- RecordAndOffset {
441
- record: record_2,
442
- offset: offset_2
443
- } ,
444
490
RecordAndOffset {
445
491
record: record_3,
446
492
offset: offset_3
0 commit comments