|
1 | 1 | /* |
2 | | - * Copyright 2017 the original author or authors. |
| 2 | + * Copyright 2017-2018 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
63 | 63 | import org.springframework.kafka.core.DefaultKafkaProducerFactory; |
64 | 64 | import org.springframework.kafka.core.KafkaTemplate; |
65 | 65 | import org.springframework.kafka.core.ProducerFactory; |
66 | | -import org.springframework.kafka.listener.AbstractMessageListenerContainer.AckMode; |
67 | 66 | import org.springframework.kafka.listener.config.ContainerProperties; |
68 | 67 | import org.springframework.kafka.support.TopicPartitionInitialOffset; |
69 | 68 | import org.springframework.kafka.test.rule.KafkaEmbedded; |
@@ -93,17 +92,22 @@ public class TransactionalContainerTests { |
93 | 92 | public static KafkaEmbedded embeddedKafka = new KafkaEmbedded(3, true, topic1, topic2); |
94 | 93 |
|
95 | 94 | @Test |
96 | | - public void testConsumeAndProduceTransactionBatch() throws Exception { |
97 | | - testConsumeAndProduceTransactionGuts(AckMode.BATCH); |
| 95 | + public void testConsumeAndProduceTransactionKTM() throws Exception { |
| 96 | + testConsumeAndProduceTransactionGuts(false, false); |
98 | 97 | } |
99 | 98 |
|
100 | 99 | @Test |
101 | | - public void testConsumeAndProduceTransactionRecord() throws Exception { |
102 | | - testConsumeAndProduceTransactionGuts(AckMode.RECORD); |
| 100 | + public void testConsumeAndProduceTransactionKCTM() throws Exception { |
| 101 | + testConsumeAndProduceTransactionGuts(true, false); |
| 102 | + } |
| 103 | + |
| 104 | + @Test |
| 105 | + public void testConsumeAndProduceTransactionHandleError() throws Exception { |
| 106 | + testConsumeAndProduceTransactionGuts(false, true); |
103 | 107 | } |
104 | 108 |
|
105 | 109 | @SuppressWarnings({ "rawtypes", "unchecked" }) |
106 | | - private void testConsumeAndProduceTransactionGuts(AckMode ackMode) throws Exception { |
| 110 | + private void testConsumeAndProduceTransactionGuts(boolean chained, boolean handleError) throws Exception { |
107 | 111 | Consumer consumer = mock(Consumer.class); |
108 | 112 | final TopicPartition topicPartition = new TopicPartition("foo", 0); |
109 | 113 | willAnswer(i -> { |
@@ -141,8 +145,13 @@ private void testConsumeAndProduceTransactionGuts(AckMode ackMode) throws Except |
141 | 145 | final KafkaTemplate template = new KafkaTemplate(pf); |
142 | 146 | props.setMessageListener((MessageListener) m -> { |
143 | 147 | template.send("bar", "baz"); |
| 148 | + if (handleError) { |
| 149 | + throw new RuntimeException("fail"); |
| 150 | + } |
144 | 151 | }); |
145 | | - props.setAckMode(ackMode); |
| 152 | + if (handleError) { |
| 153 | + props.setErrorHandler((e, data) -> { }); |
| 154 | + } |
146 | 155 | KafkaMessageListenerContainer container = new KafkaMessageListenerContainer<>(cf, props); |
147 | 156 | container.setBeanName("commit"); |
148 | 157 | container.start(); |
|
0 commit comments