/** * Aggregates other class loading object info this object. * * @param other * Object to aggregate data from. */ @Override public void aggregate(ThreadInformationData other) { count += other.count; minDaemonThreadCount = Math.min(other.getMinDaemonThreadCount(), minDaemonThreadCount); minPeakThreadCount = Math.min(other.getMinPeakThreadCount(), minPeakThreadCount); minThreadCount = Math.min(other.getMinThreadCount(), minThreadCount); minTotalStartedThreadCount = Math.min(other.getMinTotalStartedThreadCount(), minTotalStartedThreadCount); maxDaemonThreadCount = Math.max(other.getMaxDaemonThreadCount(), maxDaemonThreadCount); maxPeakThreadCount = Math.max(other.getMaxPeakThreadCount(), maxPeakThreadCount); maxThreadCount = Math.max(other.getMaxThreadCount(), maxThreadCount); maxTotalStartedThreadCount = Math.max(other.getMaxTotalStartedThreadCount(), maxTotalStartedThreadCount); totalDaemonThreadCount += other.getTotalDaemonThreadCount(); totalPeakThreadCount += other.getTotalPeakThreadCount(); totalThreadCount += other.getTotalThreadCount(); totalTotalStartedThreadCount += other.getTotalTotalStartedThreadCount(); }
@Test void totalStartedThreadCountIsCalculated() { when(this.threadBean.getTotalStartedThreadCount()).thenReturn(10L).thenReturn(9L).thenReturn(11L).thenReturn(10L); this.cut.gather(); this.cut.gather(); this.cut.gather(); this.cut.gather(); ThreadInformationData collector = (ThreadInformationData) this.cut.get(); assertThat(collector.getMinTotalStartedThreadCount(), is(9L)); assertThat(collector.getMaxTotalStartedThreadCount(), is(11L)); assertThat(collector.getTotalTotalStartedThreadCount(), is(40L)); }
@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.getTotalThreadCount()).thenReturn(RandomUtils.nextInt()); when(data.getTotalDaemonThreadCount()).thenReturn(RandomUtils.nextInt()); when(data.getTotalTotalStartedThreadCount()).thenReturn(RandomUtils.nextLong()); when(data.getTotalPeakThreadCount()).thenReturn(RandomUtils.nextInt()); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.ThreadInformation.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.ThreadInformation.FIELD_DEAMON_THREAD_COUNT, (Object) Long.valueOf(data.getTotalDaemonThreadCount() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.ThreadInformation.FIELD_LIVE_THREAD_COUNT, (Object) Long.valueOf(data.getTotalThreadCount() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.ThreadInformation.FIELD_PEAK_THREAD_COUNT, (Object) Long.valueOf(data.getTotalPeakThreadCount() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.ThreadInformation.FIELD_TOTAL_STARTED_THREAD_COUNT, (Object) (data.getTotalTotalStartedThreadCount() / data.getCount()))); }
/** * {@inheritDoc} */ @Override protected void addFields(ThreadInformationData data, Builder builder) { int count = data.getCount(); long liveThreadCount = data.getTotalThreadCount() / count; long daemonThreadCount = data.getTotalDaemonThreadCount() / count; long totalStartedThreadCount = data.getTotalTotalStartedThreadCount() / count; long peakThreadCount = data.getTotalPeakThreadCount() / count; // fields builder.addField(Series.ThreadInformation.FIELD_LIVE_THREAD_COUNT, liveThreadCount); builder.addField(Series.ThreadInformation.FIELD_DEAMON_THREAD_COUNT, daemonThreadCount); builder.addField(Series.ThreadInformation.FIELD_TOTAL_STARTED_THREAD_COUNT, totalStartedThreadCount); builder.addField(Series.ThreadInformation.FIELD_PEAK_THREAD_COUNT, peakThreadCount); }
assertThat(threadInformationData.getMaxThreadCount(), is(12)); assertThat(threadInformationData.getTotalTotalStartedThreadCount(), is(13L)); assertThat(threadInformationData.getMinTotalStartedThreadCount(), is(14L)); assertThat(threadInformationData.getMaxTotalStartedThreadCount(), is(15L));
assertThat(threadInformationData.getMaxThreadCount(), is(0)); assertThat(threadInformationData.getTotalTotalStartedThreadCount(), is(0L)); assertThat(threadInformationData.getMinTotalStartedThreadCount(), is(Long.MAX_VALUE)); assertThat(threadInformationData.getMaxTotalStartedThreadCount(), is(0L));
/** * {@inheritDoc} */ @Override public SystemSensorData get() { ThreadInformationData newThreadInformationData = new ThreadInformationData(); newThreadInformationData.setPlatformIdent(this.threadInformationData.getPlatformIdent()); newThreadInformationData.setSensorTypeIdent(this.threadInformationData.getSensorTypeIdent()); newThreadInformationData.setCount(this.threadInformationData.getCount()); newThreadInformationData.setTotalDaemonThreadCount(this.threadInformationData.getTotalDaemonThreadCount()); newThreadInformationData.setMinDaemonThreadCount(this.threadInformationData.getMinDaemonThreadCount()); newThreadInformationData.setMaxDaemonThreadCount(this.threadInformationData.getMaxDaemonThreadCount()); newThreadInformationData.setTotalPeakThreadCount(this.threadInformationData.getTotalPeakThreadCount()); newThreadInformationData.setMinPeakThreadCount(this.threadInformationData.getMinPeakThreadCount()); newThreadInformationData.setMaxPeakThreadCount(this.threadInformationData.getMaxPeakThreadCount()); newThreadInformationData.setTotalThreadCount(this.threadInformationData.getTotalThreadCount()); newThreadInformationData.setMinThreadCount(this.threadInformationData.getMinThreadCount()); newThreadInformationData.setMaxThreadCount(this.threadInformationData.getMaxThreadCount()); newThreadInformationData.setTotalTotalStartedThreadCount(this.threadInformationData.getTotalTotalStartedThreadCount()); newThreadInformationData.setMinTotalStartedThreadCount(this.threadInformationData.getMinTotalStartedThreadCount()); newThreadInformationData.setMaxTotalStartedThreadCount(this.threadInformationData.getMaxTotalStartedThreadCount()); newThreadInformationData.setTimeStamp(this.threadInformationData.getTimeStamp()); return newThreadInformationData; }