Search in sources :

Example 1 with GemFireHealthConfig

use of org.apache.geode.admin.GemFireHealthConfig in project geode by apache.

the class MemberHealthEvaluatorJUnitTest method testCheckVMProcessSize.

/**
   * Tests that we are in {@link GemFireHealth#OKAY_HEALTH okay} health if the VM's process size is
   * too big.
   *
   * @see MemberHealthEvaluator#checkVMProcessSize
   */
@Test
public void testCheckVMProcessSize() throws InterruptedException {
    if (PureJavaMode.osStatsAreAvailable()) {
        GemFireStatSampler sampler = system.getStatSampler();
        assertNotNull(sampler);
        // fix: remove infinite wait
        sampler.waitForInitialization(10000);
        ProcessStats stats = sampler.getProcessStats();
        assertNotNull(stats);
        List status = new ArrayList();
        long threshold = stats.getProcessSize() * 2;
        if (threshold <= 0) {
            // The process size is zero on some Linux versions
            return;
        }
        GemFireHealthConfig config = new GemFireHealthConfigImpl(null);
        config.setMaxVMProcessSize(threshold);
        MemberHealthEvaluator eval = new MemberHealthEvaluator(config, this.system.getDistributionManager());
        eval.evaluate(status);
        assertTrue(status.isEmpty());
        status = new ArrayList();
        long processSize = stats.getProcessSize();
        threshold = processSize / 2;
        assertTrue("Threshold (" + threshold + ") is > 0.  " + "Process size is " + processSize, threshold > 0);
        config = new GemFireHealthConfigImpl(null);
        config.setMaxVMProcessSize(threshold);
        eval = new MemberHealthEvaluator(config, this.system.getDistributionManager());
        eval.evaluate(status);
        assertEquals(1, status.size());
        AbstractHealthEvaluator.HealthStatus ill = (AbstractHealthEvaluator.HealthStatus) status.get(0);
        assertEquals(GemFireHealth.OKAY_HEALTH, ill.getHealthCode());
        assertTrue(ill.getDiagnosis().indexOf("The size of this VM") != -1);
    }
}
Also used : GemFireStatSampler(org.apache.geode.internal.statistics.GemFireStatSampler) GemFireHealthConfig(org.apache.geode.admin.GemFireHealthConfig) ProcessStats(org.apache.geode.internal.statistics.platform.ProcessStats) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with GemFireHealthConfig

use of org.apache.geode.admin.GemFireHealthConfig in project geode by apache.

the class GemFireHealthJmxImpl method manageGemFireHealthConfig.

public ObjectName manageGemFireHealthConfig(String hostName) throws MalformedObjectNameException {
    try {
        GemFireHealthConfig config = getGemFireHealthConfig(hostName);
        GemFireHealthConfigJmxImpl jmx = (GemFireHealthConfigJmxImpl) config;
        return new ObjectName(jmx.getMBeanName());
    }// catch (AdminException e) { logWriter.warning(e); throw e; }
     catch (RuntimeException e) {
        logger.warn(e.getMessage(), e);
        throw e;
    } catch (VirtualMachineError err) {
        SystemFailure.initiateFailure(err);
        // now, so don't let this thread continue.
        throw err;
    } catch (Error e) {
        // 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.error(e.getMessage(), e);
        throw e;
    }
}
Also used : GemFireHealthConfig(org.apache.geode.admin.GemFireHealthConfig) ObjectName(javax.management.ObjectName)

Aggregations

GemFireHealthConfig (org.apache.geode.admin.GemFireHealthConfig)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ObjectName (javax.management.ObjectName)1 GemFireStatSampler (org.apache.geode.internal.statistics.GemFireStatSampler)1 ProcessStats (org.apache.geode.internal.statistics.platform.ProcessStats)1 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)1 Test (org.junit.Test)1