@@ -19,7 +19,6 @@ import java.time.Duration
1919import java .util
2020import java .util .UUID .randomUUID
2121import java .util .{Collections , Properties }
22-
2322import org .apache .kafka .clients .admin .{AdminClient , AdminClientConfig , NewTopic }
2423import org .apache .kafka .clients .consumer .{ConsumerRecord , KafkaConsumer }
2524import org .apache .kafka .clients .producer .{KafkaProducer , ProducerConfig , ProducerRecord }
@@ -28,6 +27,7 @@ import org.apache.kafka.common.serialization.{StringDeserializer, StringSerializ
2827import org .scalatest .{AppendedClues , BeforeAndAfter , FlatSpec , Matchers }
2928import org .testcontainers .containers .KafkaContainer
3029import org .testcontainers .utility .DockerImageName
30+ import za .co .absa .hyperdrive .ingestor .implementation .transformer .deduplicate .kafka .PrunedConsumerRecord
3131
3232import scala .collection .JavaConverters ._
3333import scala .collection .mutable
@@ -39,6 +39,12 @@ class TestKafkaUtilDockerTest extends FlatSpec with Matchers with BeforeAndAfter
3939 private val kafkaInsufficientTimeout = Duration .ofMillis(1L )
4040 private val topic = " test-topic"
4141 private val maxPollRecords = 10
42+ private val pruningFn = (r : ConsumerRecord [String , String ]) => PrunedConsumerRecord (
43+ r.topic(),
44+ r.partition(),
45+ r.offset(),
46+ Seq (r.value())
47+ )
4248
4349 before{
4450 kafka.start()
@@ -62,10 +68,10 @@ class TestKafkaUtilDockerTest extends FlatSpec with Matchers with BeforeAndAfter
6268
6369 // when
6470 implicit val kafkaConsumerTimeout : Duration = kafkaSufficientTimeout
65- val records = KafkaUtil .getMessagesAtLeastToOffset(consumer, offsets)
71+ val records = KafkaUtil .getMessagesAtLeastToOffset(consumer, offsets, pruningFn )
6672
6773 // then
68- val actualMessages = records.map(_.value() ).toList.sorted
74+ val actualMessages = records.map(_.data.head. asInstanceOf [ String ] ).toList.sorted
6975 actualMessages should contain theSameElementsAs messages
7076 }
7177
@@ -99,10 +105,10 @@ class TestKafkaUtilDockerTest extends FlatSpec with Matchers with BeforeAndAfter
99105
100106 // when
101107 implicit val kafkaConsumerTimeout : Duration = kafkaSufficientTimeout
102- val records = KafkaUtil .getMessagesAtLeastToOffset(consumer, offsets)
108+ val records = KafkaUtil .getMessagesAtLeastToOffset(consumer, offsets, pruningFn )
103109
104110 // then
105- val actualMessages = records.map(_.value() ).toList.sorted
111+ val actualMessages = records.map(_.data.head. asInstanceOf [ String ] ).toList.sorted
106112 actualMessages should contain allElementsOf messages
107113
108114 // cleanup
@@ -118,7 +124,7 @@ class TestKafkaUtilDockerTest extends FlatSpec with Matchers with BeforeAndAfter
118124
119125 // when
120126 implicit val kafkaConsumerTimeout : Duration = kafkaInsufficientTimeout
121- val exception = the[Exception ] thrownBy KafkaUtil .getMessagesAtLeastToOffset(consumer, Map (new TopicPartition (topic, 0 ) -> 0 ))
127+ val exception = the[Exception ] thrownBy KafkaUtil .getMessagesAtLeastToOffset(consumer, Map (new TopicPartition (topic, 0 ) -> 0 ), pruningFn )
122128
123129 // then
124130 exception.getMessage should include (" Subscription to topics, partitions and pattern are mutually exclusive" )
@@ -140,7 +146,7 @@ class TestKafkaUtilDockerTest extends FlatSpec with Matchers with BeforeAndAfter
140146
141147 // when
142148 implicit val kafkaConsumerTimeout : Duration = kafkaInsufficientTimeout
143- val exception = the[Exception ] thrownBy KafkaUtil .getMessagesAtLeastToOffset(consumer, offsets)
149+ val exception = the[Exception ] thrownBy KafkaUtil .getMessagesAtLeastToOffset(consumer, offsets, pruningFn )
144150
145151 // then
146152 exception.getMessage should include (" Not all expected messages were consumed" )
@@ -160,7 +166,7 @@ class TestKafkaUtilDockerTest extends FlatSpec with Matchers with BeforeAndAfter
160166
161167 // when
162168 implicit val kafkaConsumerTimeout : Duration = kafkaInsufficientTimeout
163- val exception = the[Exception ] thrownBy KafkaUtil .getMessagesAtLeastToOffset(consumer, offsets)
169+ val exception = the[Exception ] thrownBy KafkaUtil .getMessagesAtLeastToOffset(consumer, offsets, pruningFn )
164170
165171 // then
166172 exception.getMessage should include (" Requested consumption" )
@@ -209,8 +215,8 @@ class TestKafkaUtilDockerTest extends FlatSpec with Matchers with BeforeAndAfter
209215 implicit val kafkaConsumerTimeout : Duration = kafkaSufficientTimeout
210216 val topicPartitions = KafkaUtil .getTopicPartitions(consumer, topic)
211217 val recordsPerPartition = topicPartitions.map(p => p -> 4L ).toMap
212- val actualRecords = KafkaUtil .getAtLeastNLatestRecordsFromPartition(consumer, recordsPerPartition)
213- val values = actualRecords.map(_.value() )
218+ val actualRecords = KafkaUtil .getAtLeastNLatestRecordsFromPartition(consumer, recordsPerPartition, pruningFn )
219+ val values = actualRecords.map(_.data.head. asInstanceOf [ String ] )
214220
215221 values.size should be >= 12
216222 values should contain allElementsOf Seq (" msg_103" , " msg_102" , " msg_101" , " msg_100" , " msg_99" , " msg_97" , " msg_95" ,
@@ -231,10 +237,10 @@ class TestKafkaUtilDockerTest extends FlatSpec with Matchers with BeforeAndAfter
231237 // when
232238 implicit val kafkaConsumerTimeout : Duration = kafkaSufficientTimeout
233239 val recordsPerPartition = topicPartitions.map(t => t -> 1000L ).toMap
234- val records = KafkaUtil .getAtLeastNLatestRecordsFromPartition(consumer, recordsPerPartition)
240+ val records = KafkaUtil .getAtLeastNLatestRecordsFromPartition(consumer, recordsPerPartition, pruningFn )
235241
236242 // then
237- val actualMessages = records.map(_.value() ).toList.sorted
243+ val actualMessages = records.map(_.data.head. asInstanceOf [ String ] ).toList.sorted
238244 actualMessages should contain theSameElementsAs messages
239245 }
240246
@@ -248,7 +254,8 @@ class TestKafkaUtilDockerTest extends FlatSpec with Matchers with BeforeAndAfter
248254
249255 val consumer = createConsumer(kafka)
250256 implicit val kafkaConsumerTimeout : Duration = kafkaInsufficientTimeout
251- val result = the[Exception ] thrownBy KafkaUtil .getAtLeastNLatestRecordsFromPartition(consumer, Map (new TopicPartition (topic, 0 ) -> 10 ))
257+ val result = the[Exception ] thrownBy KafkaUtil .getAtLeastNLatestRecordsFromPartition(consumer,
258+ Map (new TopicPartition (topic, 0 ) -> 10 ), pruningFn)
252259 result.getMessage should include(" increasing the consumer timeout" )
253260 }
254261
0 commit comments