Tuesday, 20 August 2019

kafka test


the second one is the best one ,

but you may found that your normal springboot test will stop running and with error looking for ${spring.embedded.kafka.brokers}

the reason is that you added this in your test application.properteis file to make the build-in kafka running ok which uses autowire. (and the build-in kafka will setup "spring.embedded.kafka.brokers" into your env.)

then your normal springboot test will also use this properties file,  and you didn't set the build-in kafka autowire in your test, then there is no "spring.embedded.kafka.brokers"  in your env. then you test will crash.

you can setup an env all add the build-in kafka in you this test. but not good.

so the best way is to change your kafka test. and remove the properties file from your test resource.

make your test use the default properties file from main/resources. and override things in your test by:

@SpringBootTest(properties = { "kafka.site.topic=test_json_1", "event-hub=false",
"kafka.bootstrap-server=${spring.embedded.kafka.brokers}" })

public class KafkaConsumerTest {

No comments:

Post a comment