I decided to go back to my idea of integrating Kafka Metrics with Spring Boot Actuator, which I've mentioned here:
https://github.com/spring-projects/spring-boot/issues/6227
As of now I have a separate "sandbox" project with working code, which I want to merge into Spring Boot. And now I'm a bit confused. Part of my tests require powermock to Mock Kafka's "super-secured" class:
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.
}
But powermock is not used in Spring Boot.
What should I do?
Having your confirmation in the comments, I'm just copying here my comment as a valid answer to close the question properly.
You can try to use Metrics.addMetric()
to create KafkaMetric
instance and than react to it via your KafkaStatisticsProvider.metricChange()
, which you will register in the Metrics
instance before testing. Instead of Powermock, of course.
I will try to find time next week to contribute to your actuator project that part to avoid Powermock.