【发布时间】:2016-12-02 22:26:34
【问题描述】:
我决定回到我在此处提到的将 Kafka Metrics 与 Spring Boot Actuator 集成的想法:
https://github.com/spring-projects/spring-boot/issues/6227
到目前为止,我有一个带有工作代码的单独“沙盒”项目,我想将其合并到 Spring Boot 中。现在我有点困惑。我的部分测试需要 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.
}
但是在 Spring Boot 中没有使用 powermock。
我该怎么办?
- 在 spring-boot-dependencies 和 spring-boot-actuator 中添加最新的稳定 powermock。
- 仅将最新的稳定 powermock 添加到 spring-boot-actuator - 让它成为一个隐藏的秘密助手。
- 排除需要 powermock 的测试。
- 忘掉 Kafka Metrics,它们又大又可怕,没有人愿意在我们友好的 Spring Boot Actuator 中使用它们。
【问题讨论】:
-
如何使用
Metrics.addMetric()创建KafkaMetric实例,然后通过您的KafkaStatisticsProvider.metricChange()对其做出反应,您将在测试前将其注册到Metrics实例中?当然,而不是 Powermock。不熟悉 Kafka Metrics,但我分叉了你的项目。看起来很简单,但需要一些时间来弄清楚发生了什么。如果周末没有时间,我们会在周一回复您。 -
这回答了问题,案件已结案,谢谢。期待您的来信
标签: spring-boot apache-kafka spring-boot-actuator spring-kafka