|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.boot.actuate.autoconfigure.metrics;
|
18 | 18 |
|
19 |
| -import io.micrometer.core.instrument.binder.kafka.KafkaConsumerMetrics; |
| 19 | +import io.micrometer.core.instrument.binder.kafka.KafkaClientMetrics; |
20 | 20 | import org.junit.jupiter.api.Test;
|
21 | 21 |
|
22 | 22 | import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
|
23 | 23 | import org.springframework.boot.autoconfigure.AutoConfigurations;
|
24 |
| -import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; |
| 24 | +import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration; |
25 | 25 | import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
26 | 26 | import org.springframework.context.annotation.Bean;
|
27 | 27 | import org.springframework.context.annotation.Configuration;
|
28 | 28 |
|
29 | 29 | import static org.assertj.core.api.Assertions.assertThat;
|
| 30 | +import static org.mockito.Mockito.mock; |
30 | 31 |
|
31 | 32 | /**
|
32 | 33 | * Tests for {@link KafkaMetricsAutoConfiguration}.
|
33 | 34 | *
|
34 | 35 | * @author Andy Wilkinson
|
| 36 | + * @author Stephane Nicoll |
35 | 37 | */
|
36 | 38 | class KafkaMetricsAutoConfigurationTests {
|
37 | 39 |
|
38 | 40 | private final ApplicationContextRunner contextRunner = new ApplicationContextRunner().with(MetricsRun.simple())
|
39 |
| - .withPropertyValues("spring.jmx.enabled=true") |
40 | 41 | .withConfiguration(AutoConfigurations.of(KafkaMetricsAutoConfiguration.class));
|
41 | 42 |
|
42 | 43 | @Test
|
43 |
| - void whenThereIsNoMBeanServerAutoConfigurationBacksOff() { |
44 |
| - this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(KafkaConsumerMetrics.class)); |
| 44 | + void whenThereIsNoProducerFactoryAutoConfigurationBacksOff() { |
| 45 | + this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(KafkaClientMetrics.class)); |
45 | 46 | }
|
46 | 47 |
|
47 | 48 | @Test
|
48 |
| - void whenThereIsAnMBeanServerKafkaConsumerMetricsIsConfigured() { |
49 |
| - this.contextRunner.withConfiguration(AutoConfigurations.of(JmxAutoConfiguration.class)) |
50 |
| - .run((context) -> assertThat(context).hasSingleBean(KafkaConsumerMetrics.class)); |
| 49 | + void whenThereIsAnAProducerFactoryKafkaClientMetricsIsConfigured() { |
| 50 | + this.contextRunner.withConfiguration(AutoConfigurations.of(KafkaAutoConfiguration.class)) |
| 51 | + .run((context) -> assertThat(context).hasSingleBean(KafkaClientMetrics.class)); |
51 | 52 | }
|
52 | 53 |
|
53 | 54 | @Test
|
54 |
| - void allowsCustomKafkaConsumerMetricsToBeUsed() { |
55 |
| - this.contextRunner.withConfiguration(AutoConfigurations.of(JmxAutoConfiguration.class)) |
56 |
| - .withUserConfiguration(CustomKafkaConsumerMetricsConfiguration.class) |
57 |
| - .run((context) -> assertThat(context).hasSingleBean(KafkaConsumerMetrics.class) |
58 |
| - .hasBean("customKafkaConsumerMetrics")); |
| 55 | + void allowsCustomKafkaClientMetricsToBeUsed() { |
| 56 | + this.contextRunner.withConfiguration(AutoConfigurations.of(KafkaAutoConfiguration.class)) |
| 57 | + .withUserConfiguration(CustomKafkaClientMetricsConfiguration.class).run((context) -> assertThat(context) |
| 58 | + .hasSingleBean(KafkaClientMetrics.class).hasBean("customKafkaClientMetrics")); |
59 | 59 | }
|
60 | 60 |
|
61 | 61 | @Configuration(proxyBeanMethods = false)
|
62 |
| - static class CustomKafkaConsumerMetricsConfiguration { |
| 62 | + static class CustomKafkaClientMetricsConfiguration { |
63 | 63 |
|
64 | 64 | @Bean
|
65 |
| - KafkaConsumerMetrics customKafkaConsumerMetrics() { |
66 |
| - return new KafkaConsumerMetrics(); |
| 65 | + KafkaClientMetrics customKafkaClientMetrics() { |
| 66 | + return mock(KafkaClientMetrics.class); |
67 | 67 | }
|
68 | 68 |
|
69 | 69 | }
|
|
0 commit comments