@Test void freeSwapSpaceIsCalculated() { this.mockCollectorWithDefaults(); when(this.osBean.getFreeSwapSpaceSize()).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.getMinFreeSwapSpace(), is(9L)); assertThat(collector.getMaxFreeSwapSpace(), is(11L)); assertThat(collector.getTotalFreeSwapSpace(), is(40L)); }
when(data.getCount()).thenReturn(5); when(data.getTotalFreePhysMemory()).thenReturn(0L); when(data.getTotalFreeSwapSpace()).thenReturn(0L); when(data.getTotalComittedHeapMemorySize()).thenReturn(0L); when(data.getTotalComittedNonHeapMemorySize()).thenReturn(0L); 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(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_FREE_SWAP_SPACE, (Object) (data.getTotalFreeSwapSpace() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_USED_HEAP_MEMORY, (Object) (data.getTotalUsedHeapMemorySize() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_USED_NON_HEAP_MEMORY, (Object) (data.getTotalUsedNonHeapMemorySize() / data.getCount())));
assertThat(memoryInformationData.getMaxFreePhysMemory(), is(0L)); assertThat(memoryInformationData.getTotalFreeSwapSpace(), is(0L)); assertThat(memoryInformationData.getMinFreeSwapSpace(), is(Long.MAX_VALUE)); assertThat(memoryInformationData.getMaxFreeSwapSpace(), is(0L));
when(data.getCount()).thenReturn(5); when(data.getTotalFreePhysMemory()).thenReturn(RandomUtils.nextLong()); when(data.getTotalFreeSwapSpace()).thenReturn(RandomUtils.nextLong()); when(data.getTotalComittedHeapMemorySize()).thenReturn(RandomUtils.nextLong()); when(data.getTotalComittedNonHeapMemorySize()).thenReturn(RandomUtils.nextLong()); 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(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_FREE_SWAP_SPACE, (Object) (data.getTotalFreeSwapSpace() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_USED_HEAP_MEMORY, (Object) (data.getTotalUsedHeapMemorySize() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.MemoryInformation.FIELD_AVG_USED_NON_HEAP_MEMORY, (Object) (data.getTotalUsedNonHeapMemorySize() / data.getCount())));
assertThat(memoryInformationData.getMaxFreePhysMemory(), is(6L)); assertThat(memoryInformationData.getTotalFreeSwapSpace(), is(7L)); assertThat(memoryInformationData.getMinFreeSwapSpace(), is(8L)); assertThat(memoryInformationData.getMaxFreeSwapSpace(), is(9L));
if (data.getTotalFreeSwapSpace() > 0) { freeSwapSpace = data.getTotalFreeSwapSpace() / count;
newMemoryInformationData.setMaxFreePhysMemory(this.memoryInformationData.getMaxFreePhysMemory()); newMemoryInformationData.setTotalFreeSwapSpace(this.memoryInformationData.getTotalFreeSwapSpace()); newMemoryInformationData.setMinFreeSwapSpace(this.memoryInformationData.getMinFreeSwapSpace()); newMemoryInformationData.setMaxFreeSwapSpace(this.memoryInformationData.getMaxFreeSwapSpace());