HostStatSampler implements Runnable, StatisticsSampler, StatArchiveHandlerConfig { protected long getSpecialStatsId() { try { int pid = getStatisticsManager().getPid(); if (pid > 0) { return pid; } } catch (UncheckedPidUnavailableException ignored) { } return getSystemId(); } protected  HostStatSampler(CancelCriterion stopper, StatSamplerStats samplerStats); protected  HostStatSampler(CancelCriterion stopper, StatSamplerStats samplerStats,
      NanoTimer timer); protected  HostStatSampler(CancelCriterion stopper, StatSamplerStats samplerStats,
      LogFile logFile);   HostStatSampler(CancelCriterion stopper, StatSamplerStats samplerStats, NanoTimer timer,
      LogFile logFile); StatSamplerStats getStatSamplerStats(); @Override int getStatisticsModCount(); @Override Statistics[] getStatistics(); @Override long getSystemStartTime(); @Override String getSystemDirectoryPath(); @Override Optional<LogFile> getLogFile(); @Override boolean waitForSample(long timeout); @Override SampleCollector waitForSampleCollector(long timeout); @Override void run(); void start(); void stop(); boolean isAlive(); void waitForInitialization(); boolean waitForInitialization(long ms); boolean awaitInitialization(final long timeout, final TimeUnit unit); void changeArchive(File newFile); VMStatsContract getVMStats(); @Override String toString(); abstract boolean isSamplingEnabled(); SampleCollector getSampleCollector(); static final String TEST_FILE_SIZE_LIMIT_IN_KB_PROPERTY; static final String OS_STATS_DISABLED_PROPERTY; }
@Test public void getSpecialStatsId_returnsSystemId_ifPidSupplierThrows() { when(statisticsManager.getPid()).thenThrow( new UncheckedPidUnavailableException(new PidUnavailableException("Pid not found"))); long theSystemId = 21; hostStatSampler = new TestableHostStatSampler(cancelCriterion, statSamplerStats, timer, logFile, statisticsManager, theSystemId); assertThat(hostStatSampler.getSpecialStatsId()).isEqualTo(theSystemId); }
@Test public void getSpecialStatsId_returnsPidFromPidSupplier_ifValueIsGreaterThanZero() { int thePid = 42; when(statisticsManager.getPid()).thenReturn(thePid); long anySystemId = 2; hostStatSampler = new TestableHostStatSampler(cancelCriterion, statSamplerStats, timer, logFile, statisticsManager, anySystemId); assertThat(hostStatSampler.getSpecialStatsId()).isEqualTo(thePid); }
@Test public void getSpecialStatsId_returnsSystemId_ifValueFromPidSupplierIsZero() { when(statisticsManager.getPid()).thenReturn(0); long theSystemId = 21; hostStatSampler = new TestableHostStatSampler(cancelCriterion, statSamplerStats, timer, logFile, statisticsManager, theSystemId); assertThat(hostStatSampler.getSpecialStatsId()).isEqualTo(theSystemId); }
@Test public void getSpecialStatsId_returnsSystemId_ifValueFromPidSupplierIsLessThanZero() { when(statisticsManager.getPid()).thenReturn(-1); long theSystemId = 21; hostStatSampler = new TestableHostStatSampler(cancelCriterion, statSamplerStats, timer, logFile, statisticsManager, theSystemId); assertThat(hostStatSampler.getSpecialStatsId()).isEqualTo(theSystemId); }