Search in sources :

Example 86 with CompositeData

use of javax.management.openmbean.CompositeData in project aries by apache.

the class FrameworkTest method testStopBundles.

@Test
public void testStopBundles() throws Exception {
    Bundle bundle = Mockito.mock(Bundle.class);
    Mockito.when(context.getBundle(5)).thenReturn(bundle);
    CompositeData data = mbean.stopBundles(new long[] { 5 });
    Mockito.verify(bundle).stop();
    BatchActionResult batch = BatchActionResult.from(data);
    Assert.assertEquals(5, batch.getCompleted()[0]);
    Assert.assertTrue(batch.isSuccess());
    Assert.assertNull(batch.getError());
    Assert.assertNull(batch.getRemainingItems());
    CompositeData data2 = mbean.stopBundles(null);
    BatchActionResult batch2 = BatchActionResult.from(data2);
    Assert.assertNull(batch2.getCompleted());
    Assert.assertFalse(batch2.isSuccess());
    Assert.assertNotNull(batch2.getError());
    Assert.assertNull(batch2.getRemainingItems());
}
Also used : Bundle(org.osgi.framework.Bundle) CompositeData(javax.management.openmbean.CompositeData) BatchActionResult(org.apache.aries.jmx.codec.BatchActionResult) Test(org.junit.Test)

Example 87 with CompositeData

use of javax.management.openmbean.CompositeData in project aries by apache.

the class FrameworkTest method testUpdateBundles.

@Test
public void testUpdateBundles() throws Exception {
    Bundle bundle = Mockito.mock(Bundle.class);
    Mockito.when(context.getBundle(5)).thenReturn(bundle);
    CompositeData data = mbean.updateBundles(new long[] { 5 });
    Mockito.verify(bundle).update();
    BatchActionResult batch = BatchActionResult.from(data);
    Assert.assertEquals(5, batch.getCompleted()[0]);
    Assert.assertTrue(batch.isSuccess());
    Assert.assertNull(batch.getError());
    Assert.assertNull(batch.getRemainingItems());
    CompositeData data2 = mbean.updateBundles(null);
    BatchActionResult batch2 = BatchActionResult.from(data2);
    Assert.assertNull(batch2.getCompleted());
    Assert.assertFalse(batch2.isSuccess());
    Assert.assertNotNull(batch2.getError());
    Assert.assertNull(batch2.getRemainingItems());
    Mockito.reset(bundle);
    CompositeData data3 = mbean.updateBundles(new long[] { 6 });
    Mockito.when(context.getBundle(6)).thenReturn(bundle);
    Mockito.doThrow(new BundleException("")).when(bundle).update();
    BatchActionResult batch3 = BatchActionResult.from(data3);
    Assert.assertEquals(0, batch3.getCompleted().length);
    Assert.assertFalse(batch3.isSuccess());
    Assert.assertNotNull(batch3.getError());
    Assert.assertEquals(6, batch3.getBundleInError());
    Bundle bundle6 = Mockito.mock(Bundle.class);
    Bundle bundle8 = Mockito.mock(Bundle.class);
    Bundle bundle7 = Mockito.mock(Bundle.class);
    Mockito.when(context.getBundle(6)).thenReturn(bundle6);
    Mockito.when(context.getBundle(8)).thenReturn(bundle8);
    Mockito.when(context.getBundle(7)).thenReturn(bundle7);
    Mockito.doThrow(new BundleException("")).when(bundle8).update();
    CompositeData data4 = mbean.updateBundles(new long[] { 6, 8, 7 });
    BatchActionResult batch4 = BatchActionResult.from(data4);
    Mockito.verify(bundle6).update();
    Assert.assertEquals(1, batch4.getCompleted().length);
    // should contain only bundleid 6
    Assert.assertEquals(6, batch4.getCompleted()[0]);
    Assert.assertFalse(batch4.isSuccess());
    Assert.assertNotNull(batch4.getError());
    Assert.assertEquals(8, batch4.getBundleInError());
    Assert.assertEquals(1, batch4.getRemainingItems().length);
    // should contain only bundleid 7
    Assert.assertEquals(7, batch4.getRemainingItems()[0]);
}
Also used : Bundle(org.osgi.framework.Bundle) CompositeData(javax.management.openmbean.CompositeData) BundleException(org.osgi.framework.BundleException) BatchActionResult(org.apache.aries.jmx.codec.BatchActionResult) Test(org.junit.Test)

Example 88 with CompositeData

use of javax.management.openmbean.CompositeData in project aries by apache.

the class ProvisioningService method extractProvisioningDictionary.

@SuppressWarnings("unchecked")
protected Dictionary<String, Object> extractProvisioningDictionary(TabularData info) {
    Dictionary<String, Object> provisioningInfo = new Hashtable<String, Object>();
    if (info != null) {
        Collection<CompositeData> compositeData = (Collection<CompositeData>) info.values();
        for (CompositeData row : compositeData) {
            PropertyData<? extends Class> propertyData = PropertyData.from(row);
            provisioningInfo.put(propertyData.getKey(), propertyData.getValue());
        }
    }
    return provisioningInfo;
}
Also used : Hashtable(java.util.Hashtable) CompositeData(javax.management.openmbean.CompositeData) Collection(java.util.Collection)

Example 89 with CompositeData

use of javax.management.openmbean.CompositeData in project deltaspike by apache.

the class SimpleRegistrationTest method checkMBean.

@Test
public void checkMBean() throws Exception {
    assertEquals(0, myMBean.getCounter());
    myMBean.resetTo(2);
    final ObjectName on = new ObjectName("org.apache.deltaspike:type=MBeans,name=" + MyMBean.class.getName());
    assertTrue(server.isRegistered(on));
    assertEquals(2, server.getAttribute(on, "counter"));
    assertEquals(6, server.invoke(on, "multiply", new Object[] { 3 }, new String[0]));
    myMBean.resetTo(5);
    assertEquals(5, server.getAttribute(on, "counter"));
    assertEquals(20, server.invoke(on, "multiply", new Object[] { 4 }, new String[0]));
    server.setAttribute(on, new Attribute("counter", 10));
    assertEquals(10, myMBean.getCounter());
    final Collection<Notification> notifications = new ArrayList<Notification>();
    server.addNotificationListener(on, new NotificationListener() {

        @Override
        public void handleNotification(final Notification notification, final Object handback) {
            notifications.add(notification);
        }
    }, null, null);
    myMBean.broadcast();
    assertEquals(1, notifications.size());
    assertEquals(10L, notifications.iterator().next().getSequenceNumber());
    MBeanInfo mBeanInfo = server.getMBeanInfo(on);
    Assert.assertNotNull(mBeanInfo);
    MBeanOperationInfo[] operations = mBeanInfo.getOperations();
    Assert.assertNotNull(operations);
    Assert.assertTrue(operations.length > 0);
    Assert.assertTrue("Empty Signature on operation: " + operations[1], operations[1].getSignature().length > 0);
    MBeanParameterInfo parameterInfo = operations[1].getSignature()[0];
    assertEquals("multiplier", parameterInfo.getName());
    assertEquals("the multiplier", parameterInfo.getDescription());
    {
        // table support - through map
        Object table = server.getAttribute(on, "table");
        assertTrue(TabularData.class.isInstance(table));
        final TabularData data = TabularData.class.cast(table);
        assertEquals(1, data.size());
        final CompositeData compositeData = CompositeData.class.cast(data.values().iterator().next());
        assertEquals(2, compositeData.values().size());
        assertEquals("value1", compositeData.get("key1"));
        assertEquals("value2", compositeData.get("key2"));
    }
    {
        // table support - through Table
        Object table = server.getAttribute(on, "table2");
        assertTrue(TabularData.class.isInstance(table));
        final TabularData data = TabularData.class.cast(table);
        assertEquals(2, data.size());
        final Iterator<?> iterator = data.values().iterator();
        {
            final CompositeData compositeData = CompositeData.class.cast(iterator.next());
            assertEquals(3, compositeData.values().size());
            assertEquals("1", compositeData.get("a"));
            assertEquals("2", compositeData.get("b"));
            assertEquals("3", compositeData.get("c"));
        }
        {
            final CompositeData compositeData = CompositeData.class.cast(iterator.next());
            assertEquals(3, compositeData.values().size());
            assertEquals("alpha", compositeData.get("a"));
            assertEquals("beta", compositeData.get("b"));
            assertEquals("gamma", compositeData.get("c"));
        }
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) MBeanOperationInfo(javax.management.MBeanOperationInfo) CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData) Iterator(java.util.Iterator) NotificationListener(javax.management.NotificationListener) MBeanParameterInfo(javax.management.MBeanParameterInfo) Test(org.junit.Test)

Example 90 with CompositeData

use of javax.management.openmbean.CompositeData in project geode by apache.

the class TableConverter method fromNonNullOpenValue.

public Object fromNonNullOpenValue(Object openValue) throws InvalidObjectException {
    final TabularData table = (TabularData) openValue;
    final Collection<CompositeData> rows = (Collection<CompositeData>) table.values();
    final Map<Object, Object> valueMap = sortedMap ? OpenTypeUtil.newSortedMap() : OpenTypeUtil.newMap();
    for (CompositeData row : rows) {
        final Object key = keyConverter.fromOpenValue(row.get("key"));
        final Object value = valueConverter.fromOpenValue(row.get("value"));
        if (valueMap.put(key, value) != null) {
            final String msg = "Duplicate entry in TabularData: key=" + key;
            throw new InvalidObjectException(msg);
        }
    }
    return valueMap;
}
Also used : CompositeData(javax.management.openmbean.CompositeData) Collection(java.util.Collection) InvalidObjectException(java.io.InvalidObjectException) TabularData(javax.management.openmbean.TabularData)

Aggregations

CompositeData (javax.management.openmbean.CompositeData)229 TabularData (javax.management.openmbean.TabularData)91 Test (org.junit.Test)73 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)68 TabularDataSupport (javax.management.openmbean.TabularDataSupport)51 CompositeType (javax.management.openmbean.CompositeType)50 HashMap (java.util.HashMap)31 ArrayList (java.util.ArrayList)27 Map (java.util.Map)27 Bundle (org.osgi.framework.Bundle)24 ObjectName (javax.management.ObjectName)21 OpenDataException (javax.management.openmbean.OpenDataException)18 IOException (java.io.IOException)17 Collection (java.util.Collection)16 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)16 AuditEvent (org.nhindirect.common.audit.AuditEvent)15 TabularType (javax.management.openmbean.TabularType)13 MBeanServer (javax.management.MBeanServer)12 DefaultAuditContext (org.nhindirect.common.audit.DefaultAuditContext)11 MBeanException (javax.management.MBeanException)8