### Question:
CustomizedViewMonitor extends DynamicMBeanProvider { @Override public DynamicMBeanProvider register() throws JMException { List<DynamicMetric<?, ?>> attributeList = new ArrayList<>(); attributeList.add(_updateToAggregationLatencyGauge); doRegister(attributeList, MBEAN_DESCRIPTION, getMBeanObjectName()); return this; } CustomizedViewMonitor(String clusterName); @Override DynamicMBeanProvider register(); @Override String getSensorName(); void recordUpdateToAggregationLatency(long latency); static final String UPDATE_TO_AGGREGATION_LATENCY_GAUGE; }### Answer:
@Test public void testMBeanRegistration() throws JMException, IOException { int numOfMonitors = 5; Stack<CustomizedViewMonitor> monitors = new Stack<>(); for (int i = 0; i < numOfMonitors; i++) { CustomizedViewMonitor monitor = new CustomizedViewMonitor(TEST_CLUSTER); monitor.register(); monitors.push(monitor); } for (int i = 0; i < numOfMonitors; i++) { if (i == numOfMonitors - 1) { Assert.assertTrue(_server.isRegistered(buildObjectName(0))); } else { Assert.assertTrue(_server.isRegistered(buildObjectName(numOfMonitors - i - 1))); } CustomizedViewMonitor monitor = monitors.pop(); assert monitor != null; monitor.unregister(); if (i == numOfMonitors - 1) { Assert.assertFalse(_server.isRegistered(buildObjectName(0))); } else { Assert.assertFalse(_server.isRegistered(buildObjectName(numOfMonitors - i - 1))); } } }