69
69
import org .apache .kafka .clients .consumer .ConsumerRecords ;
70
70
import org .apache .kafka .clients .consumer .KafkaConsumer ;
71
71
import org .apache .kafka .clients .consumer .OffsetAndMetadata ;
72
+ import org .apache .kafka .clients .consumer .OffsetAndTimestamp ;
72
73
import org .apache .kafka .clients .consumer .OffsetCommitCallback ;
73
74
import org .apache .kafka .clients .consumer .RetriableCommitFailedException ;
74
75
import org .apache .kafka .clients .producer .ProducerConfig ;
137
138
KafkaMessageListenerContainerTests .topic17 , KafkaMessageListenerContainerTests .topic18 ,
138
139
KafkaMessageListenerContainerTests .topic19 , KafkaMessageListenerContainerTests .topic20 ,
139
140
KafkaMessageListenerContainerTests .topic21 , KafkaMessageListenerContainerTests .topic22 ,
140
- KafkaMessageListenerContainerTests .topic23 })
141
+ KafkaMessageListenerContainerTests .topic23 , KafkaMessageListenerContainerTests . topic24 })
141
142
public class KafkaMessageListenerContainerTests {
142
143
143
144
private final LogAccessor logger = new LogAccessor (LogFactory .getLog (this .getClass ()));
@@ -190,6 +191,8 @@ public class KafkaMessageListenerContainerTests {
190
191
191
192
public static final String topic24 = "testTopic24" ;
192
193
194
+ public static final String topic25 = "testTopic24" ;
195
+
193
196
private static EmbeddedKafkaBroker embeddedKafka ;
194
197
195
198
@ BeforeAll
@@ -2542,15 +2545,20 @@ public void testInitialSeek() throws Exception {
2542
2545
Thread .sleep (50 );
2543
2546
return emptyRecords ;
2544
2547
});
2545
- TopicPartitionOffset [] topicPartition = new TopicPartitionOffset [] {
2548
+
2549
+ Map <TopicPartition , OffsetAndTimestamp > offsets = new HashMap <>();
2550
+ offsets .put (new TopicPartition ("foo" , 6 ), new OffsetAndTimestamp (42L , 1234L ));
2551
+ offsets .put (new TopicPartition ("foo" , 7 ), null );
2552
+ given (consumer .offsetsForTimes (any ())).willReturn (offsets );
2553
+ ContainerProperties containerProps = new ContainerProperties (
2546
2554
new TopicPartitionOffset ("foo" , 0 , SeekPosition .BEGINNING ),
2547
2555
new TopicPartitionOffset ("foo" , 1 , SeekPosition .END ),
2548
2556
new TopicPartitionOffset ("foo" , 2 , 0L ),
2549
2557
new TopicPartitionOffset ("foo" , 3 , Long .MAX_VALUE ),
2550
2558
new TopicPartitionOffset ("foo" , 4 , SeekPosition .BEGINNING ),
2551
2559
new TopicPartitionOffset ("foo" , 5 , SeekPosition .END ),
2552
- };
2553
- ContainerProperties containerProps = new ContainerProperties ( topicPartition );
2560
+ new TopicPartitionOffset ( "foo" , 6 , 1234L , SeekPosition . TIMESTAMP ),
2561
+ new TopicPartitionOffset ( "foo" , 7 , 1234L , SeekPosition . TIMESTAMP ) );
2554
2562
containerProps .setGroupId ("grp" );
2555
2563
containerProps .setAckMode (AckMode .RECORD );
2556
2564
containerProps .setClientId ("clientId" );
@@ -2566,9 +2574,11 @@ public void testInitialSeek() throws Exception {
2566
2574
.isEqualTo (new HashSet <>(Arrays .asList (new TopicPartition ("foo" , 0 ), new TopicPartition ("foo" , 4 ))));
2567
2575
verify (consumer ).seekToEnd (captor .capture ());
2568
2576
assertThat (captor .getValue ())
2569
- .isEqualTo (new HashSet <>(Arrays .asList (new TopicPartition ("foo" , 1 ), new TopicPartition ("foo" , 5 ))));
2577
+ .isEqualTo (new HashSet <>(Arrays .asList (new TopicPartition ("foo" , 1 ), new TopicPartition ("foo" , 5 ),
2578
+ new TopicPartition ("foo" , 7 ))));
2570
2579
verify (consumer ).seek (new TopicPartition ("foo" , 2 ), 0L );
2571
2580
verify (consumer ).seek (new TopicPartition ("foo" , 3 ), Long .MAX_VALUE );
2581
+ verify (consumer ).seek (new TopicPartition ("foo" , 6 ), 42L );
2572
2582
container .stop ();
2573
2583
}
2574
2584
0 commit comments