|
1 | 1 | /*
|
| 2 | + * Copyright 2017-2018 the original author or authors. |
2 | 3 | * Copyright 2017 the original author or authors.
|
3 | 4 | *
|
4 | 5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
|
17 | 18 | package org.springframework.kafka.core;
|
18 | 19 |
|
19 | 20 | import static org.assertj.core.api.Assertions.assertThat;
|
| 21 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
20 | 22 | import static org.mockito.ArgumentMatchers.any;
|
21 | 23 | import static org.mockito.ArgumentMatchers.eq;
|
22 | 24 | import static org.mockito.BDDMockito.given;
|
@@ -77,7 +79,7 @@ public void testLocalTransaction() throws Exception {
|
77 | 79 | DefaultKafkaProducerFactory<String, String> pf = new DefaultKafkaProducerFactory<>(senderProps);
|
78 | 80 | pf.setKeySerializer(new StringSerializer());
|
79 | 81 | pf.setTransactionIdPrefix("my.transaction.");
|
80 |
| - KafkaTemplate<String, String> template = new KafkaTemplate<>(pf, true); |
| 82 | + KafkaTemplate<String, String> template = new KafkaTemplate<>(pf); |
81 | 83 | template.setDefaultTopic(STRING_KEY_TOPIC);
|
82 | 84 | Map<String, Object> consumerProps = KafkaTestUtils.consumerProps("testTxString", "false", embeddedKafka);
|
83 | 85 | consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
|
@@ -113,7 +115,7 @@ public void testGlobalTransaction() throws Exception {
|
113 | 115 | DefaultKafkaProducerFactory<String, String> pf = new DefaultKafkaProducerFactory<>(senderProps);
|
114 | 116 | pf.setKeySerializer(new StringSerializer());
|
115 | 117 | pf.setTransactionIdPrefix("my.transaction.");
|
116 |
| - KafkaTemplate<String, String> template = new KafkaTemplate<>(pf, true); |
| 118 | + KafkaTemplate<String, String> template = new KafkaTemplate<>(pf); |
117 | 119 | template.setDefaultTopic(STRING_KEY_TOPIC);
|
118 | 120 | Map<String, Object> consumerProps = KafkaTestUtils.consumerProps("testTxString", "false", embeddedKafka);
|
119 | 121 | consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
|
@@ -165,6 +167,20 @@ public void testDeclarative() {
|
165 | 167 | ctx.close();
|
166 | 168 | }
|
167 | 169 |
|
| 170 | + @Test |
| 171 | + public void testNoTx() { |
| 172 | + Map<String, Object> senderProps = KafkaTestUtils.producerProps(embeddedKafka); |
| 173 | + senderProps.put(ProducerConfig.RETRIES_CONFIG, 1); |
| 174 | + DefaultKafkaProducerFactory<String, String> pf = new DefaultKafkaProducerFactory<>(senderProps); |
| 175 | + pf.setKeySerializer(new StringSerializer()); |
| 176 | + pf.setTransactionIdPrefix("my.transaction."); |
| 177 | + KafkaTemplate<String, String> template = new KafkaTemplate<>(pf); |
| 178 | + template.setDefaultTopic(STRING_KEY_TOPIC); |
| 179 | + assertThatThrownBy(() -> template.send("foo", "bar")) |
| 180 | + .isInstanceOf(IllegalStateException.class) |
| 181 | + .hasMessageContaining("No transaction is in process;"); |
| 182 | + } |
| 183 | + |
168 | 184 | @Configuration
|
169 | 185 | @EnableTransactionManagement
|
170 | 186 | public static class DeclarativeConfig {
|
|
0 commit comments