Kafkametricsreporter背靠Spring Boot致动器

whitzsjs  于 2021-06-07  发布在  Kafka
关注(0)|答案(1)|浏览(315)

我决定回到我的想法,将kafka度量与spring boot actuator集成在一起,我在这里提到:
https://github.com/spring-projects/spring-boot/issues/6227
到现在为止,我有一个单独的“沙盒”项目和工作代码,我想合并到springboot中。现在我有点困惑了。我的部分测试需要powermock来模拟kafka的“超级安全”类:

package org.apache.kafka.common.metrics;

// some imports...

public final class KafkaMetric implements Metric {
    private MetricName metricName;
    private final Object lock;
    private final Time time;
    private final Measurable measurable;
    private MetricConfig config;

    KafkaMetric(Object lock, MetricName metricName, Measurable measurable, MetricConfig config, Time time) {
        this.metricName = metricName;
        this.lock = lock;
        this.measurable = measurable;
        this.config = config;
        this.time = time;
    }

    // some good code here, but no public constructor and the class is final... of course.

}

但powermock并没有在spring boot中使用。
我该怎么办?
添加最新的稳定的powermock-在spring-boot依赖项和spring-boot-actuator中。
添加最新的稳定powermock到Spring启动驱动器只-让它成为一个隐藏的秘密助手。
排除需要powermock的测试。
忘了Kafka的指标,他们是巨大的和可怕的,没有人希望他们在我们漂亮和友好的 Spring 启动驱动器。

9rygscc1

9rygscc11#

在评论中得到您的确认后,我将我的评论复制到这里,作为正确回答问题的有效答案。
你可以试着用 Metrics.addMetric() 创造 KafkaMetric 然后通过你的 KafkaStatisticsProvider.metricChange() ,您将在 Metrics 测试前的示例。当然不是powermock。
下周我会尽量抽出时间为您的执行器项目贡献这一部分,以避免powermock。

相关问题