@Test void comittedHeapMemorySizeIsCalculated() { this.mockCollectorWithDefaults(); MemoryUsage heapMemoryUsage = this.memoryBean.getHeapMemoryUsage(); when(heapMemoryUsage.getCommitted()).thenReturn(10L).thenReturn(9L).thenReturn(11L).thenReturn(10L); this.cut.gather(); this.cut.gather(); this.cut.gather(); this.cut.gather(); MemoryInformationData collector = (MemoryInformationData) this.cut.get(); assertThat(collector.getMinComittedHeapMemorySize(), is(9L)); assertThat(collector.getMaxComittedHeapMemorySize(), is(11L)); assertThat(collector.getTotalComittedHeapMemorySize(), is(40L)); }
when(data.getTotalFreePhysMemory()).thenReturn(0L); when(data.getTotalFreeSwapSpace()).thenReturn(0L); when(data.getTotalComittedHeapMemorySize()).thenReturn(0L); when(data.getTotalComittedNonHeapMemorySize()).thenReturn(0L); when(data.getTotalUsedHeapMemorySize()).thenReturn(0L); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_ID, String.valueOf(PLATFORM_ID))); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_NAME, String.valueOf(AGENT_NAME))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_COMMITTED_HEAP_MEMORY, (Object) (data.getTotalComittedHeapMemorySize() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_COMMITTED_NON_HEAP_MEMORY, (Object) (data.getTotalComittedNonHeapMemorySize() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_FREE_PHYS_MEMORY, (Object) (data.getTotalFreePhysMemory() / data.getCount())));
when(data.getTotalFreePhysMemory()).thenReturn(RandomUtils.nextLong()); when(data.getTotalFreeSwapSpace()).thenReturn(RandomUtils.nextLong()); when(data.getTotalComittedHeapMemorySize()).thenReturn(RandomUtils.nextLong()); when(data.getTotalComittedNonHeapMemorySize()).thenReturn(RandomUtils.nextLong()); when(data.getTotalUsedHeapMemorySize()).thenReturn(RandomUtils.nextLong()); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_ID, String.valueOf(PLATFORM_ID))); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_NAME, String.valueOf(AGENT_NAME))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_COMMITTED_HEAP_MEMORY, (Object) (data.getTotalComittedHeapMemorySize() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_COMMITTED_NON_HEAP_MEMORY, (Object) (data.getTotalComittedNonHeapMemorySize() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_FREE_PHYS_MEMORY, (Object) (data.getTotalFreePhysMemory() / data.getCount())));
assertThat(memoryInformationData.getMaxUsedHeapMemorySize(), is(15L)); assertThat(memoryInformationData.getTotalComittedHeapMemorySize(), is(16L)); assertThat(memoryInformationData.getMinComittedHeapMemorySize(), is(17L)); assertThat(memoryInformationData.getMaxComittedHeapMemorySize(), is(18L));
assertThat(memoryInformationData.getMaxUsedHeapMemorySize(), is(0L)); assertThat(memoryInformationData.getTotalComittedHeapMemorySize(), is(0L)); assertThat(memoryInformationData.getMinComittedHeapMemorySize(), is(Long.MAX_VALUE)); assertThat(memoryInformationData.getMaxComittedHeapMemorySize(), is(0L));
if (data.getTotalComittedHeapMemorySize() > 0) { committedHeapMemorySize = data.getTotalComittedHeapMemorySize() / count;
newMemoryInformationData.setMaxUsedHeapMemorySize(this.memoryInformationData.getMaxUsedHeapMemorySize()); newMemoryInformationData.setTotalComittedHeapMemorySize(this.memoryInformationData.getTotalComittedHeapMemorySize()); newMemoryInformationData.setMinComittedHeapMemorySize(this.memoryInformationData.getMinComittedHeapMemorySize()); newMemoryInformationData.setMaxComittedHeapMemorySize(this.memoryInformationData.getMaxComittedHeapMemorySize());