Search in sources :

Example 36 with InvalidAttributeValueException

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

the class MyTestListener method testSetAttribute.

@Test
public final void testSetAttribute() {
    // The only writable attribute of this type of bean
    Attribute attr = null;
    try {
        attr = new Attribute("Verbose", new Boolean(true));
        mbs.setAttribute(objName, attr);
    } catch (AttributeNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected AttributeNotFoundException " + e.getMessage());
    } catch (InvalidAttributeValueException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InvalidAttributeValueException occurred (Verbose): " + e.getMessage());
    } catch (MBeanException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected MBeanException occurred (Verbose): " + e.getCause().getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException occurred (Verbose): " + e.getCause().getMessage());
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred (Verbose): " + e.getMessage());
    }
    // Now check that the other, readonly attributes can't be set.
    MemoryUsage mu = new MemoryUsage(1, 2, 3, 4);
    CompositeData cd = TestUtil.toCompositeData(mu);
    attr = new Attribute("HeapMemoryUsage", cd);
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception.");
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred (HeapMemoryUsage): " + e.getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException occurred (HeapMemoryUsage): " + e.getMessage());
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
        logger.debug("Exception occurred, as expected: " + e1.getMessage());
    }
    attr = new Attribute("NonHeapMemoryUsage", cd);
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception.");
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred (NonHeapMemoryUsage): " + e.getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException occurred (NonHeapMemoryUsage): " + e.getMessage());
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
        logger.debug("Exception occurred, as expected: " + e1.getMessage());
    }
    attr = new Attribute("ObjectPendingFinalizationCount", new Long(38));
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception.");
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred (ObjectPendingFinalizationCount): " + e.getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException occurred (ObjectPendingFinalizationCount): " + e.getMessage());
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
        logger.debug("Exception occurred, as expected: " + e1.getMessage());
    }
    // Try and set the Verbose attribute with an incorrect type.
    attr = new Attribute("Verbose", new Long(42));
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception.");
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred (Verbose): " + e.getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException occurred (Verbose): " + e.getMessage());
    } catch (Exception e2) {
        AssertJUnit.assertTrue(e2 instanceof javax.management.InvalidAttributeValueException);
        logger.debug("Exception occurred, as expected: " + e2.getMessage());
    }
    // set Verbose back to false
    try {
        attr = new Attribute("Verbose", new Boolean(false));
        mbs.setAttribute(objName, attr);
    } catch (AttributeNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected AttributeNotFoundException " + e.getMessage());
    } catch (InvalidAttributeValueException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InvalidAttributeValueException occurred (Verbose): " + e.getMessage());
    } catch (MBeanException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected MBeanException occurred (Verbose): " + e.getCause().getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException occurred (Verbose): " + e.getCause().getMessage());
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred (Verbose): " + e.getMessage());
    }
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) InstanceNotFoundException(javax.management.InstanceNotFoundException) CompositeData(javax.management.openmbean.CompositeData) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MemoryUsage(java.lang.management.MemoryUsage) AttributeNotFoundException(javax.management.AttributeNotFoundException) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ListenerNotFoundException(javax.management.ListenerNotFoundException) Test(org.testng.annotations.Test)

Example 37 with InvalidAttributeValueException

use of javax.management.InvalidAttributeValueException 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", new Long(newCUT));
            mbs.setAttribute(objName, newCUTAttr);
            AssertJUnit.assertEquals(new Long(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", new Long(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)

Example 38 with InvalidAttributeValueException

use of javax.management.InvalidAttributeValueException 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", new Boolean(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", new Boolean(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", new Long(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 39 with InvalidAttributeValueException

use of javax.management.InvalidAttributeValueException in project Payara by payara.

the class AbstractDynamicMBeanImpl method setAttributes.

public final AttributeList setAttributes(AttributeList attributes) {
    AttributeList r = new AttributeList(attributes.size());
    for (Object a : attributes) {
        try {
            setAttribute(Attribute.class.cast(a));
            r.add(Attribute.class.cast(a));
        } catch (AttributeNotFoundException e) {
        // error is silently ignored
        } catch (ReflectionException e) {
        // error is silently ignored
        } catch (MBeanException e) {
        // error is silently ignored
        } catch (InvalidAttributeValueException e) {
        // error is silently ignored
        }
    }
    return r;
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException)

Aggregations

InvalidAttributeValueException (javax.management.InvalidAttributeValueException)39 AttributeNotFoundException (javax.management.AttributeNotFoundException)26 ReflectionException (javax.management.ReflectionException)24 MBeanException (javax.management.MBeanException)23 Attribute (javax.management.Attribute)19 InstanceNotFoundException (javax.management.InstanceNotFoundException)13 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 RuntimeOperationsException (javax.management.RuntimeOperationsException)8 AttributeList (javax.management.AttributeList)6 IntrospectionException (javax.management.IntrospectionException)6 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)6 Test (org.testng.annotations.Test)6 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 Method (java.lang.reflect.Method)5 URI (java.net.URI)5 ListenerNotFoundException (javax.management.ListenerNotFoundException)5 RuntimeErrorException (javax.management.RuntimeErrorException)5 Consumes (javax.ws.rs.Consumes)5 DefaultValue (javax.ws.rs.DefaultValue)5 HeaderParam (javax.ws.rs.HeaderParam)5