Search in sources :

Example 1 with MainWithChildrenRollingFileHandler

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();
}
Also used : NanoTimer(org.apache.geode.internal.NanoTimer) TimeoutException(java.util.concurrent.TimeoutException) Statistics(org.apache.geode.Statistics) StatisticsType(org.apache.geode.StatisticsType) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TestName(org.junit.rules.TestName) After(org.junit.After) Assertions(org.assertj.core.api.Assertions) MainWithChildrenRollingFileHandler(org.apache.geode.internal.io.MainWithChildrenRollingFileHandler) Before(org.junit.Before) StatisticDescriptor(org.apache.geode.StatisticDescriptor) IOException(java.io.IOException) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) List(java.util.List) Rule(org.junit.Rule) TEST_FILE_SIZE_LIMIT_IN_KB_PROPERTY(org.apache.geode.internal.statistics.HostStatSampler.TEST_FILE_SIZE_LIMIT_IN_KB_PROPERTY) ResourceInst(org.apache.geode.internal.statistics.StatArchiveReader.ResourceInst) RestoreSystemProperties(org.junit.contrib.java.lang.system.RestoreSystemProperties) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest) TemporaryFolder(org.junit.rules.TemporaryFolder) MainWithChildrenRollingFileHandler(org.apache.geode.internal.io.MainWithChildrenRollingFileHandler) File(java.io.File) Before(org.junit.Before)

Example 2 with MainWithChildrenRollingFileHandler

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());
}
Also used : MainWithChildrenRollingFileHandler(org.apache.geode.internal.io.MainWithChildrenRollingFileHandler) File(java.io.File) Before(org.junit.Before)

Example 3 with 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();
}
Also used : MainWithChildrenRollingFileHandler(org.apache.geode.internal.io.MainWithChildrenRollingFileHandler) File(java.io.File) Before(org.junit.Before)

Example 4 with 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");
        }
    }
}
Also used : CancelException(org.apache.geode.CancelException) MainWithChildrenRollingFileHandler(org.apache.geode.internal.io.MainWithChildrenRollingFileHandler)

Example 5 with MainWithChildrenRollingFileHandler

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();
}
Also used : Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MainWithChildrenRollingFileHandler(org.apache.geode.internal.io.MainWithChildrenRollingFileHandler) File(java.io.File) Statistics(org.apache.geode.Statistics) Before(org.junit.Before)

Aggregations

MainWithChildrenRollingFileHandler (org.apache.geode.internal.io.MainWithChildrenRollingFileHandler)9 File (java.io.File)8 Before (org.junit.Before)5 Statistics (org.apache.geode.Statistics)4 StatisticsType (org.apache.geode.StatisticsType)3 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 StatisticDescriptor (org.apache.geode.StatisticDescriptor)2 Expectations (org.jmock.Expectations)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 CancelException (org.apache.geode.CancelException)1 NanoTimer (org.apache.geode.internal.NanoTimer)1 RollingFileHandler (org.apache.geode.internal.io.RollingFileHandler)1