Search in sources :

Example 76 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project openj9 by eclipse.

the class TestThreadMXBean method testSetAttribute.

@Test
public final void testSetAttribute() {
    // There are only two writable attributes in this type.
    Attribute attr = new Attribute("ThreadContentionMonitoringEnabled", Boolean.valueOf(true));
    if (tb.isThreadContentionMonitoringSupported()) {
        try {
            // TODO : Set - test - Reset, when VM permits
            mbs.setAttribute(objName, attr);
        } catch (Exception e1) {
            if (e1 instanceof MBeanException) {
                Assert.fail("Unexpected exception : " + ((MBeanException) e1).getCause().getMessage());
            } else {
                Assert.fail("Unexpected exception : " + e1.getMessage());
            }
        }
    } else {
        try {
            mbs.setAttribute(objName, attr);
            Assert.fail("Should have thrown exception!");
        } catch (Exception e) {
            AssertJUnit.assertTrue(e instanceof MBeanException);
        }
    }
    attr = new Attribute("ThreadCpuTimeEnabled", Boolean.valueOf(true));
    if (tb.isThreadCpuTimeSupported()) {
        try {
            // TODO : Set - test - Reset, when VM permits
            mbs.setAttribute(objName, attr);
        } catch (Exception e1) {
            logger.error("Unexpected exception.");
            e1.printStackTrace();
        }
    } else {
        try {
            // TODO : Set - test - Reset, when VM permits
            mbs.setAttribute(objName, attr);
        } catch (Exception e) {
            AssertJUnit.assertTrue(e instanceof MBeanException);
        }
    }
    // The rest of the attempted sets should fail
    attr = new Attribute("AllThreadIds", new long[] { 1L, 2L, 3L, 4L });
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Should have thrown an exception.");
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof AttributeNotFoundException);
    }
    attr = new Attribute("CurrentThreadCpuTime", 1415L);
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Should have thrown an exception.");
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof AttributeNotFoundException);
    }
    attr = new Attribute("DaemonThreadCount", 1415);
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Should have thrown an exception.");
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof AttributeNotFoundException);
    }
    attr = new Attribute("PeakThreadCount", 1415);
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Should have thrown an exception.");
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof AttributeNotFoundException);
    }
    attr = new Attribute("ThreadCount", 1415);
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Should have thrown an exception.");
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof AttributeNotFoundException);
    }
    attr = new Attribute("TotalStartedThreadCount", 1415L);
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Should have thrown an exception.");
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof AttributeNotFoundException);
    }
    attr = new Attribute("CurrentThreadCpuTimeSupported", true);
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Should have thrown an exception.");
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof AttributeNotFoundException);
    }
    attr = new Attribute("ThreadContentionMonitoringEnabled", true);
    if (tb.isThreadContentionMonitoringSupported()) {
        try {
            mbs.setAttribute(objName, attr);
        } catch (Exception e) {
            Assert.fail("Should NOT have thrown an exception!");
        }
    } else {
        try {
            mbs.setAttribute(objName, attr);
            Assert.fail("Should have thrown an exception.");
        } catch (Exception e1) {
            if (tb.isThreadContentionMonitoringSupported()) {
                AssertJUnit.assertTrue(e1 instanceof AttributeNotFoundException);
            }
        }
    }
    attr = new Attribute("ThreadContentionMonitoringSupported", true);
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Should have thrown an exception.");
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof AttributeNotFoundException);
    }
    attr = new Attribute("ThreadCpuTimeEnabled", true);
    if (tb.isThreadCpuTimeSupported()) {
        try {
            mbs.setAttribute(objName, attr);
        } catch (Exception e1) {
            Assert.fail("caught unexpected exception.");
        }
    } else {
        try {
            mbs.setAttribute(objName, attr);
            Assert.fail("Should have thrown an exception.");
        } catch (Exception e1) {
            AssertJUnit.assertTrue(e1 instanceof MBeanException);
        }
    }
    attr = new Attribute("ThreadCpuTimeSupported", true);
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Should have thrown an exception.");
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof AttributeNotFoundException);
    }
    // Try and set an attribute with an incorrect type.
    attr = new Attribute("ThreadContentionMonitoringEnabled", Long.valueOf(42));
    if (tb.isThreadContentionMonitoringSupported()) {
        try {
            mbs.setAttribute(objName, attr);
            Assert.fail("Should have thrown an exception");
        } catch (Exception e1) {
            AssertJUnit.assertTrue(e1 instanceof InvalidAttributeValueException);
        }
    }
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) AttributeNotFoundException(javax.management.AttributeNotFoundException) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) Test(org.testng.annotations.Test)

Example 77 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project openj9 by eclipse.

the class TestMemoryPoolMXBean method testSetCollectionUsageThresholdAttribute.

@Test
public void testSetCollectionUsageThresholdAttribute() {
    MemoryPoolMXBean testImpl = testBean;
    if (testImpl.isCollectionUsageThresholdSupported()) {
        try {
            long originalCUT = (Long) mbs.getAttribute(objName, "CollectionUsageThreshold");
            long newCUT = originalCUT + 1024;
            Attribute newCUTAttr = new Attribute("CollectionUsageThreshold", Long.valueOf(newCUT));
            mbs.setAttribute(objName, newCUTAttr);
            AssertJUnit.assertEquals(Long.valueOf(newCUT), (Long) mbs.getAttribute(objName, "CollectionUsageThreshold"));
        } catch (AttributeNotFoundException e) {
            e.printStackTrace();
            Assert.fail("Unexpected AttributeNotFoundException occurred: " + e.getMessage());
        } catch (InstanceNotFoundException e) {
            e.printStackTrace();
            Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
        } catch (MBeanException e) {
            e.printStackTrace();
            Assert.fail("Unexpected MBeanException occurred: " + e.getMessage());
        } catch (ReflectionException e) {
            e.printStackTrace();
            Assert.fail("Unexpected ReflectionException occurred: " + e.getMessage());
        } catch (InvalidAttributeValueException e) {
            e.printStackTrace();
            Assert.fail("Unexpected InvalidAttributeValueException occurred: " + e.getMessage());
        }
    } else {
        try {
            Attribute newCUTAttr = new Attribute("CollectionUsageThreshold", Long.valueOf(100 * 1024));
            mbs.setAttribute(objName, newCUTAttr);
            Assert.fail("Unreacheable code: should have thrown exception!");
        } catch (Exception e) {
            AssertJUnit.assertTrue(e instanceof javax.management.RuntimeMBeanException);
            logger.debug("Exception occurred, as expected: cannot set attribute (CollectionUsageThreshold).");
        }
    }
// end else collection usage threshold is not supported
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) AttributeNotFoundException(javax.management.AttributeNotFoundException) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) Test(org.testng.annotations.Test)

Aggregations

AttributeNotFoundException (javax.management.AttributeNotFoundException)77 ReflectionException (javax.management.ReflectionException)57 MBeanException (javax.management.MBeanException)54 InstanceNotFoundException (javax.management.InstanceNotFoundException)40 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)30 Attribute (javax.management.Attribute)26 ObjectName (javax.management.ObjectName)24 RuntimeOperationsException (javax.management.RuntimeOperationsException)16 IntrospectionException (javax.management.IntrospectionException)13 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)13 AttributeList (javax.management.AttributeList)12 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 Method (java.lang.reflect.Method)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 Test (org.testng.annotations.Test)9 MBeanInfo (javax.management.MBeanInfo)8 ListenerNotFoundException (javax.management.ListenerNotFoundException)7 RuntimeErrorException (javax.management.RuntimeErrorException)7 RuntimeMBeanException (javax.management.RuntimeMBeanException)7 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)7