Skip to content

Commit

Permalink
Merge branch '1.10.x' into 1.11.x
Browse files Browse the repository at this point in the history
  • Loading branch information
marcingrzejszczak committed Dec 28, 2023
2 parents b8ffc44 + a687509 commit 51745d7
Showing 1 changed file with 2 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,26 +338,7 @@ void emptyShouldNotContainTags() {
@Issue("#3313")
@DisabledIfSystemProperty(named = "java.vm.name", matches = JAVA_VM_NAME_J9_REGEX,
disabledReason = "Sun ThreadMXBean with allocation counter not available")
@EnabledForJreRange(max = JRE.JAVA_18)
void andEmptyDoesNotAllocate() {
andEmptyDoesNotAllocate(0);
}

// See https://github.com/micrometer-metrics/micrometer/issues/3436
@Test
@Issue("#3313")
@DisabledIfSystemProperty(named = "java.vm.name", matches = JAVA_VM_NAME_J9_REGEX,
disabledReason = "Sun ThreadMXBean with allocation counter not available")
@EnabledIf("java19")
void andEmptyDoesNotAllocateOnJava19() {
andEmptyDoesNotAllocate(16);
}

static boolean java19() {
return "19".equals(System.getProperty("java.version"));
}

private void andEmptyDoesNotAllocate(int expectedAllocatedBytes) {
ThreadMXBean threadMXBean = (ThreadMXBean) ManagementFactory.getThreadMXBean();
long currentThreadId = Thread.currentThread().getId();
Tags tags = Tags.of("a", "b");
Expand All @@ -368,29 +349,14 @@ private void andEmptyDoesNotAllocate(int expectedAllocatedBytes) {
long allocatedBytes = threadMXBean.getThreadAllocatedBytes(currentThreadId) - allocatedBytesBefore;

assertThat(combined).isEqualTo(tags);
assertThat(allocatedBytes).isEqualTo(expectedAllocatedBytes);
assertThat(allocatedBytes).isEqualTo(0);
}

@Test
@Issue("#3313")
@DisabledIfSystemProperty(named = "java.vm.name", matches = JAVA_VM_NAME_J9_REGEX,
disabledReason = "Sun ThreadMXBean with allocation counter not available")
@EnabledForJreRange(max = JRE.JAVA_18)
void ofEmptyDoesNotAllocate() {
ofEmptyDoesNotAllocate(0);
}

// See https://github.com/micrometer-metrics/micrometer/issues/3436
@Test
@Issue("#3313")
@DisabledIfSystemProperty(named = "java.vm.name", matches = JAVA_VM_NAME_J9_REGEX,
disabledReason = "Sun ThreadMXBean with allocation counter not available")
@EnabledIf("java19")
void ofEmptyDoesNotAllocateOnJava19() {
ofEmptyDoesNotAllocate(16);
}

private void ofEmptyDoesNotAllocate(int expectedAllocatedBytes) {
ThreadMXBean threadMXBean = (ThreadMXBean) ManagementFactory.getThreadMXBean();
long currentThreadId = Thread.currentThread().getId();
Tags extraTags = Tags.empty();
Expand All @@ -400,7 +366,7 @@ private void ofEmptyDoesNotAllocate(int expectedAllocatedBytes) {
long allocatedBytes = threadMXBean.getThreadAllocatedBytes(currentThreadId) - allocatedBytesBefore;

assertThat(of).isEqualTo(Tags.empty());
assertThat(allocatedBytes).isEqualTo(expectedAllocatedBytes);
assertThat(allocatedBytes).isEqualTo(0);
}

private void assertTags(Tags tags, String... keyValues) {
Expand Down

0 comments on commit 51745d7

Please sign in to comment.