|
61 | 61 | import org.springframework.kafka.core.DefaultKafkaProducerFactory; |
62 | 62 | import org.springframework.kafka.core.KafkaTemplate; |
63 | 63 | import org.springframework.kafka.core.ProducerFactory; |
| 64 | +import org.springframework.kafka.listener.AbstractMessageListenerContainer.AckMode; |
64 | 65 | import org.springframework.kafka.listener.config.ContainerProperties; |
65 | 66 | import org.springframework.kafka.test.rule.KafkaEmbedded; |
66 | 67 | import org.springframework.kafka.test.utils.KafkaTestUtils; |
@@ -88,9 +89,18 @@ public class TransactionalContainerTests { |
88 | 89 | @ClassRule |
89 | 90 | public static KafkaEmbedded embeddedKafka = new KafkaEmbedded(3, true, topic1, topic2); |
90 | 91 |
|
91 | | - @SuppressWarnings({ "rawtypes", "unchecked" }) |
92 | 92 | @Test |
93 | | - public void testConsumeAndProduceTransaction() throws Exception { |
| 93 | + public void testConsumeAndProduceTransactionBatch() throws Exception { |
| 94 | + testConsumeAndProduceTransactionGuts(AckMode.BATCH); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + public void testConsumeAndProduceTransactionRecord() throws Exception { |
| 99 | + testConsumeAndProduceTransactionGuts(AckMode.RECORD); |
| 100 | + } |
| 101 | + |
| 102 | + @SuppressWarnings({ "rawtypes", "unchecked" }) |
| 103 | + private void testConsumeAndProduceTransactionGuts(AckMode ackMode) throws Exception { |
94 | 104 | Consumer consumer = mock(Consumer.class); |
95 | 105 | final TopicPartition topicPartition = new TopicPartition("foo", 0); |
96 | 106 | willAnswer(i -> { |
@@ -129,6 +139,7 @@ public void testConsumeAndProduceTransaction() throws Exception { |
129 | 139 | props.setMessageListener((MessageListener) m -> { |
130 | 140 | template.send("bar", "baz"); |
131 | 141 | }); |
| 142 | + props.setAckMode(ackMode); |
132 | 143 | KafkaMessageListenerContainer container = new KafkaMessageListenerContainer<>(cf, props); |
133 | 144 | container.setBeanName("commit"); |
134 | 145 | container.start(); |
|
0 commit comments