@Test void cpuUsageIsSetForMinAndMaxOnTheFirstRun() { when(this.osBean.retrieveCpuUsage()).thenReturn(10f); this.cut.gather(); CpuInformationData collector = (CpuInformationData) this.cut.get(); assertThat(collector.getMinCpuUsage(), is(10f)); assertThat(collector.getMaxCpuUsage(), is(10f)); assertThat(collector.getTotalCpuUsage(), is(10f)); }
/** * Updates the upper plot with the given input data. * * @param cpuData * The input data. */ private void addUpperPlotData(List<CpuInformationData> cpuData) { for (CpuInformationData data : cpuData) { float cpuAverage = data.getTotalCpuUsage() / data.getCount(); cpuUsage.add(data.getTimeStamp().getTime(), cpuAverage, data.getMinCpuUsage(), data.getMaxCpuUsage(), false); } cpuUsage.fireSeriesChanged(); }
@Test void cpuUsageIsCalculated() { when(this.osBean.retrieveCpuUsage()).thenReturn(10f).thenReturn(9f).thenReturn(11f).thenReturn(10f); this.cut.gather(); this.cut.gather(); this.cut.gather(); this.cut.gather(); CpuInformationData collector = (CpuInformationData) this.cut.get(); assertThat(collector.getMinCpuUsage(), is(9f)); assertThat(collector.getMaxCpuUsage(), is(11f)); assertThat(collector.getTotalCpuUsage(), is(40f)); }
/** * {@inheritDoc} */ @Override protected void addFields(CpuInformationData data, Builder builder) { float cpuAverage = data.getTotalCpuUsage() / data.getCount(); // fields builder.addField(Series.CpuInformation.FIELD_AVG_CPU_UTIL, cpuAverage); builder.addField(Series.CpuInformation.FIELD_MIN_CPU_UTIL, data.getMinCpuUsage()); builder.addField(Series.CpuInformation.FIELD_MAX_CPU_UTIL, data.getMaxCpuUsage()); }
@Test public void happyPath() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(platformIdent); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getCount()).thenReturn(5); when(data.getTotalCpuUsage()).thenReturn(RandomUtils.nextFloat()); when(data.getMinCpuUsage()).thenReturn(RandomUtils.nextFloat()); when(data.getMaxCpuUsage()).thenReturn(RandomUtils.nextFloat()); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.CpuInformation.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); 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.CpuInformation.FIELD_AVG_CPU_UTIL, (Object) Double.valueOf(data.getTotalCpuUsage() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.CpuInformation.FIELD_MAX_CPU_UTIL, (Object) Double.valueOf(data.getMaxCpuUsage()))); assertThat(getFields(pointBuilder), hasEntry(Series.CpuInformation.FIELD_MIN_CPU_UTIL, (Object) Double.valueOf(data.getMinCpuUsage()))); }
@Test void getNewCpuInformationData() throws Exception { CpuInformationData collector = (CpuInformationData) this.cut.getSystemSensorData(); collector.setCount(1); collector.setPlatformIdent(2L); collector.setSensorTypeIdent(3L); collector.setProcessCpuTime(4L); collector.setTotalCpuUsage(5f); collector.setMaxCpuUsage(6f); collector.setMinCpuUsage(7f); collector.setTimeStamp(new Timestamp(8L)); CpuInformationData cpuInformationData = (CpuInformationData) this.cut.get(); assertThat(cpuInformationData.getCount(), is(1)); assertThat(cpuInformationData.getPlatformIdent(), is(2L)); assertThat(cpuInformationData.getSensorTypeIdent(), is(3L)); assertThat(cpuInformationData.getProcessCpuTime(), is(4L)); assertThat(cpuInformationData.getTotalCpuUsage(), is(5f)); assertThat(cpuInformationData.getMaxCpuUsage(), is(6f)); assertThat(cpuInformationData.getMinCpuUsage(), is(7f)); assertThat(cpuInformationData.getTimeStamp().getTime(), is(8L)); } }
@Test void collectorClassIsResetted() throws Exception { CpuInformationData collector = (CpuInformationData) this.cut.getSystemSensorData(); collector.setCount(1); collector.setPlatformIdent(2L); collector.setSensorTypeIdent(3L); collector.setProcessCpuTime(4L); collector.setTotalCpuUsage(5f); collector.setMaxCpuUsage(6f); collector.setMinCpuUsage(7f); collector.setTimeStamp(new Timestamp(8L)); this.cut.reset(); CpuInformationData cpuInformationData = (CpuInformationData) this.cut.get(); assertThat(cpuInformationData.getCount(), is(0)); assertThat(cpuInformationData.getPlatformIdent(), is(2L)); assertThat(cpuInformationData.getSensorTypeIdent(), is(3L)); assertThat(cpuInformationData.getProcessCpuTime(), is(0L)); assertThat(cpuInformationData.getTotalCpuUsage(), is(0f)); assertThat(cpuInformationData.getMaxCpuUsage(), is(0f)); assertThat(cpuInformationData.getMinCpuUsage(), is(Float.MAX_VALUE)); assertThat(cpuInformationData.getTimeStamp().getTime(), is(not(8L))); } }
/** * {@inheritDoc} */ @Override public SystemSensorData get() { CpuInformationData newCpuInformationData = new CpuInformationData(); newCpuInformationData.setPlatformIdent(this.cpuInformationData.getPlatformIdent()); newCpuInformationData.setSensorTypeIdent(this.cpuInformationData.getSensorTypeIdent()); newCpuInformationData.setCount(this.cpuInformationData.getCount()); newCpuInformationData.setProcessCpuTime(this.cpuInformationData.getProcessCpuTime()); newCpuInformationData.setTotalCpuUsage(this.cpuInformationData.getTotalCpuUsage()); newCpuInformationData.setMinCpuUsage(this.cpuInformationData.getMinCpuUsage()); newCpuInformationData.setMaxCpuUsage(this.cpuInformationData.getMaxCpuUsage()); newCpuInformationData.setTimeStamp(this.cpuInformationData.getTimeStamp()); return newCpuInformationData; }