diff --git a/spring-integration-kafka/src/test/java/org/springframework/integration/kafka/inbound/InboundGatewayTests.java b/spring-integration-kafka/src/test/java/org/springframework/integration/kafka/inbound/InboundGatewayTests.java index 71fd21bac4..7b5bb6bba2 100644 --- a/spring-integration-kafka/src/test/java/org/springframework/integration/kafka/inbound/InboundGatewayTests.java +++ b/spring-integration-kafka/src/test/java/org/springframework/integration/kafka/inbound/InboundGatewayTests.java @@ -91,6 +91,12 @@ public class InboundGatewayTests { @Test public void testInbound() throws Exception { + Map consumerProps = KafkaTestUtils.consumerProps("replyHandler1", "false", embeddedKafka); + consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); + ConsumerFactory cf2 = new DefaultKafkaConsumerFactory<>(consumerProps); + Consumer consumer = cf2.createConsumer(); + embeddedKafka.consumeFromAnEmbeddedTopic(consumer, topic2); + Map props = KafkaTestUtils.consumerProps("test1", "false", embeddedKafka); props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); DefaultKafkaConsumerFactory cf = new DefaultKafkaConsumerFactory(props); @@ -141,11 +147,6 @@ public class InboundGatewayTests { assertThat(headers.get("testHeader")).isEqualTo("testValue"); reply.send(MessageBuilder.withPayload("FOO").copyHeaders(headers).build()); - Map consumerProps = KafkaTestUtils.consumerProps("replyHandler1", "false", embeddedKafka); - consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); - ConsumerFactory cf2 = new DefaultKafkaConsumerFactory<>(consumerProps); - Consumer consumer = cf2.createConsumer(); - embeddedKafka.consumeFromAnEmbeddedTopic(consumer, topic2); ConsumerRecord record = KafkaTestUtils.getSingleRecord(consumer, topic2); assertThat(record).has(partition(1)); assertThat(record).has(value("FOO")); @@ -155,6 +156,12 @@ public class InboundGatewayTests { @Test public void testInboundErrorRecover() throws Exception { + Map consumerProps = KafkaTestUtils.consumerProps("replyHandler2", "false", embeddedKafka); + consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); + ConsumerFactory cf2 = new DefaultKafkaConsumerFactory<>(consumerProps); + Consumer consumer = cf2.createConsumer(); + embeddedKafka.consumeFromAnEmbeddedTopic(consumer, topic4); + Map props = KafkaTestUtils.consumerProps("test2", "false", embeddedKafka); props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); DefaultKafkaConsumerFactory cf = new DefaultKafkaConsumerFactory(props); @@ -215,11 +222,6 @@ public class InboundGatewayTests { assertThat(headers.get(KafkaHeaders.REPLY_TOPIC)).isEqualTo(topic4); assertThat(headers.get("testHeader")).isEqualTo("testValue"); - Map consumerProps = KafkaTestUtils.consumerProps("replyHandler2", "false", embeddedKafka); - consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); - ConsumerFactory cf2 = new DefaultKafkaConsumerFactory<>(consumerProps); - Consumer consumer = cf2.createConsumer(); - embeddedKafka.consumeFromAnEmbeddedTopic(consumer, topic4); ConsumerRecord record = KafkaTestUtils.getSingleRecord(consumer, topic4); assertThat(record).has(partition(1)); assertThat(record).has(value("ERROR")); @@ -229,6 +231,12 @@ public class InboundGatewayTests { @Test public void testInboundRetryErrorRecover() throws Exception { + Map consumerProps = KafkaTestUtils.consumerProps("replyHandler3", "false", embeddedKafka); + consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); + ConsumerFactory cf2 = new DefaultKafkaConsumerFactory<>(consumerProps); + Consumer consumer = cf2.createConsumer(); + embeddedKafka.consumeFromAnEmbeddedTopic(consumer, topic6); + Map props = KafkaTestUtils.consumerProps("test3", "false", embeddedKafka); props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); DefaultKafkaConsumerFactory cf = new DefaultKafkaConsumerFactory(props); @@ -297,11 +305,6 @@ public class InboundGatewayTests { assertThat(headers.get(KafkaHeaders.REPLY_TOPIC)).isEqualTo(topic6); assertThat(headers.get("testHeader")).isEqualTo("testValue"); - Map consumerProps = KafkaTestUtils.consumerProps("replyHandler3", "false", embeddedKafka); - consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); - ConsumerFactory cf2 = new DefaultKafkaConsumerFactory<>(consumerProps); - Consumer consumer = cf2.createConsumer(); - embeddedKafka.consumeFromAnEmbeddedTopic(consumer, topic6); ConsumerRecord record = KafkaTestUtils.getSingleRecord(consumer, topic6); assertThat(record).has(partition(1)); assertThat(record).has(value("ERROR"));