Skip to content

Commit a5d8b67

Browse files
committed
new test
1 parent 4e566d7 commit a5d8b67

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/state/AsynchronousMetricStorageTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,37 @@ void record_MaxCardinality(MemoryMode memoryMode) {
208208
logs.assertContains("Instrument long-counter has exceeded the maximum allowed cardinality");
209209
}
210210

211+
@ParameterizedTest
212+
@EnumSource(MemoryMode.class)
213+
void record_HandlesSpotsAreReleasedAfterCollection(MemoryMode memoryMode) {
214+
setup(memoryMode);
215+
216+
longCounterStorage.setEpochInformation(0, 1);
217+
for (int i = 0; i < CARDINALITY_LIMIT - 1; i++) {
218+
longCounterStorage.record(Attributes.builder().put("key" + i, "val").build(), 1);
219+
}
220+
221+
assertThat(longCounterStorage.collect(resource, scope, 0, testClock.nanoTime()))
222+
.satisfies(
223+
metricData ->
224+
assertThat(metricData.getLongSumData().getPoints()).hasSize(CARDINALITY_LIMIT - 1));
225+
logs.assertDoesNotContain(
226+
"Instrument long-counter has exceeded the maximum allowed cardinality");
227+
228+
longCounterStorage.setEpochInformation(1, 2);
229+
for (int i = 0; i < CARDINALITY_LIMIT - 1; i++) {
230+
// Different attribute
231+
longCounterStorage.record(Attributes.builder().put("key" + i, "val2").build(), 1);
232+
}
233+
234+
assertThat(longCounterStorage.collect(resource, scope, 0, testClock.nanoTime()))
235+
.satisfies(
236+
metricData ->
237+
assertThat(metricData.getLongSumData().getPoints()).hasSize(CARDINALITY_LIMIT - 1));
238+
logs.assertDoesNotContain(
239+
"Instrument long-counter has exceeded the maximum allowed cardinality");
240+
}
241+
211242
@ParameterizedTest
212243
@EnumSource(MemoryMode.class)
213244
void record_DuplicateAttributes(MemoryMode memoryMode) {

0 commit comments

Comments
 (0)