### Question:
RocksDBStoreMBean implements DynamicMBean, MetricsSource { @Override public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException { for (String histogramAttribute : histogramAttributes) { if (attribute.endsWith("_" + histogramAttribute.toUpperCase())) { String keyName = attribute .substring(0, attribute.length() - histogramAttribute.length() - 1); try { HistogramData histogram = statistics.getHistogramData(HistogramType.valueOf(keyName)); try { Method method = HistogramData.class.getMethod("get" + histogramAttribute); return method.invoke(histogram); } catch (Exception e) { throw new ReflectionException(e, "Can't read attribute " + attribute); } } catch (IllegalArgumentException exception) { throw new AttributeNotFoundException( "No such attribute in RocksDB stats: " + attribute); } } } try { return statistics.getTickerCount(TickerType.valueOf(attribute)); } catch (IllegalArgumentException ex) { throw new AttributeNotFoundException( "No such attribute in RocksDB stats: " + attribute); } } RocksDBStoreMBean(Statistics statistics, String dbName); static RocksDBStoreMBean create(Statistics statistics,
                                         String contextName); @Override Object getAttribute(String attribute); @Override void setAttribute(Attribute attribute); @Override AttributeList getAttributes(String[] attributes); @Override AttributeList setAttributes(AttributeList attributes); @Override Object invoke(String actionName, Object[] params, String[] signature); @Override MBeanInfo getMBeanInfo(); @Override void getMetrics(MetricsCollector metricsCollector, boolean b); final static String ROCKSDB_CONTEXT_PREFIX; }### Answer:
@Test public void testJmxBeans() throws Exception { RocksDBStore metadataStore = getTestRocksDBStoreWithData(); MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer(); Thread.sleep(2000); Object keysWritten = platformMBeanServer .getAttribute(metadataStore.getStatMBeanName(), "NUMBER_KEYS_WRITTEN"); assertEquals(10L, keysWritten); Object dbWriteAverage = platformMBeanServer .getAttribute(metadataStore.getStatMBeanName(), "DB_WRITE_AVERAGE"); assertTrue((double) dbWriteAverage > 0); metadataStore.close(); }