< prev index next >

application/tests/org.openjdk.jmc.rjmx.test/src/test/java/org/openjdk/jmc/rjmx/test/synthetic/SyntheticAttributesTest.java

Print this page

        

*** 59,113 **** import org.openjdk.jmc.rjmx.subscription.MRI.Type; import org.openjdk.jmc.rjmx.subscription.internal.AttributeValueToolkit; import org.openjdk.jmc.rjmx.test.ServerHandleTestCase; public class SyntheticAttributesTest extends ServerHandleTestCase { ! private final static String NEW_VALUE = "new value"; //$NON-NLS-1$ protected IConnectionHandle localConnection; @Test public void testLookupDomain() throws Exception { ! assertTrue("Could not find the test domain!", containsDomain("org.openjdk.jmc.test")); //$NON-NLS-1$ //$NON-NLS-2$ } @Test public void testFindNonSyntheticDomain() throws Exception { ! assertTrue("Could not find the java.lang domain!", containsDomain("java.lang")); //$NON-NLS-1$ //$NON-NLS-2$ } @Test public void testFindMBean() throws Exception { ObjectName mbean = getSyntheticAttributeDescriptor().getObjectName(); ! assertTrue("Could not find the test mbean!", containsMBean(mbean)); //$NON-NLS-1$ } @Test public void testFindNonSyntheticMBean() throws Exception { ! ObjectName mbean = new ObjectName("java.lang:type=Runtime"); //$NON-NLS-1$ ! assertTrue("Could not find the Runtime mbean!", containsMBean(mbean)); //$NON-NLS-1$ } @Test public void testGetAttribute() throws Exception { MRI descriptor = getSyntheticAttributeDescriptor(); Object value = getAttributeValue(descriptor); ! assertNotNull("Could not retrieve the attribute value", value); //$NON-NLS-1$ } @Test public void testGetCompositeAttribute() throws Exception { MRI descriptor = getCompositeAttributeDescriptor(); Object value = getAttributeValue(descriptor); ! assertNotNull("Could not retrieve the attribute value", value); //$NON-NLS-1$ } @Test public void testGetAttributes() throws Exception { MRI descriptor = getSyntheticAttributeDescriptor(); AttributeList list = getAttributeValues(descriptor.getObjectName(), new String[] {descriptor.getDataPath()}); Object value = list.get(0); ! assertNotNull("Could not retrieve the attribute value", value); //$NON-NLS-1$ } @Test public void testGetCompositeAttributes() throws Exception { MRI[] descriptors = getCombinedAttributeDescriptors(); --- 59,113 ---- import org.openjdk.jmc.rjmx.subscription.MRI.Type; import org.openjdk.jmc.rjmx.subscription.internal.AttributeValueToolkit; import org.openjdk.jmc.rjmx.test.ServerHandleTestCase; public class SyntheticAttributesTest extends ServerHandleTestCase { ! private final static String NEW_VALUE = "new value"; protected IConnectionHandle localConnection; @Test public void testLookupDomain() throws Exception { ! assertTrue("Could not find the test domain!", containsDomain("org.openjdk.jmc.test")); } @Test public void testFindNonSyntheticDomain() throws Exception { ! assertTrue("Could not find the java.lang domain!", containsDomain("java.lang")); } @Test public void testFindMBean() throws Exception { ObjectName mbean = getSyntheticAttributeDescriptor().getObjectName(); ! assertTrue("Could not find the test mbean!", containsMBean(mbean)); } @Test public void testFindNonSyntheticMBean() throws Exception { ! ObjectName mbean = new ObjectName("java.lang:type=Runtime"); ! assertTrue("Could not find the Runtime mbean!", containsMBean(mbean)); } @Test public void testGetAttribute() throws Exception { MRI descriptor = getSyntheticAttributeDescriptor(); Object value = getAttributeValue(descriptor); ! assertNotNull("Could not retrieve the attribute value", value); } @Test public void testGetCompositeAttribute() throws Exception { MRI descriptor = getCompositeAttributeDescriptor(); Object value = getAttributeValue(descriptor); ! assertNotNull("Could not retrieve the attribute value", value); } @Test public void testGetAttributes() throws Exception { MRI descriptor = getSyntheticAttributeDescriptor(); AttributeList list = getAttributeValues(descriptor.getObjectName(), new String[] {descriptor.getDataPath()}); Object value = list.get(0); ! assertNotNull("Could not retrieve the attribute value", value); } @Test public void testGetCompositeAttributes() throws Exception { MRI[] descriptors = getCombinedAttributeDescriptors();
*** 115,125 **** List<String> names = new ArrayList<>(); for (MRI ad : descriptors) { names.add(ad.getDataPath()); } AttributeList list = getAttributeValues(objectName, names.toArray(new String[descriptors.length])); ! assertEquals("Could not retrieve all values", descriptors.length, list.size()); //$NON-NLS-1$ } @Test public void testGetCompositeAttributesThroughMBeanHelperService() throws Exception { MRI[] descriptors = getCombinedAttributeDescriptors(); --- 115,125 ---- List<String> names = new ArrayList<>(); for (MRI ad : descriptors) { names.add(ad.getDataPath()); } AttributeList list = getAttributeValues(objectName, names.toArray(new String[descriptors.length])); ! assertEquals("Could not retrieve all values", descriptors.length, list.size()); } @Test public void testGetCompositeAttributesThroughMBeanHelperService() throws Exception { MRI[] descriptors = getCombinedAttributeDescriptors();
*** 127,192 **** List<String> names = new ArrayList<>(); for (MRI ad : descriptors) { names.add(ad.getDataPath()); } Collection<Object> list = getAttributeValuesThroughMBeanHelperService(objectName, names); ! assertEquals("Could not retrieve all values", descriptors.length, list.size()); //$NON-NLS-1$ } @Test public void testGetMultipleAttributes() throws Exception { MRI syntheticDescriptor = getExtendedSyntheticAttributeDescriptor(); MRI nonsyntheticDescriptor = getNonSyntheticDescriptor(); ObjectName mbean = syntheticDescriptor.getObjectName(); ! assertTrue("Not same MBean", mbean.equals(nonsyntheticDescriptor.getObjectName())); //$NON-NLS-1$ String[] attributes = new String[] {nonsyntheticDescriptor.getDataPath(), syntheticDescriptor.getDataPath()}; AttributeList values = getAttributeValues(mbean, attributes); ! assertTrue("Not two values", values.size() == 2); //$NON-NLS-1$ for (Object attribute : values) { assertNotNull(((Attribute) attribute).getValue()); } } @Test public void testGetExtendedAttribute() throws Exception { MRI descriptor = getExtendedSyntheticAttributeDescriptor(); Object value = getAttributeValue(descriptor); ! assertNotNull("Could not retrieve the extended attribute value", value); //$NON-NLS-1$ } @Test public void testSetExtendedAttribute() throws Exception { MRI descriptor = getExtendedSyntheticAttributeDescriptor(); String newValue = NEW_VALUE; String oldValue = (String) getAttributeValue(descriptor); setAttributeValue(descriptor, newValue); ! assertEquals("Could not set the attribute value!", NEW_VALUE, getAttributeValue(descriptor)); //$NON-NLS-1$ setAttributeValue(descriptor, oldValue); ! assertEquals("Could not restore old attribute value!", oldValue, getAttributeValue(descriptor)); //$NON-NLS-1$ } @Test public void testSetAttribute() throws Exception { MRI descriptor = getSyntheticAttributeDescriptor(); String newValue = NEW_VALUE; String oldValue = (String) getAttributeValue(descriptor); setAttributeValue(descriptor, newValue); ! assertEquals("Could not set the attribute value!", NEW_VALUE, getAttributeValue(descriptor)); //$NON-NLS-1$ setAttributeValue(descriptor, oldValue); ! assertEquals("Could not restore old attribute value!", oldValue, getAttributeValue(descriptor)); //$NON-NLS-1$ } @Test public void testGetProperties() throws Exception { @SuppressWarnings("unchecked") Map<String, Object> values = (Map<String, Object>) getAttributeValue( getPropertiesSyntheticAttributeDescriptor()); ! assertEquals("Gegga", values.get("denominator")); //$NON-NLS-1$ //$NON-NLS-2$ ! assertEquals("Moja", values.get("numerator")); //$NON-NLS-1$ //$NON-NLS-2$ ! assertEquals(100, values.get("someinteger")); //$NON-NLS-1$ ! assertEquals(0.01f, values.get("factor")); //$NON-NLS-1$ ! assertEquals(true, values.get("someboolean")); //$NON-NLS-1$ } @Test public void testGetNonSyntheticAttribute() throws Exception { MRI descriptor = getNonSyntheticDescriptor(); --- 127,192 ---- List<String> names = new ArrayList<>(); for (MRI ad : descriptors) { names.add(ad.getDataPath()); } Collection<Object> list = getAttributeValuesThroughMBeanHelperService(objectName, names); ! assertEquals("Could not retrieve all values", descriptors.length, list.size()); } @Test public void testGetMultipleAttributes() throws Exception { MRI syntheticDescriptor = getExtendedSyntheticAttributeDescriptor(); MRI nonsyntheticDescriptor = getNonSyntheticDescriptor(); ObjectName mbean = syntheticDescriptor.getObjectName(); ! assertTrue("Not same MBean", mbean.equals(nonsyntheticDescriptor.getObjectName())); String[] attributes = new String[] {nonsyntheticDescriptor.getDataPath(), syntheticDescriptor.getDataPath()}; AttributeList values = getAttributeValues(mbean, attributes); ! assertTrue("Not two values", values.size() == 2); for (Object attribute : values) { assertNotNull(((Attribute) attribute).getValue()); } } @Test public void testGetExtendedAttribute() throws Exception { MRI descriptor = getExtendedSyntheticAttributeDescriptor(); Object value = getAttributeValue(descriptor); ! assertNotNull("Could not retrieve the extended attribute value", value); } @Test public void testSetExtendedAttribute() throws Exception { MRI descriptor = getExtendedSyntheticAttributeDescriptor(); String newValue = NEW_VALUE; String oldValue = (String) getAttributeValue(descriptor); setAttributeValue(descriptor, newValue); ! assertEquals("Could not set the attribute value!", NEW_VALUE, getAttributeValue(descriptor)); setAttributeValue(descriptor, oldValue); ! assertEquals("Could not restore old attribute value!", oldValue, getAttributeValue(descriptor)); } @Test public void testSetAttribute() throws Exception { MRI descriptor = getSyntheticAttributeDescriptor(); String newValue = NEW_VALUE; String oldValue = (String) getAttributeValue(descriptor); setAttributeValue(descriptor, newValue); ! assertEquals("Could not set the attribute value!", NEW_VALUE, getAttributeValue(descriptor)); setAttributeValue(descriptor, oldValue); ! assertEquals("Could not restore old attribute value!", oldValue, getAttributeValue(descriptor)); } @Test public void testGetProperties() throws Exception { @SuppressWarnings("unchecked") Map<String, Object> values = (Map<String, Object>) getAttributeValue( getPropertiesSyntheticAttributeDescriptor()); ! assertEquals("Gegga", values.get("denominator")); ! assertEquals("Moja", values.get("numerator")); ! assertEquals(100, values.get("someinteger")); ! assertEquals(0.01f, values.get("factor")); ! assertEquals(true, values.get("someboolean")); } @Test public void testGetNonSyntheticAttribute() throws Exception { MRI descriptor = getNonSyntheticDescriptor();
*** 215,229 **** Boolean value = (Boolean) getAttributeValue(normalDescriptor); assertNotNull(value); setAttributeValues(new MRI[] {synthethicDescriptor, normalDescriptor}, new Object[] {newValue, Boolean.valueOf(!value.booleanValue())}); ! assertEquals("Could not set the attribute value!", NEW_VALUE, getAttributeValue(synthethicDescriptor)); //$NON-NLS-1$ assertNotSame(value, getAttributeValue(normalDescriptor)); setAttributeValues(new MRI[] {synthethicDescriptor, normalDescriptor}, new Object[] {oldValue, value}); ! assertEquals("Could not restore old attribute value!", oldValue, getAttributeValue(synthethicDescriptor)); //$NON-NLS-1$ assertEquals(value, getAttributeValue(normalDescriptor)); } @Test --- 215,229 ---- Boolean value = (Boolean) getAttributeValue(normalDescriptor); assertNotNull(value); setAttributeValues(new MRI[] {synthethicDescriptor, normalDescriptor}, new Object[] {newValue, Boolean.valueOf(!value.booleanValue())}); ! assertEquals("Could not set the attribute value!", NEW_VALUE, getAttributeValue(synthethicDescriptor)); assertNotSame(value, getAttributeValue(normalDescriptor)); setAttributeValues(new MRI[] {synthethicDescriptor, normalDescriptor}, new Object[] {oldValue, value}); ! assertEquals("Could not restore old attribute value!", oldValue, getAttributeValue(synthethicDescriptor)); assertEquals(value, getAttributeValue(normalDescriptor)); } @Test
*** 233,250 **** assertEquals(2, info.getAttributes().length); MBeanAttributeInfo attributeInfo = findCorresponding(info.getAttributes(), descriptor); assertTrue(attributeInfo.isReadable()); assertTrue(attributeInfo.isWritable()); assertFalse(attributeInfo.isIs()); ! assertEquals("java.lang.String", attributeInfo.getType()); //$NON-NLS-1$ } @Test public void testExtendedMetadata() throws Exception { MRI descriptor = getExtendedSyntheticAttributeDescriptor(); MBeanInfo info = getMetadata(descriptor); ! assertTrue(info.getDescription().contains("Extended")); //$NON-NLS-1$ MBeanAttributeInfo extendedInfo = null; for (MBeanAttributeInfo attr : info.getAttributes()) { if (attr.getName().equals(descriptor.getDataPath())) { extendedInfo = attr; --- 233,250 ---- assertEquals(2, info.getAttributes().length); MBeanAttributeInfo attributeInfo = findCorresponding(info.getAttributes(), descriptor); assertTrue(attributeInfo.isReadable()); assertTrue(attributeInfo.isWritable()); assertFalse(attributeInfo.isIs()); ! assertEquals("java.lang.String", attributeInfo.getType()); } @Test public void testExtendedMetadata() throws Exception { MRI descriptor = getExtendedSyntheticAttributeDescriptor(); MBeanInfo info = getMetadata(descriptor); ! assertTrue(info.getDescription().contains("Extended")); MBeanAttributeInfo extendedInfo = null; for (MBeanAttributeInfo attr : info.getAttributes()) { if (attr.getName().equals(descriptor.getDataPath())) { extendedInfo = attr;
*** 253,263 **** assertNotNull(extendedInfo); MBeanAttributeInfo attributeInfo = findCorresponding(info.getAttributes(), descriptor); assertTrue(attributeInfo.isReadable()); assertTrue(attributeInfo.isWritable()); assertFalse(attributeInfo.isIs()); ! assertEquals("java.lang.String", attributeInfo.getType()); //$NON-NLS-1$ } private MBeanAttributeInfo findCorresponding(MBeanAttributeInfo[] attributes, MRI descriptor) { for (MBeanAttributeInfo info : attributes) { if (descriptor.getDataPath().equals(info.getName())) { --- 253,263 ---- assertNotNull(extendedInfo); MBeanAttributeInfo attributeInfo = findCorresponding(info.getAttributes(), descriptor); assertTrue(attributeInfo.isReadable()); assertTrue(attributeInfo.isWritable()); assertFalse(attributeInfo.isIs()); ! assertEquals("java.lang.String", attributeInfo.getType()); } private MBeanAttributeInfo findCorresponding(MBeanAttributeInfo[] attributes, MRI descriptor) { for (MBeanAttributeInfo info : attributes) { if (descriptor.getDataPath().equals(info.getName())) {
*** 266,305 **** } return null; } private MRI getPropertiesSyntheticAttributeDescriptor() { ! return MRI.createFromQualifiedName("attribute://org.openjdk.jmc.test:type=Test/Properties"); //$NON-NLS-1$ } private boolean containsMBean(ObjectName mbean) throws Exception { MBeanServerConnection connection = getLocalConnection().getServiceOrThrow(MBeanServerConnection.class); @SuppressWarnings("rawtypes") Set mbeans = connection.queryMBeans(mbean, null); return mbeans.size() > 0; } private MRI getSyntheticAttributeDescriptor() { ! return MRI.createFromQualifiedName("attribute://org.openjdk.jmc.test:type=Test/Test"); //$NON-NLS-1$ } private MRI getExtendedSyntheticAttributeDescriptor() { ! return MRI.createFromQualifiedName("attribute://java.lang:type=ClassLoading/Test"); //$NON-NLS-1$ } private MRI getNonSyntheticDescriptor() { ! return MRI.createFromQualifiedName("attribute://java.lang:type=ClassLoading/Verbose"); //$NON-NLS-1$ } private MRI getCompositeAttributeDescriptor() { ! return MRI.createFromQualifiedName("attribute://java.lang:type=OperatingSystem/TotalPhysicalMemorySize"); //$NON-NLS-1$ } private MRI[] getCombinedAttributeDescriptors() { ! return new MRI[] {MRI.createFromQualifiedName("attribute://java.lang:type=Memory/HeapMemoryUsage/used"), //$NON-NLS-1$ ! MRI.createFromQualifiedName("attribute://java.lang:type=Memory/NonHeapMemoryUsage/max"), //$NON-NLS-1$ ! MRI.createFromQualifiedName("attribute://java.lang:type=Memory/Verbose")}; //$NON-NLS-1$ } private boolean containsDomain(String checkDomain) throws Exception { MBeanServerConnection connection = getLocalConnection().getServiceOrThrow(MBeanServerConnection.class); boolean containsDomain = false; --- 266,305 ---- } return null; } private MRI getPropertiesSyntheticAttributeDescriptor() { ! return MRI.createFromQualifiedName("attribute://org.openjdk.jmc.test:type=Test/Properties"); } private boolean containsMBean(ObjectName mbean) throws Exception { MBeanServerConnection connection = getLocalConnection().getServiceOrThrow(MBeanServerConnection.class); @SuppressWarnings("rawtypes") Set mbeans = connection.queryMBeans(mbean, null); return mbeans.size() > 0; } private MRI getSyntheticAttributeDescriptor() { ! return MRI.createFromQualifiedName("attribute://org.openjdk.jmc.test:type=Test/Test"); } private MRI getExtendedSyntheticAttributeDescriptor() { ! return MRI.createFromQualifiedName("attribute://java.lang:type=ClassLoading/Test"); } private MRI getNonSyntheticDescriptor() { ! return MRI.createFromQualifiedName("attribute://java.lang:type=ClassLoading/Verbose"); } private MRI getCompositeAttributeDescriptor() { ! return MRI.createFromQualifiedName("attribute://java.lang:type=OperatingSystem/TotalPhysicalMemorySize"); } private MRI[] getCombinedAttributeDescriptors() { ! return new MRI[] {MRI.createFromQualifiedName("attribute://java.lang:type=Memory/HeapMemoryUsage/used"), ! MRI.createFromQualifiedName("attribute://java.lang:type=Memory/NonHeapMemoryUsage/max"), ! MRI.createFromQualifiedName("attribute://java.lang:type=Memory/Verbose")}; } private boolean containsDomain(String checkDomain) throws Exception { MBeanServerConnection connection = getLocalConnection().getServiceOrThrow(MBeanServerConnection.class); boolean containsDomain = false;
*** 358,368 **** @Override @Before public void setUp() throws Exception { super.setUp(); ! localConnection = getDefaultServer().connect("Test"); //$NON-NLS-1$ } @Override public void tearDown() throws Exception { localConnection.close(); --- 358,368 ---- @Override @Before public void setUp() throws Exception { super.setUp(); ! localConnection = getDefaultServer().connect("Test"); } @Override public void tearDown() throws Exception { localConnection.close();
< prev index next >