-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from data-integrations/bugfix/CDAP-19731-vali…
…date-offsets CDAP-19731 - Validate offsets and give informative error message.
- Loading branch information
Showing
3 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...lugins-client/src/test/java/io/cdap/plugin/kafka/source/KafkaStreamingSourceUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.cdap.plugin.kafka.source; | ||
|
||
import org.apache.kafka.common.TopicPartition; | ||
import org.junit.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Tests for KafkaStreamingSourceUtil | ||
*/ | ||
public class KafkaStreamingSourceUtilTest { | ||
|
||
@Test | ||
public void testValidateSavedPartitionsValid() { | ||
Map<TopicPartition, Long> savedPartitions = new HashMap<>(); | ||
TopicPartition partition1 = new TopicPartition("test-topic", 0); | ||
TopicPartition partition2 = new TopicPartition("test-topic", 1); | ||
savedPartitions.put(partition1, 100L); | ||
savedPartitions.put(partition2, 102L); | ||
Map<TopicPartition, Long> earliestOffsets = new HashMap<>(); | ||
earliestOffsets.put(partition1, 0L); | ||
earliestOffsets.put(partition2, 0L); | ||
Map<TopicPartition, Long> latestOffsets = new HashMap<>(); | ||
latestOffsets.put(partition1, 202L); | ||
latestOffsets.put(partition2, 200L); | ||
KafkaStreamingSourceUtil.validateSavedPartitions(savedPartitions, earliestOffsets, latestOffsets); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testValidateSavedPartitionsInvalid() { | ||
Map<TopicPartition, Long> savedPartitions = new HashMap<>(); | ||
TopicPartition partition1 = new TopicPartition("test-topic", 0); | ||
TopicPartition partition2 = new TopicPartition("test-topic", 1); | ||
savedPartitions.put(partition1, 100L); | ||
savedPartitions.put(partition2, 102L); | ||
Map<TopicPartition, Long> earliestOffsets = new HashMap<>(); | ||
earliestOffsets.put(partition1, 0L); | ||
earliestOffsets.put(partition2, 0L); | ||
Map<TopicPartition, Long> latestOffsets = new HashMap<>(); | ||
latestOffsets.put(partition1, 10L); | ||
latestOffsets.put(partition2, 0L); | ||
KafkaStreamingSourceUtil.validateSavedPartitions(savedPartitions, earliestOffsets, latestOffsets); | ||
} | ||
} |