-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
101 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ient/deployment/src/test/java/io/quarkus/mongodb/deployment/MongoClientProcessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.quarkus.mongodb.deployment; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Optional; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
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(); | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"true, true, true", // Metrics enabled and Micrometer supported | ||
"true, false, false", // Metrics enabled but Micrometer not supported | ||
"false, true, false", // Metrics disabled and Micrometer supported | ||
"false, false, false" // Metrics disabled and Micrometer not supported | ||
}) | ||
void testIncludeMongoCommandMetricListener(boolean metricsEnabled, boolean micrometerSupported, boolean expectedResult) { | ||
MongoClientBuildTimeConfig config = config(metricsEnabled); | ||
Optional<MetricsCapabilityBuildItem> capability = capability(metricsEnabled, micrometerSupported); | ||
|
||
AdditionalIndexedClassesBuildItem result = buildStep.includeMongoCommandMetricListener(config, capability); | ||
|
||
if (expectedResult) { | ||
assertThat(result.getClassesToIndex()) | ||
.containsExactly("io.quarkus.mongodb.metrics.MicrometerCommandListener"); | ||
} else { | ||
assertThat(result.getClassesToIndex()).isEmpty(); | ||
} | ||
} | ||
|
||
private static Optional<MetricsCapabilityBuildItem> capability(boolean metricsEnabled, boolean micrometerSupported) { | ||
MetricsCapabilityBuildItem capability = metricsEnabled | ||
? new MetricsCapabilityBuildItem(factory -> MetricsFactory.MICROMETER.equals(factory) && micrometerSupported) | ||
: null; | ||
return Optional.ofNullable(capability); | ||
} | ||
|
||
private static MongoClientBuildTimeConfig config(boolean metricsEnabled) { | ||
MongoClientBuildTimeConfig buildTimeConfig = new MongoClientBuildTimeConfig(); | ||
buildTimeConfig.metricsEnabled = metricsEnabled; | ||
return buildTimeConfig; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters