|
82 | 82 | * @author Martin Dam |
83 | 83 | * @author Artem Bilan |
84 | 84 | * @author Loic Talhouarne |
| 85 | + * @author Thorsten Binias |
85 | 86 | */ |
86 | 87 | public class KafkaMessageListenerContainerTests { |
87 | 88 |
|
@@ -119,9 +120,11 @@ public class KafkaMessageListenerContainerTests { |
119 | 120 |
|
120 | 121 | private static String topic16 = "testTopic16"; |
121 | 122 |
|
| 123 | + private static String topic17 = "testTopic17"; |
| 124 | + |
122 | 125 | @ClassRule |
123 | 126 | public static KafkaEmbedded embeddedKafka = new KafkaEmbedded(1, true, topic1, topic2, topic3, topic4, topic5, |
124 | | - topic6, topic7, topic8, topic9, topic10, topic11, topic12, topic13, topic14, topic15, topic16); |
| 127 | + topic6, topic7, topic8, topic9, topic10, topic11, topic12, topic13, topic14, topic15, topic16, topic17); |
125 | 128 |
|
126 | 129 | @Rule |
127 | 130 | public TestName testName = new TestName(); |
@@ -849,20 +852,20 @@ public void testBatchListenerErrors() throws Exception { |
849 | 852 | @Test |
850 | 853 | public void testSeek() throws Exception { |
851 | 854 | Map<String, Object> props = KafkaTestUtils.consumerProps("test11", "false", embeddedKafka); |
852 | | - testSeekGuts(props, topic11, false); |
| 855 | + testSeekGuts(props, topic11, false, false); |
853 | 856 | } |
854 | 857 |
|
855 | 858 | @Test |
856 | 859 | public void testSeekAutoCommit() throws Exception { |
857 | 860 | Map<String, Object> props = KafkaTestUtils.consumerProps("test12", "true", embeddedKafka); |
858 | | - testSeekGuts(props, topic12, true); |
| 861 | + testSeekGuts(props, topic12, true, false); |
859 | 862 | } |
860 | 863 |
|
861 | 864 | @Test |
862 | 865 | public void testSeekAutoCommitDefault() throws Exception { |
863 | 866 | Map<String, Object> props = KafkaTestUtils.consumerProps("test15", "true", embeddedKafka); |
864 | 867 | props.remove(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG); // test true by default |
865 | | - testSeekGuts(props, topic15, true); |
| 868 | + testSeekGuts(props, topic15, true, false); |
866 | 869 | } |
867 | 870 |
|
868 | 871 | @Test |
@@ -912,7 +915,13 @@ public void onIdleContainer(Map<TopicPartition, Long> assignments, ConsumerSeekC |
912 | 915 | container.stop(); |
913 | 916 | } |
914 | 917 |
|
915 | | - private void testSeekGuts(Map<String, Object> props, String topic, boolean autoCommit) throws Exception { |
| 918 | + @Test |
| 919 | + public void testSeekAck() throws Exception { |
| 920 | + Map<String, Object> props = KafkaTestUtils.consumerProps("test17", "false", embeddedKafka); |
| 921 | + testSeekGuts(props, topic17, false, true); |
| 922 | + } |
| 923 | + |
| 924 | + private void testSeekGuts(Map<String, Object> props, String topic, boolean autoCommit, boolean acknowledging) throws Exception { |
916 | 925 | logger.info("Start seek " + topic); |
917 | 926 | DefaultKafkaConsumerFactory<Integer, String> cf = new DefaultKafkaConsumerFactory<>(props); |
918 | 927 | ContainerProperties containerProps = new ContainerProperties(topic); |
@@ -964,7 +973,17 @@ public void onIdleContainer(Map<TopicPartition, Long> assignments, ConsumerSeekC |
964 | 973 | } |
965 | 974 |
|
966 | 975 | } |
967 | | - Listener messageListener = new Listener(); |
| 976 | + |
| 977 | + class AcknowledgingListener extends Listener implements AcknowledgingMessageListener<Integer, String> { |
| 978 | + |
| 979 | + @Override |
| 980 | + public void onMessage(ConsumerRecord<Integer, String> data, Acknowledgment acknowledgment) { |
| 981 | + super.onMessage(data); |
| 982 | + } |
| 983 | + |
| 984 | + } |
| 985 | + |
| 986 | + Listener messageListener = acknowledging ? new AcknowledgingListener() : new Listener(); |
968 | 987 | containerProps.setMessageListener(messageListener); |
969 | 988 | containerProps.setSyncCommits(true); |
970 | 989 | containerProps.setAckMode(AckMode.RECORD); |
|
0 commit comments