小编flo*_*ong的帖子

DirtiesContext不关闭Kafka消费者和生产者

我正在尝试使用 JUnit5 和 EmbededKafka 测试 KafkaStreams 应用程序。执行任何测试用例时,我看到日志被以下消息轰炸

[Producer clientId=myTask-227e2e90-212b-4663-bd17-2d307018c81a-StreamThread-1-producer] Connection to node 0 (localhost/127.0.0.1:61269) could not be established. Broker may not be available.
[Consumer clientId=myTask-227e2e90-212b-4663-bd17-2d307018c81a-StreamThread-3-consumer, groupId=my-task] Connection to node 0 (localhost/127.0.0.1:61269) could not be established. Broker may not be available.
Run Code Online (Sandbox Code Playgroud)

我还添加了

@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
Run Code Online (Sandbox Code Playgroud)

类级别配置

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@TestPropertySource("/application-test.properties")
@EmbeddedKafka(topics = { "${kafka.topic.}"
    },
    partitions = 1, controlledShutdown = true
)
@ExtendWith(MockitoExtension.class)
public class KStreamTest{

    @Autowired
 protected EmbeddedKafkaBroker embeddedKafka;
  
  //TestMethod

 }
Run Code Online (Sandbox Code Playgroud)

你能建议我尝试什么或者如果我错过了什么吗?

java unit-testing junit5 apache-kafka-streams

6
推荐指数
1
解决办法
702
查看次数

标签 统计

apache-kafka-streams ×1

java ×1

junit5 ×1

unit-testing ×1