Skip to content

Commit

Permalink
Fix KafkaOutAdapterParserTests race condition
Browse files Browse the repository at this point in the history
The `Future` for `Producer.send()` can be fulfilled before
we return it (`isDone()`), so `KafkaTemplate` short-circuits
with a `KafkaException`.

* Modify `KafkaOutboundAdapterParserTests.testSyncMode()`
to assert against `KafkaException` which may be thrown earlier
then previously expected `KafkaProducerException`

**Cherry-pick to `5.5.x`**
  • Loading branch information
artembilan committed Jul 18, 2022
1 parent 1c461a3 commit d9a42c9
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.springframework.integration.MessageTimeoutException;
import org.springframework.integration.kafka.outbound.KafkaProducerMessageHandler;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.kafka.core.KafkaProducerException;
import org.springframework.kafka.KafkaException;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.core.ProducerFactory;
import org.springframework.messaging.MessageHandlingException;
Expand Down Expand Up @@ -136,7 +136,7 @@ public void close(Duration timeout) {

assertThatExceptionOfType(MessageHandlingException.class)
.isThrownBy(() -> handler.handleMessage(new GenericMessage<>("foo")))
.withCauseInstanceOf(KafkaProducerException.class)
.withCauseInstanceOf(KafkaException.class)
.withRootCauseInstanceOf(RuntimeException.class)
.withStackTraceContaining("Async Producer Mock exception");

Expand Down

0 comments on commit d9a42c9

Please sign in to comment.