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 ;
138
139
KafkaMessageListenerContainerTests .topic17 , KafkaMessageListenerContainerTests .topic18 ,
139
140
KafkaMessageListenerContainerTests .topic19 , KafkaMessageListenerContainerTests .topic20 ,
140
141
KafkaMessageListenerContainerTests .topic21 , KafkaMessageListenerContainerTests .topic22 ,
141
- KafkaMessageListenerContainerTests .topic23 })
142
+ KafkaMessageListenerContainerTests .topic23 , KafkaMessageListenerContainerTests . topic24 })
142
143
public class KafkaMessageListenerContainerTests {
143
144
144
145
private final LogAccessor logger = new LogAccessor (LogFactory .getLog (this .getClass ()));
@@ -191,6 +192,8 @@ public class KafkaMessageListenerContainerTests {
191
192
192
193
public static final String topic24 = "testTopic24" ;
193
194
195
+ public static final String topic25 = "testTopic24" ;
196
+
194
197
private static EmbeddedKafkaBroker embeddedKafka ;
195
198
196
199
@ BeforeAll
@@ -2758,15 +2761,20 @@ public void testInitialSeek() throws Exception {
2758
2761
Thread .sleep (50 );
2759
2762
return emptyRecords ;
2760
2763
});
2761
- TopicPartitionOffset [] topicPartition = new TopicPartitionOffset [] {
2764
+
2765
+ Map <TopicPartition , OffsetAndTimestamp > offsets = new HashMap <>();
2766
+ offsets .put (new TopicPartition ("foo" , 6 ), new OffsetAndTimestamp (42L , 1234L ));
2767
+ offsets .put (new TopicPartition ("foo" , 7 ), null );
2768
+ given (consumer .offsetsForTimes (any ())).willReturn (offsets );
2769
+ ContainerProperties containerProps = new ContainerProperties (
2762
2770
new TopicPartitionOffset ("foo" , 0 , SeekPosition .BEGINNING ),
2763
2771
new TopicPartitionOffset ("foo" , 1 , SeekPosition .END ),
2764
2772
new TopicPartitionOffset ("foo" , 2 , 0L ),
2765
2773
new TopicPartitionOffset ("foo" , 3 , Long .MAX_VALUE ),
2766
2774
new TopicPartitionOffset ("foo" , 4 , SeekPosition .BEGINNING ),
2767
2775
new TopicPartitionOffset ("foo" , 5 , SeekPosition .END ),
2768
- };
2769
- ContainerProperties containerProps = new ContainerProperties ( topicPartition );
2776
+ new TopicPartitionOffset ( "foo" , 6 , 1234L , SeekPosition . TIMESTAMP ),
2777
+ new TopicPartitionOffset ( "foo" , 7 , 1234L , SeekPosition . TIMESTAMP ) );
2770
2778
containerProps .setGroupId ("grp" );
2771
2779
containerProps .setAckMode (AckMode .RECORD );
2772
2780
containerProps .setClientId ("clientId" );
@@ -2782,9 +2790,11 @@ public void testInitialSeek() throws Exception {
2782
2790
.isEqualTo (new HashSet <>(Arrays .asList (new TopicPartition ("foo" , 0 ), new TopicPartition ("foo" , 4 ))));
2783
2791
verify (consumer ).seekToEnd (captor .capture ());
2784
2792
assertThat (captor .getValue ())
2785
- .isEqualTo (new HashSet <>(Arrays .asList (new TopicPartition ("foo" , 1 ), new TopicPartition ("foo" , 5 ))));
2793
+ .isEqualTo (new HashSet <>(Arrays .asList (new TopicPartition ("foo" , 1 ), new TopicPartition ("foo" , 5 ),
2794
+ new TopicPartition ("foo" , 7 ))));
2786
2795
verify (consumer ).seek (new TopicPartition ("foo" , 2 ), 0L );
2787
2796
verify (consumer ).seek (new TopicPartition ("foo" , 3 ), Long .MAX_VALUE );
2797
+ verify (consumer ).seek (new TopicPartition ("foo" , 6 ), 42L );
2788
2798
container .stop ();
2789
2799
}
2790
2800
0 commit comments