use of org.apache.geode.internal.io.MainWithChildrenRollingFileHandler in project geode by apache.
the class StatTypesAreRolledOverRegressionTest method setUp.
@Before
public void setUp() throws Exception {
this.dir = this.temporaryFolder.getRoot();
this.archiveFileName = new File(this.dir, this.testName.getMethodName() + ".gfs").getAbsolutePath();
this.factory = new LocalStatisticsFactory(null);
this.statisticDescriptors = new StatisticDescriptor[] { this.factory.createIntCounter("stat1", "description of stat1", "units", true) };
this.statisticsType = factory.createType("statisticsType1", "statisticsType1", this.statisticDescriptors);
this.statistics = factory.createAtomicStatistics(this.statisticsType, "statistics1", 1);
Answer<Statistics[]> statisticsAnswer = invocation -> factory.getStatistics();
Answer<Integer> modCountAnswer = invocation -> factory.getStatListModCount();
StatisticsSampler sampler = mock(StatisticsSampler.class);
when(sampler.getStatistics()).thenAnswer(statisticsAnswer);
when(sampler.getStatisticsModCount()).thenAnswer(modCountAnswer);
StatArchiveHandlerConfig config = mock(StatArchiveHandlerConfig.class);
when(config.getArchiveFileName()).thenReturn(new File(this.archiveFileName));
when(config.getArchiveFileSizeLimit()).thenReturn(FILE_SIZE_LIMIT);
when(config.getSystemId()).thenReturn(1L);
when(config.getSystemStartTime()).thenReturn(System.currentTimeMillis());
when(config.getSystemDirectoryPath()).thenReturn(this.temporaryFolder.getRoot().getAbsolutePath());
when(config.getProductDescription()).thenReturn(this.testName.getMethodName());
when(config.getArchiveDiskSpaceLimit()).thenReturn(0L);
this.sampleCollector = new SampleCollector(sampler);
this.sampleCollector.initialize(config, this.timer.getTime(), new MainWithChildrenRollingFileHandler());
this.timer.reset();
this.nanosTimeStamp = this.timer.getLastResetTime() - getNanoRate();
}
use of org.apache.geode.internal.io.MainWithChildrenRollingFileHandler in project geode by apache.
the class SampleCollectorTest method setUp.
@Before
public void setUp() throws Exception {
final long startTime = System.currentTimeMillis();
this.manager = new TestStatisticsManager(1, getClass().getSimpleName(), startTime);
final StatArchiveHandlerConfig mockStatArchiveHandlerConfig = mock(StatArchiveHandlerConfig.class, getClass().getSimpleName() + "$" + StatArchiveHandlerConfig.class.getSimpleName());
when(mockStatArchiveHandlerConfig.getArchiveFileName()).thenReturn(new File(""));
when(mockStatArchiveHandlerConfig.getArchiveFileSizeLimit()).thenReturn(0L);
when(mockStatArchiveHandlerConfig.getArchiveDiskSpaceLimit()).thenReturn(0L);
when(mockStatArchiveHandlerConfig.getSystemId()).thenReturn(0L);
when(mockStatArchiveHandlerConfig.getSystemStartTime()).thenReturn(startTime);
when(mockStatArchiveHandlerConfig.getSystemDirectoryPath()).thenReturn("");
when(mockStatArchiveHandlerConfig.getProductDescription()).thenReturn(getClass().getSimpleName());
final StatisticsSampler sampler = new TestStatisticsSampler(manager);
this.sampleCollector = new SampleCollector(sampler);
this.sampleCollector.initialize(mockStatArchiveHandlerConfig, NanoTimer.getTime(), new MainWithChildrenRollingFileHandler());
}
use of org.apache.geode.internal.io.MainWithChildrenRollingFileHandler in project geode by apache.
the class StatArchiveHandlerIntegrationTest method setUp.
@Before
public void setUp() throws Exception {
this.dir = this.temporaryFolder.getRoot();
this.ext = ".gfs";
this.name = this.testName.getMethodName();
this.archive = new File(this.dir, this.name + this.ext);
this.mockConfig = mock(StatArchiveHandlerConfig.class);
this.mockCollector = mock(SampleCollector.class);
this.rollingFileHandler = new MainWithChildrenRollingFileHandler();
}
use of org.apache.geode.internal.io.MainWithChildrenRollingFileHandler in project geode by apache.
the class HostStatSampler method run.
/**
* This service's main loop
*/
@Override
public void run() {
final boolean isDebugEnabled_STATISTICS = logger.isTraceEnabled(LogMarker.STATISTICS);
if (isDebugEnabled_STATISTICS) {
logger.trace(LogMarker.STATISTICS, "HostStatSampler started");
}
boolean latchCountedDown = false;
try {
initSpecialStats();
this.sampleCollector = new SampleCollector(this);
this.sampleCollector.initialize(this, timer.getTime(), new MainWithChildrenRollingFileHandler());
this.statSamplerInitializedLatch.countDown();
latchCountedDown = true;
timer.reset();
// subtract getNanoRate from lastTS to force a quick initial sample
long nanosLastTimeStamp = timer.getLastResetTime() - getNanoRate();
while (!stopRequested()) {
SystemFailure.checkFailure();
if (Thread.currentThread().isInterrupted()) {
break;
}
final long nanosBeforeSleep = timer.getLastResetTime();
final long nanosToDelay = nanosLastTimeStamp + getNanoRate();
delay(nanosToDelay);
nanosLastTimeStamp = timer.getLastResetTime();
if (!stopRequested() && isSamplingEnabled()) {
final long nanosTimeStamp = timer.getLastResetTime();
final long nanosElapsedSleeping = nanosTimeStamp - nanosBeforeSleep;
checkElapsedSleepTime(nanosElapsedSleeping);
if (stopRequested())
break;
sampleSpecialStats(false);
if (stopRequested())
break;
checkListeners();
if (stopRequested())
break;
this.sampleCollector.sample(nanosTimeStamp);
final long nanosSpentWorking = timer.reset();
accountForTimeSpentWorking(nanosSpentWorking, nanosElapsedSleeping);
} else if (!stopRequested() && !isSamplingEnabled()) {
// fixes bug 42527
sampleSpecialStats(true);
}
}
} catch (InterruptedException ex) {
// Silently exit
} catch (CancelException ex) {
// Silently exit
} catch (RuntimeException ex) {
logger.fatal(LogMarker.STATISTICS, ex.getMessage(), ex);
throw ex;
} catch (VirtualMachineError err) {
SystemFailure.initiateFailure(err);
// now, so don't let this thread continue.
throw err;
} catch (Error ex) {
// Whenever you catch Error or Throwable, you must also
// catch VirtualMachineError (see above). However, there is
// _still_ a possibility that you are dealing with a cascading
// error condition, so you also need to check to see if the JVM
// is still usable:
SystemFailure.checkFailure();
logger.fatal(LogMarker.STATISTICS, ex.getMessage(), ex);
throw ex;
} finally {
try {
closeSpecialStats();
if (this.sampleCollector != null) {
this.sampleCollector.close();
}
} finally {
if (!latchCountedDown) {
// Make sure the latch gets counted down since
// other threads wait for this to indicate that
// the sampler is initialized.
this.statSamplerInitializedLatch.countDown();
}
}
if (isDebugEnabled_STATISTICS) {
logger.trace(LogMarker.STATISTICS, "HostStatSampler stopped");
}
}
}
use of org.apache.geode.internal.io.MainWithChildrenRollingFileHandler in project geode by apache.
the class FileSizeLimitIntegrationTest method setUp.
@Before
public void setUp() throws Exception {
this.dir = this.temporaryFolder.getRoot();
this.archiveFileName = new File(this.dir, this.testName.getMethodName() + ".gfs").getAbsolutePath();
this.factory = new LocalStatisticsFactory(null);
this.statisticDescriptors = new StatisticDescriptor[] { this.factory.createIntCounter("stat1", "description of stat1", "units", true) };
this.statisticsType = factory.createType("statisticsType1", "statisticsType1", this.statisticDescriptors);
this.statistics = factory.createAtomicStatistics(this.statisticsType, "statistics1", 1);
Answer<Statistics[]> statisticsAnswer = new Answer<Statistics[]>() {
public Statistics[] answer(InvocationOnMock invocation) throws Throwable {
return factory.getStatistics();
}
};
Answer<Integer> modCountAnswer = new Answer<Integer>() {
public Integer answer(InvocationOnMock invocation) throws Throwable {
return factory.getStatListModCount();
}
};
StatisticsSampler sampler = mock(StatisticsSampler.class);
when(sampler.getStatistics()).thenAnswer(statisticsAnswer);
when(sampler.getStatisticsModCount()).thenAnswer(modCountAnswer);
StatArchiveHandlerConfig config = mock(StatArchiveHandlerConfig.class);
when(config.getArchiveFileName()).thenReturn(new File(this.archiveFileName));
when(config.getArchiveFileSizeLimit()).thenReturn(FILE_SIZE_LIMIT);
when(config.getSystemId()).thenReturn(1L);
when(config.getSystemStartTime()).thenReturn(System.currentTimeMillis());
when(config.getSystemDirectoryPath()).thenReturn(this.temporaryFolder.getRoot().getAbsolutePath());
when(config.getProductDescription()).thenReturn(this.testName.getMethodName());
when(config.getArchiveDiskSpaceLimit()).thenReturn(0L);
this.sampleCollector = new SampleCollector(sampler);
this.sampleCollector.initialize(config, this.timer.getTime(), new MainWithChildrenRollingFileHandler());
this.timer.reset();
this.nanosTimeStamp = this.timer.getLastResetTime() - getNanoRate();
}
Aggregations