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);
}
}
}
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
}
Aggregations