Skip to content

Commit

Permalink
Avoid producing empty AdditionalIndexedClassesBuildItem
Browse files Browse the repository at this point in the history
Even if it doesn't complain right now,
that's certainly something that could break later
  • Loading branch information
vkn committed Dec 17, 2024
1 parent e24f716 commit be1fa40
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
5 changes: 5 additions & 0 deletions extensions/mongodb-client/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,18 @@ AdditionalIndexedClassesBuildItem includeMongoCommandListener(MongoClientBuildTi
}

@BuildStep
AdditionalIndexedClassesBuildItem includeMongoCommandMetricListener(
void includeMongoCommandMetricListener(
BuildProducer<AdditionalIndexedClassesBuildItem> additionalIndexedClasses,
MongoClientBuildTimeConfig buildTimeConfig,
Optional<MetricsCapabilityBuildItem> metricsCapability) {
if (!buildTimeConfig.metricsEnabled) {
return new AdditionalIndexedClassesBuildItem();
return;
}
boolean withMicrometer = metricsCapability.map(cap -> cap.metricsSupported(MetricsFactory.MICROMETER))
.orElse(false);
if (withMicrometer) {
return new AdditionalIndexedClassesBuildItem(MicrometerCommandListener.class.getName());
additionalIndexedClasses.produce(new AdditionalIndexedClassesBuildItem(MicrometerCommandListener.class.getName()));
}
return new AdditionalIndexedClassesBuildItem();
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package io.quarkus.mongodb.deployment;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

import java.util.Optional;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.mockito.ArgumentCaptor;

import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.builditem.AdditionalIndexedClassesBuildItem;
import io.quarkus.deployment.metrics.MetricsCapabilityBuildItem;
import io.quarkus.runtime.metrics.MetricsFactory;

class MongoClientProcessorTest {
private final MongoClientProcessor buildStep = new MongoClientProcessor();

@SuppressWarnings("unchecked")
@ParameterizedTest
@CsvSource({
"true, true, true", // Metrics enabled and Micrometer supported
Expand All @@ -25,13 +30,16 @@ void testIncludeMongoCommandMetricListener(boolean metricsEnabled, boolean micro
MongoClientBuildTimeConfig config = config(metricsEnabled);
Optional<MetricsCapabilityBuildItem> capability = capability(metricsEnabled, micrometerSupported);

AdditionalIndexedClassesBuildItem result = buildStep.includeMongoCommandMetricListener(config, capability);
BuildProducer<AdditionalIndexedClassesBuildItem> buildProducer = mock(BuildProducer.class);
buildStep.includeMongoCommandMetricListener(buildProducer, config, capability);

if (expectedResult) {
assertThat(result.getClassesToIndex())
var captor = ArgumentCaptor.forClass(AdditionalIndexedClassesBuildItem.class);
verify(buildProducer, times(1)).produce(captor.capture());
assertThat(captor.getAllValues().get(0).getClassesToIndex())
.containsExactly("io.quarkus.mongodb.metrics.MicrometerCommandListener");
} else {
assertThat(result.getClassesToIndex()).isEmpty();
verify(buildProducer, never()).produce(any(AdditionalIndexedClassesBuildItem.class));
}
}

Expand Down

0 comments on commit be1fa40

Please sign in to comment.