Skip to content

Commit

Permalink
Convert tests to from :sdk:metrics-testing to :sdk:testing (#4444)
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg authored May 9, 2022
1 parent 89c6323 commit e067223
Show file tree
Hide file tree
Showing 67 changed files with 2,594 additions and 3,420 deletions.
4 changes: 4 additions & 0 deletions docs/apidiffs/current_vs_latest/opentelemetry-sdk-testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ Comparing source compatibility of against
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.HistogramPointAssert hasBucketBoundaries(double[])
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.HistogramPointAssert hasBucketCounts(long[])
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.HistogramPointAssert hasCount(long)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.HistogramPointAssert hasExemplars(io.opentelemetry.sdk.metrics.data.DoubleExemplarData[])
+++ NEW METHOD: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.testing.assertj.HistogramPointAssert hasExemplarsSatisfying(java.util.function.Consumer[])
+++ NEW ANNOTATION: java.lang.SafeVarargs
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.HistogramPointAssert hasExemplarsSatisfying(java.lang.Iterable)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.HistogramPointAssert hasMax(double)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.HistogramPointAssert hasMin(double)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.HistogramPointAssert hasSum(double)
Expand Down
1 change: 0 additions & 1 deletion exporters/otlp/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ dependencies {
testRuntimeOnly("io.grpc:grpc-netty-shaded")

jmhImplementation(project(":sdk:testing"))
jmhImplementation(project(":sdk:metrics-testing"))
jmhImplementation(project(":sdk-extensions:resources"))
jmhImplementation("com.fasterxml.jackson.core:jackson-core")
jmhImplementation("io.opentelemetry.proto:opentelemetry-proto")
Expand Down
3 changes: 0 additions & 3 deletions micrometer1-shim/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies {

api("io.micrometer:micrometer-core")

testImplementation(project(":sdk:metrics-testing"))
testImplementation(project(":sdk:testing"))
}

Expand All @@ -25,7 +24,6 @@ testing {
}
}
dependencies {
implementation(project(":sdk:metrics-testing"))
implementation(project(":sdk:testing"))

implementation(project.dependencies.enforcedPlatform("io.micrometer:micrometer-bom:1.5.17"))
Expand All @@ -38,7 +36,6 @@ testing {
}
}
dependencies {
implementation(project(":sdk:metrics-testing"))
implementation(project(":sdk:testing"))

implementation(project.dependencies.enforcedPlatform("io.micrometer:micrometer-bom:1.6.13"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package io.opentelemetry.micrometer1shim;

import static io.opentelemetry.micrometer1shim.OpenTelemetryMeterRegistryBuilder.INSTRUMENTATION_NAME;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;

import io.micrometer.core.instrument.Counter;
Expand Down Expand Up @@ -41,15 +41,14 @@ void testCounter() {
InstrumentationScopeInfo.create(INSTRUMENTATION_NAME, null, null))
.hasDescription("This is a test counter")
.hasUnit("items")
.hasDoubleSum()
.isMonotonic()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(3)
.attributes()
.containsOnly(attributeEntry("tag", "value"))));
.hasDoubleSumSatisfying(
sum ->
sum.isMonotonic()
.hasPointsSatisfying(
point ->
point
.hasValue(3)
.hasAttributes(attributeEntry("tag", "value")))));

Metrics.globalRegistry.remove(counter);
counter.increment();
Expand All @@ -60,8 +59,7 @@ void testCounter() {
metric ->
assertThat(metric)
.hasName("testCounter")
.hasDoubleSum()
.points()
.satisfiesExactly(point -> assertThat(point).hasValue(3)));
.hasDoubleSumSatisfying(
sum -> sum.hasPointsSatisfying(point -> point.hasValue(3))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package io.opentelemetry.micrometer1shim;

import static io.opentelemetry.micrometer1shim.OpenTelemetryMeterRegistryBuilder.INSTRUMENTATION_NAME;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;

import io.micrometer.core.instrument.DistributionSummary;
Expand Down Expand Up @@ -42,27 +42,25 @@ void testMicrometerDistributionSummary() {
InstrumentationScopeInfo.create(INSTRUMENTATION_NAME, null, null))
.hasDescription("This is a test distribution summary")
.hasUnit("things")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasSum(7)
.hasCount(3)
.attributes()
.containsOnly(attributeEntry("tag", "value"))),
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(7)
.hasCount(3)
.hasAttributes(attributeEntry("tag", "value")))),
metric ->
assertThat(metric)
.hasName("testSummary.max")
.hasDescription("This is a test distribution summary")
.hasDoubleGauge()
.points()
.anySatisfy(
point ->
assertThat(point)
.hasValue(4)
.attributes()
.containsEntry("tag", "value")));
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasValue(4)
.hasAttributes(attributeEntry("tag", "value")))));

Metrics.globalRegistry.remove(summary);

Expand All @@ -73,15 +71,14 @@ void testMicrometerDistributionSummary() {
metric ->
assertThat(metric)
.hasName("testSummary")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasSum(7)
.hasCount(3)
.attributes()
.containsOnly(attributeEntry("tag", "value"))));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(7)
.hasCount(3)
.hasAttributes(attributeEntry("tag", "value")))));
}

@Test
Expand Down Expand Up @@ -109,44 +106,55 @@ void testMicrometerHistogram() {
InstrumentationScopeInfo.create(INSTRUMENTATION_NAME, null, null))
.hasDescription("This is a test distribution summary")
.hasUnit("things")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasSum(555.5)
.hasCount(4)
.attributes()
.containsOnly(attributeEntry("tag", "value"))),
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
points ->
points
.hasSum(555.5)
.hasCount(4)
.hasAttributes(attributeEntry("tag", "value")))),
metric ->
assertThat(metric)
.hasName("testSummary.max")
.hasDescription("This is a test distribution summary")
.hasDoubleGauge()
.points()
.anySatisfy(
point ->
assertThat(point)
.hasValue(500)
.attributes()
.containsEntry("tag", "value")),
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasValue(500)
.hasAttributes(attributeEntry("tag", "value")))),
metric ->
assertThat(metric)
.hasName("testSummary.histogram")
.hasDoubleGauge()
.points()
.satisfiesExactlyInAnyOrder(
point ->
assertThat(point).hasValue(1).attributes().containsEntry("le", "1"),
point ->
assertThat(point).hasValue(2).attributes().containsEntry("le", "10"),
point ->
assertThat(point).hasValue(3).attributes().containsEntry("le", "100"),
point ->
assertThat(point)
.hasValue(4)
.attributes()
.containsEntry("le", "1000")));
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasValue(1)
.hasAttributes(
attributeEntry("le", "1"),
attributeEntry("tag", "value")),
point ->
point
.hasValue(2)
.hasAttributes(
attributeEntry("le", "10"),
attributeEntry("tag", "value")),
point ->
point
.hasValue(3)
.hasAttributes(
attributeEntry("le", "100"),
attributeEntry("tag", "value")),
point ->
point
.hasValue(4)
.hasAttributes(
attributeEntry("le", "1000"),
attributeEntry("tag", "value")))));
}

@Test
Expand All @@ -171,36 +179,42 @@ void testMicrometerPercentiles() {
InstrumentationScopeInfo.create(INSTRUMENTATION_NAME, null, null))
.hasDescription("This is a test distribution summary")
.hasUnit("things")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasSum(150)
.hasCount(2)
.attributes()
.containsOnly(attributeEntry("tag", "value"))),
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(150)
.hasCount(2)
.hasAttributes(attributeEntry("tag", "value")))),
metric ->
assertThat(metric)
.hasName("testSummary.max")
.hasDescription("This is a test distribution summary")
.hasDoubleGauge()
.points()
.anySatisfy(
point ->
assertThat(point)
.hasValue(100)
.attributes()
.containsEntry("tag", "value")),
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasValue(100)
.hasAttributes(attributeEntry("tag", "value")))),
metric ->
assertThat(metric)
.hasName("testSummary.percentile")
.hasDoubleGauge()
.points()
.anySatisfy(point -> assertThat(point).attributes().containsEntry("phi", "0.5"))
.anySatisfy(
point -> assertThat(point).attributes().containsEntry("phi", "0.95"))
.anySatisfy(
point -> assertThat(point).attributes().containsEntry("phi", "0.99")));
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point.hasAttributes(
attributeEntry("phi", "0.5"),
attributeEntry("tag", "value")),
point ->
point.hasAttributes(
attributeEntry("phi", "0.95"),
attributeEntry("tag", "value")),
point ->
point.hasAttributes(
attributeEntry("phi", "0.99"),
attributeEntry("tag", "value")))));
}
}
Loading

0 comments on commit e067223

Please sign in to comment.