import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration;
import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.context.annotation.Import;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.test.context.EmbeddedKafka;
@SpringBootTest(
classes = {
+ KafkaTestUtils.KafkaTestConfiguration.class,
KafkaAutoConfiguration.class,
TaskExecutionAutoConfiguration.class,
},
"chat.backend.kafka.data-channel-topic=" + DATA_TOPIC,
"chat.backend.kafka.num-partitions=" + NUM_SHARDS,
})
-@Import(KafkaTestUtils.class)
@EmbeddedKafka(
topics = { INFO_TOPIC, DATA_TOPIC },
partitions = 10)
import static de.juplo.kafka.chat.backend.implementation.kafka.KafkaChatHomeServiceTest.INFO_TOPIC;
-@TestConfiguration
-@Import(KafkaServicesConfiguration.class)
-@EnableConfigurationProperties(ChatBackendProperties.class)
-@TestPropertySource(properties = {
- "spring.main.allow-bean-definition-overriding=true",
- "chat.backend.services=kafka",
- "chat.backend.kafka.client-id-PREFIX=TEST",
- "chat.backend.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}",
- "spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}",
-})
@Slf4j
public abstract class KafkaTestUtils
{
- @Bean
- WorkAssignor dataChannelWorkAssignor(DataChannel dataChannel)
+ @TestConfiguration
+ @Import(KafkaServicesConfiguration.class)
+ @EnableConfigurationProperties(ChatBackendProperties.class)
+ @TestPropertySource(properties = {
+ "spring.main.allow-bean-definition-overriding=true",
+ "chat.backend.services=kafka",
+ "chat.backend.kafka.client-id-PREFIX=TEST",
+ "chat.backend.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}",
+ "spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}",
+ })
+ public static class KafkaTestConfiguration
{
- return consumer ->
+ @Bean
+ WorkAssignor dataChannelWorkAssignor(DataChannel dataChannel)
{
- List<TopicPartition> assignedPartitions =
- List.of(new TopicPartition(DATA_TOPIC, 2));
- consumer.assign(assignedPartitions);
- dataChannel.onPartitionsAssigned(assignedPartitions);
- };
- }
+ return consumer ->
+ {
+ List<TopicPartition> assignedPartitions =
+ List.of(new TopicPartition(DATA_TOPIC, 2));
+ consumer.assign(assignedPartitions);
+ dataChannel.onPartitionsAssigned(assignedPartitions);
+ };
+ }
- @Bean
- Clock clock()
- {
- return Clock.systemDefaultZone();
+ @Bean
+ Clock clock()
+ {
+ return Clock.systemDefaultZone();
+ }
}