use of javax.management.AttributeNotFoundException in project spf4j by zolyfarkas.
the class ExportedValuesMBean method setAttribute.
/**
* {@inheritDoc}
*/
@Override
public void setAttribute(final Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
String name = attribute.getName();
ExportedValue<Object> result = (ExportedValue<Object>) exportedValues.get(name);
if (result == null) {
throw new AttributeNotFoundException(name);
}
try {
result.set(attribute.getValue());
} catch (SecurityException ex) {
throw ex;
} catch (InvalidObjectException | RuntimeException ex) {
Logger.getLogger(ExportedValuesMBean.class.getName()).log(Level.SEVERE, "Exception while setting attr: " + attribute, ex);
InvalidAttributeValueException jx = new InvalidAttributeValueException("Invalid value " + attribute);
jx.addSuppressed(ex);
throw jx;
}
}
use of javax.management.AttributeNotFoundException in project openj9 by eclipse.
the class TestLoggingMXBean method testSetAttribute.
@Test
public final void testSetAttribute() {
// The only attribute for this type is not a writable one.
Attribute attr = new Attribute("LoggerLevel", "Boris");
try {
mbs.setAttribute(objName, attr);
Assert.fail("Should have thrown an exception.");
} catch (AttributeNotFoundException | ReflectionException e) {
// One of these exceptions is expected.
} catch (Exception e) {
Assert.fail("Unexpected exception: " + e.getMessage());
}
attr = new Attribute("LoggerNames", new String[] { "Strummer", "Jones" });
try {
mbs.setAttribute(objName, attr);
Assert.fail("Should have thrown an exception.");
} catch (AttributeNotFoundException | ReflectionException e) {
// One of these exceptions is expected.
} catch (Exception e) {
Assert.fail("Unexpected exception: " + e.getMessage());
}
}
use of javax.management.AttributeNotFoundException 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", Boolean.valueOf(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 = MemoryUsageUtil.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", Long.valueOf(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", Long.valueOf(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", Boolean.valueOf(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());
}
}
use of javax.management.AttributeNotFoundException in project openj9 by eclipse.
the class TestCompilationMXBean method testSetAttribute.
/* Test the setAttribute() API. */
@Test
public final void testSetAttribute() {
// Nothing is writable for this type. Try setting values into those readonly attributes ...
Attribute attr = new Attribute("Name", "Boris");
try {
mbs.setAttribute(objName, attr);
Assert.fail("Unreacheable code: should have thrown an exception.");
} catch (Exception e1) {
AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
logger.debug("Exception occurred, as expected: " + "attempting to set a read-only attribute.");
}
attr = new Attribute("TotalCompilationTime", Long.valueOf(65533));
try {
mbs.setAttribute(objName, attr);
Assert.fail("Unreacheable code: should have thrown an exception.");
} catch (Exception e1) {
AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
logger.debug("Exception occurred, as expected: " + "attempting to set a read-only attribute.");
}
attr = new Attribute("CompilationTimeMonitoringSupported", Boolean.valueOf(true));
try {
mbs.setAttribute(objName, attr);
Assert.fail("Unreacheable code: should have thrown an exception.");
} catch (Exception e1) {
AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
logger.debug("Exception occurred, as expected: " + "attempting to set a read-only attribute.");
}
// Try and set the Name attribute with an incorrect type.
attr = new Attribute("Name", Long.valueOf(42));
try {
mbs.setAttribute(objName, attr);
Assert.fail("Unreacheable code: should have thrown an exception");
} catch (InstanceNotFoundException e) {
Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
} catch (Exception e2) {
AssertJUnit.assertTrue(e2 instanceof javax.management.AttributeNotFoundException);
logger.debug("AttributeNotFoundException Exception occurred, as expected: " + e2.getMessage());
}
}
use of javax.management.AttributeNotFoundException in project openj9 by eclipse.
the class AttributeData method testSetAttribute.
@Test
public final void testSetAttribute() {
Attribute attr = null;
try {
// The one writable attribute of ClassLoadingMXBean...
Boolean before = (Boolean) mbs.getAttribute(objName, "Verbose");
// Toggle the boolean state of "isVerbose"
boolean newVal = !before;
attr = new Attribute("Verbose", Boolean.valueOf(newVal));
mbs.setAttribute(objName, attr);
Boolean after = (Boolean) mbs.getAttribute(objName, "Verbose");
assert (newVal == after);
} 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 " + e.getMessage());
} catch (MBeanException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected MBeanException " + e.getCause().getMessage());
} catch (ReflectionException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected ReflectionException " + e.getCause().getMessage());
} catch (InstanceNotFoundException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
}
// Let's try and set some non-writable attributes.
attr = new Attribute("LoadedClassCount", Integer.valueOf(25));
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: " + e.getMessage());
} catch (ReflectionException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected ReflectionException occurred: " + e.getMessage());
} catch (Exception e1) {
AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
logger.debug("Exception occurred, as expected: " + e1.getMessage());
}
attr = new Attribute("TotalLoadedClassCount", Long.valueOf(3300));
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: " + e.getMessage());
} catch (ReflectionException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected ReflectionException occurred: " + e.getMessage());
} catch (Exception e1) {
AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
logger.debug("Exception occurred, as expected: " + e1.getMessage());
}
attr = new Attribute("UnloadedClassCount", Long.valueOf(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: " + e.getMessage());
} catch (ReflectionException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected ReflectionException occurred: " + 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", Long.valueOf(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: " + e.getMessage());
} catch (ReflectionException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected ReflectionException occurred: " + e.getMessage());
} catch (Exception e2) {
AssertJUnit.assertTrue(e2 instanceof javax.management.InvalidAttributeValueException);
logger.debug("Exception occurred, as expected: " + e2.getMessage());
}
}
Aggregations