Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
import io.opentelemetry.sdk.testing.time.TestClock;
import java.time.Duration;
import java.util.stream.IntStream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand Down Expand Up @@ -174,96 +173,4 @@ void doubleCounterAdd_NaN() {
doubleCounter.add(Double.NaN);
assertThat(sdkMeterReader.collectAllMetrics()).hasSize(0);
}

@Test
void stressTest() {
DoubleCounter doubleCounter = sdkMeter.counterBuilder("testCounter").ofDoubles().build();

StressTestRunner.Builder stressTestBuilder =
StressTestRunner.builder().setCollectionIntervalMs(100);

for (int i = 0; i < 4; i++) {
stressTestBuilder.addOperation(
StressTestRunner.Operation.create(
1_000, 1, () -> doubleCounter.add(10, Attributes.builder().put("K", "V").build())));
}

stressTestBuilder.build().run();
assertThat(sdkMeterReader.collectAllMetrics())
.satisfiesExactly(
metric ->
assertThat(metric)
.hasResource(RESOURCE)
.hasInstrumentationScope(INSTRUMENTATION_SCOPE_INFO)
.hasName("testCounter")
.hasDoubleSumSatisfying(
sum ->
sum.isCumulative()
.isMonotonic()
.hasPointsSatisfying(
point ->
point
.hasStartEpochNanos(testClock.now())
.hasEpochNanos(testClock.now())
.hasValue(40000)
.hasAttributes(attributeEntry("K", "V")))));
}

@Test
void stressTest_WithDifferentLabelSet() {
String[] keys = {"Key_1", "Key_2", "Key_3", "Key_4"};
String[] values = {"Value_1", "Value_2", "Value_3", "Value_4"};
DoubleCounter doubleCounter = sdkMeter.counterBuilder("testCounter").ofDoubles().build();

StressTestRunner.Builder stressTestBuilder =
StressTestRunner.builder().setCollectionIntervalMs(100);

IntStream.range(0, 4)
.forEach(
i ->
stressTestBuilder.addOperation(
StressTestRunner.Operation.create(
2_000,
1,
() ->
doubleCounter.add(
10, Attributes.builder().put(keys[i], values[i]).build()))));

stressTestBuilder.build().run();
assertThat(sdkMeterReader.collectAllMetrics())
.satisfiesExactly(
metric ->
assertThat(metric)
.hasResource(RESOURCE)
.hasInstrumentationScope(INSTRUMENTATION_SCOPE_INFO)
.hasDoubleSumSatisfying(
sum ->
sum.isCumulative()
.isMonotonic()
.hasPointsSatisfying(
point ->
point
.hasStartEpochNanos(testClock.now())
.hasEpochNanos(testClock.now())
.hasValue(20_000)
.hasAttributes(attributeEntry(keys[0], values[0])),
point ->
point
.hasStartEpochNanos(testClock.now())
.hasEpochNanos(testClock.now())
.hasValue(20_000)
.hasAttributes(attributeEntry(keys[1], values[1])),
point ->
point
.hasStartEpochNanos(testClock.now())
.hasEpochNanos(testClock.now())
.hasValue(20_000)
.hasAttributes(attributeEntry(keys[2], values[2])),
point ->
point
.hasStartEpochNanos(testClock.now())
.hasEpochNanos(testClock.now())
.hasValue(20_000)
.hasAttributes(attributeEntry(keys[3], values[3])))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import java.time.Duration;
import java.util.Collections;
import java.util.stream.IntStream;
import org.junit.jupiter.api.Test;

/** Unit tests for {@link SdkDoubleGauge}. */
Expand Down Expand Up @@ -271,98 +270,4 @@ void collectMetrics_WithMultipleCollects() {
.hasValue(222d)
.hasAttributes(attributeEntry("K", "V")))));
}

@Test
void stressTest() {
DoubleGauge doubleGauge = sdkMeter.gaugeBuilder("testGauge").build();

StressTestRunner.Builder stressTestBuilder =
StressTestRunner.builder().setCollectionIntervalMs(100);

for (int i = 0; i < 4; i++) {
stressTestBuilder.addOperation(
StressTestRunner.Operation.create(
1_000,
1,
() -> {
doubleGauge.set(10, Attributes.builder().put("K", "V").build());
doubleGauge.set(11, Attributes.builder().put("K", "V").build());
}));
}

stressTestBuilder.build().run();
assertThat(cumulativeReader.collectAllMetrics())
.satisfiesExactly(
metric ->
assertThat(metric)
.hasResource(RESOURCE)
.hasInstrumentationScope(INSTRUMENTATION_SCOPE_INFO)
.hasName("testGauge")
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasStartEpochNanos(testClock.now())
.hasEpochNanos(testClock.now())
.hasValue(11)
.hasAttributes(attributeEntry("K", "V")))));
}

@Test
void stressTest_WithDifferentLabelSet() {
String[] keys = {"Key_1", "Key_2", "Key_3", "Key_4"};
String[] values = {"Value_1", "Value_2", "Value_3", "Value_4"};
DoubleGauge doubleGauge = sdkMeter.gaugeBuilder("testGauge").build();

StressTestRunner.Builder stressTestBuilder =
StressTestRunner.builder().setCollectionIntervalMs(100);

IntStream.range(0, 4)
.forEach(
i ->
stressTestBuilder.addOperation(
StressTestRunner.Operation.create(
2_000,
1,
() -> {
doubleGauge.set(10, Attributes.builder().put(keys[i], values[i]).build());
doubleGauge.set(11, Attributes.builder().put(keys[i], values[i]).build());
})));

stressTestBuilder.build().run();
assertThat(cumulativeReader.collectAllMetrics())
.satisfiesExactly(
metric ->
assertThat(metric)
.hasResource(RESOURCE)
.hasInstrumentationScope(INSTRUMENTATION_SCOPE_INFO)
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasStartEpochNanos(testClock.now())
.hasEpochNanos(testClock.now())
.hasValue(11)
.hasAttributes(attributeEntry(keys[0], values[0])),
point ->
point
.hasStartEpochNanos(testClock.now())
.hasEpochNanos(testClock.now())
.hasValue(11)
.hasAttributes(attributeEntry(keys[1], values[1])),
point ->
point
.hasStartEpochNanos(testClock.now())
.hasEpochNanos(testClock.now())
.hasValue(11)
.hasAttributes(attributeEntry(keys[2], values[2])),
point ->
point
.hasStartEpochNanos(testClock.now())
.hasEpochNanos(testClock.now())
.hasValue(11)
.hasAttributes(attributeEntry(keys[3], values[3])))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.stream.IntStream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand Down Expand Up @@ -369,108 +368,4 @@ void collectMetrics_ExemplarsWithExplicitBucketHistogram() {
.put("key", "value")
.build())))));
}

@Test
void stressTest() {
DoubleHistogram doubleHistogram = sdkMeter.histogramBuilder("testHistogram").build();

StressTestRunner.Builder stressTestBuilder =
StressTestRunner.builder().setCollectionIntervalMs(100);

for (int i = 0; i < 4; i++) {
stressTestBuilder.addOperation(
StressTestRunner.Operation.create(
1_000,
1,
() -> doubleHistogram.record(10, Attributes.builder().put("K", "V").build())));
}

stressTestBuilder.build().run();
assertThat(sdkMeterReader.collectAllMetrics())
.satisfiesExactly(
metric ->
assertThat(metric)
.hasResource(RESOURCE)
.hasInstrumentationScope(INSTRUMENTATION_SCOPE_INFO)
.hasName("testHistogram")
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasStartEpochNanos(testClock.now())
.hasEpochNanos(testClock.now())
.hasAttributes(attributeEntry("K", "V"))
.hasCount(4_000)
.hasSum(40_000))));
}

@Test
void stressTest_WithDifferentLabelSet() {
String[] keys = {"Key_1", "Key_2", "Key_3", "Key_4"};
String[] values = {"Value_1", "Value_2", "Value_3", "Value_4"};
DoubleHistogram doubleHistogram = sdkMeter.histogramBuilder("testHistogram").build();

StressTestRunner.Builder stressTestBuilder =
StressTestRunner.builder().setCollectionIntervalMs(100);

IntStream.range(0, 4)
.forEach(
i ->
stressTestBuilder.addOperation(
StressTestRunner.Operation.create(
2_000,
1,
() ->
doubleHistogram.record(
10, Attributes.builder().put(keys[i], values[i]).build()))));

stressTestBuilder.build().run();
assertThat(sdkMeterReader.collectAllMetrics())
.satisfiesExactly(
metric ->
assertThat(metric)
.hasResource(RESOURCE)
.hasInstrumentationScope(INSTRUMENTATION_SCOPE_INFO)
.hasName("testHistogram")
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasStartEpochNanos(testClock.now())
.hasEpochNanos(testClock.now())
.hasCount(2_000)
.hasSum(20_000)
.hasBucketCounts(
0, 0, 2000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
.hasAttributes(attributeEntry(keys[0], values[0])),
point ->
point
.hasStartEpochNanos(testClock.now())
.hasEpochNanos(testClock.now())
.hasCount(2_000)
.hasSum(20_000)
.hasBucketCounts(
0, 0, 2000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
.hasAttributes(attributeEntry(keys[1], values[1])),
point ->
point
.hasStartEpochNanos(testClock.now())
.hasEpochNanos(testClock.now())
.hasCount(2_000)
.hasSum(20_000)
.hasBucketCounts(
0, 0, 2000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
.hasAttributes(attributeEntry(keys[2], values[2])),
point ->
point
.hasStartEpochNanos(testClock.now())
.hasEpochNanos(testClock.now())
.hasCount(2_000)
.hasSum(20_000)
.hasBucketCounts(
0, 0, 2000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
.hasAttributes(attributeEntry(keys[3], values[3])))));
}
}
Loading
Loading