From 9b0d48e5c8275718a3cddaaf63011b2d50d8cdaa Mon Sep 17 00:00:00 2001 From: Asaf Mesika Date: Tue, 9 Jan 2024 17:05:23 +0200 Subject: [PATCH] Added more tests for code coverage --- ...utableExponentialHistogramBucketsTest.java | 10 ++++++--- ...ableExponentialHistogramPointDataTest.java | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/data/MutableExponentialHistogramBucketsTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/data/MutableExponentialHistogramBucketsTest.java index 0d2c04145f4..067f34a54c7 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/data/MutableExponentialHistogramBucketsTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/data/MutableExponentialHistogramBucketsTest.java @@ -30,13 +30,17 @@ void testSanity() { assertThat(buckets.getBucketCounts()).containsExactly(1L, 2L, 3L); assertThat(buckets.getReusableBucketCountsList()).containsExactly(1L, 2L, 3L); + assertThat(buckets.toString()) + .isEqualTo( + "MutableExponentialHistogramBuckets{scale=1, offset=2, bucketCounts=[1, 2, 3], totalCount=3}"); + MutableExponentialHistogramBuckets sameBuckets = new MutableExponentialHistogramBuckets(); sameBuckets.set(1, 2, 3, DynamicPrimitiveLongList.of(1, 2, 3)); assertThat(sameBuckets).isEqualTo(buckets); assertThat(sameBuckets.hashCode()).isEqualTo(buckets.hashCode()); - assertThat(buckets.toString()) - .isEqualTo( - "MutableExponentialHistogramBuckets{scale=1, offset=2, bucketCounts=[1, 2, 3], totalCount=3}"); + sameBuckets.set(1, 2, 3, DynamicPrimitiveLongList.of(1, 20, 3)); + assertThat(sameBuckets).isNotEqualTo(buckets); + assertThat(sameBuckets.hashCode()).isNotEqualTo(buckets.hashCode()); } } diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/data/MutableExponentialHistogramPointDataTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/data/MutableExponentialHistogramPointDataTest.java index 7a6466b2d9a..0cd56aa6f72 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/data/MutableExponentialHistogramPointDataTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/data/MutableExponentialHistogramPointDataTest.java @@ -89,5 +89,26 @@ public void testSanity() { Attributes.of(AttributeKey.stringKey("foo"), "bar"), Collections.emptyList()); assertThat(samePointData).isEqualTo(pointData); + assertThat(samePointData.hashCode()).isEqualTo(pointData.hashCode()); + + MutableExponentialHistogramPointData differentPointData = + new MutableExponentialHistogramPointData(); + differentPointData.set( + /* scale= */ 1, + /* sum= */ 2, + /* zeroCount= */ 10000000, + /* hasMin= */ true, + /* min= */ 100, + /* hasMax= */ true, + /* max= */ 1000, + positiveBuckets, + negativeBuckets, + /* startEpochNanos= */ 10, + /* epochNanos= */ 20, + Attributes.of(AttributeKey.stringKey("foo"), "bar"), + Collections.emptyList()); + + assertThat(differentPointData).isNotEqualTo(pointData); + assertThat(differentPointData.hashCode()).isNotEqualTo(pointData.hashCode()); } }