@Test public void multipleMBeansOneMetricEach() throws MalformedObjectNameException, IntrospectionException, ReflectionException, AttributeNotFoundException, MBeanException, InstanceNotFoundException { ObjectName mBeanName1 = new ObjectName("domain1", "key1", "value1"); ObjectName mBeanName2 = new ObjectName("domain2", "key2", "value2"); names.add(mBeanName1); names.add(mBeanName2); AppType appType = AppType.P2P; ObjectName objName = new ObjectName("org.glassfish.jersey:type=P2PRestApp,subType=Resources,resource=com.quorum.tessera.*,executionTimes=RequestTimes,detail=methods,method=*"); when(mBeanServer.queryNames(objName, null)).thenReturn(names); String attributeName1 = "name_total"; String attributeName2 = "name2_total"; MBeanAttributeInfo[] mBeanAttributes1 = { new MBeanAttributeInfo(attributeName1, "type", "desc", true, false, false) }; MBeanAttributeInfo[] mBeanAttributes2 = { new MBeanAttributeInfo(attributeName2, "type", "desc", true, false, false) }; MBeanInfo mBeanInfo1 = new MBeanInfo(null, null, mBeanAttributes1, null, null, null); MBeanInfo mBeanInfo2 = new MBeanInfo(null, null, mBeanAttributes2, null, null, null); when(mBeanServer.getMBeanInfo(mBeanName1)).thenReturn(mBeanInfo1); when(mBeanServer.getMBeanInfo(mBeanName2)).thenReturn(mBeanInfo2); when(mBeanServer.getAttribute(any(ObjectName.class), any(String.class))).thenReturn(1); List<MBeanMetric> metrics = metricsEnquirer.getMBeanMetrics(appType); assertThat(metrics.size()).isEqualTo(2); assertThat(metrics.get(0).getName()).isEqualTo("name2_total"); assertThat(metrics.get(1).getName()).isEqualTo("name_total"); }
public List<MBeanMetric> getMBeanMetrics(AppType appType) { List<MBeanMetric> mBeanMetrics = new ArrayList<>(); Set<ObjectName> mBeanNames; try { mBeanNames = getTesseraResourceMBeanNames(appType); for(ObjectName mBeanName : mBeanNames) { List<MBeanMetric> temp; try { temp = getMetricsForMBean(mBeanName); } catch (AttributeNotFoundException | MBeanException | InstanceNotFoundException | ReflectionException | IntrospectionException e) { throw new RuntimeException(e); } mBeanMetrics.addAll(temp); } } catch (MalformedObjectNameException e) { throw new RuntimeException(e); } return Collections.unmodifiableList(mBeanMetrics); }
MetricsEnquirer { public List<MBeanMetric> getMBeanMetrics(AppType appType) { List<MBeanMetric> mBeanMetrics = new ArrayList<>(); Set<ObjectName> mBeanNames; try { mBeanNames = getTesseraResourceMBeanNames(appType); for(ObjectName mBeanName : mBeanNames) { List<MBeanMetric> temp; try { temp = getMetricsForMBean(mBeanName); } catch (AttributeNotFoundException | MBeanException | InstanceNotFoundException | ReflectionException | IntrospectionException e) { throw new RuntimeException(e); } mBeanMetrics.addAll(temp); } } catch (MalformedObjectNameException e) { throw new RuntimeException(e); } return Collections.unmodifiableList(mBeanMetrics); } }
MetricsEnquirer { public List<MBeanMetric> getMBeanMetrics(AppType appType) { List<MBeanMetric> mBeanMetrics = new ArrayList<>(); Set<ObjectName> mBeanNames; try { mBeanNames = getTesseraResourceMBeanNames(appType); for(ObjectName mBeanName : mBeanNames) { List<MBeanMetric> temp; try { temp = getMetricsForMBean(mBeanName); } catch (AttributeNotFoundException | MBeanException | InstanceNotFoundException | ReflectionException | IntrospectionException e) { throw new RuntimeException(e); } mBeanMetrics.addAll(temp); } } catch (MalformedObjectNameException e) { throw new RuntimeException(e); } return Collections.unmodifiableList(mBeanMetrics); } MetricsEnquirer(MBeanServer mBeanServer); }
MetricsEnquirer { public List<MBeanMetric> getMBeanMetrics(AppType appType) { List<MBeanMetric> mBeanMetrics = new ArrayList<>(); Set<ObjectName> mBeanNames; try { mBeanNames = getTesseraResourceMBeanNames(appType); for(ObjectName mBeanName : mBeanNames) { List<MBeanMetric> temp; try { temp = getMetricsForMBean(mBeanName); } catch (AttributeNotFoundException | MBeanException | InstanceNotFoundException | ReflectionException | IntrospectionException e) { throw new RuntimeException(e); } mBeanMetrics.addAll(temp); } } catch (MalformedObjectNameException e) { throw new RuntimeException(e); } return Collections.unmodifiableList(mBeanMetrics); } MetricsEnquirer(MBeanServer mBeanServer); List<MBeanMetric> getMBeanMetrics(AppType appType); }
MetricsEnquirer { public List<MBeanMetric> getMBeanMetrics(AppType appType) { List<MBeanMetric> mBeanMetrics = new ArrayList<>(); Set<ObjectName> mBeanNames; try { mBeanNames = getTesseraResourceMBeanNames(appType); for(ObjectName mBeanName : mBeanNames) { List<MBeanMetric> temp; try { temp = getMetricsForMBean(mBeanName); } catch (AttributeNotFoundException | MBeanException | InstanceNotFoundException | ReflectionException | IntrospectionException e) { throw new RuntimeException(e); } mBeanMetrics.addAll(temp); } } catch (MalformedObjectNameException e) { throw new RuntimeException(e); } return Collections.unmodifiableList(mBeanMetrics); } MetricsEnquirer(MBeanServer mBeanServer); List<MBeanMetric> getMBeanMetrics(AppType appType);  }