protected void mockCollectorWithDefaults() { MemoryUsage heapMemoryUsage = Mockito.mock(MemoryUsage.class); when(heapMemoryUsage.getUsed()).thenReturn(0L); when(heapMemoryUsage.getCommitted()).thenReturn(0L); MemoryUsage nonHeapMemoryUsage = Mockito.mock(MemoryUsage.class); when(nonHeapMemoryUsage.getUsed()).thenReturn(0L); when(nonHeapMemoryUsage.getCommitted()).thenReturn(0L); when(this.osBean.getFreePhysicalMemorySize()).thenReturn(0L); when(this.osBean.getFreeSwapSpaceSize()).thenReturn(0L); when(this.osBean.getCommittedVirtualMemorySize()).thenReturn(0L); when(this.memoryBean.getHeapMemoryUsage()).thenReturn(heapMemoryUsage); when(this.memoryBean.getNonHeapMemoryUsage()).thenReturn(nonHeapMemoryUsage); } }
@Test void usedNonHeapMemorySizeIsCalculated() { this.mockCollectorWithDefaults(); MemoryUsage nonHeapMemoryUsage = this.memoryBean.getNonHeapMemoryUsage(); when(nonHeapMemoryUsage.getUsed()).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.getMinUsedNonHeapMemorySize(), is(9L)); assertThat(collector.getMaxUsedNonHeapMemorySize(), is(11L)); assertThat(collector.getTotalUsedNonHeapMemorySize(), is(40L)); }
@Test void comittedNonHeapMemorySizeIsCalculated() { this.mockCollectorWithDefaults(); MemoryUsage nonHeapMemoryUsage = this.memoryBean.getNonHeapMemoryUsage(); when(nonHeapMemoryUsage.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.getMinComittedNonHeapMemorySize(), is(9L)); assertThat(collector.getMaxComittedNonHeapMemorySize(), is(11L)); assertThat(collector.getTotalComittedNonHeapMemorySize(), is(40L)); }
when(nonHeapMemoryUsage.getInit()).thenReturn(18L); when(nonHeapMemoryUsage.getMax()).thenReturn(19L); when(this.memoryBean.getNonHeapMemoryUsage()).thenReturn(nonHeapMemoryUsage);
when(nonHeapMemoryUsageA.getInit()).thenReturn(18L); when(nonHeapMemoryUsageA.getMax()).thenReturn(19L); when(this.memoryBean.getNonHeapMemoryUsage()).thenReturn(nonHeapMemoryUsageA); when(nonHeapMemoryUsageB.getInit()).thenReturn(1800L); when(nonHeapMemoryUsageB.getMax()).thenReturn(1900L); when(this.memoryBean.getNonHeapMemoryUsage()).thenReturn(nonHeapMemoryUsageB);
this.systemInformationData.setMaxHeapMemorySize(this.getMemoryBean().getHeapMemoryUsage().getMax()); this.systemInformationData.setInitNonHeapMemorySize(this.getMemoryBean().getNonHeapMemoryUsage().getInit()); this.systemInformationData.setMaxNonHeapMemorySize(this.getMemoryBean().getNonHeapMemoryUsage().getMax());
long usedHeapMemorySize = this.getMemoryBean().getHeapMemoryUsage().getUsed(); long comittedHeapMemorySize = this.getMemoryBean().getHeapMemoryUsage().getCommitted(); long usedNonHeapMemorySize = this.getMemoryBean().getNonHeapMemoryUsage().getUsed(); long comittedNonHeapMemorySize = this.getMemoryBean().getNonHeapMemoryUsage().getCommitted();