### Question:
HelixCallbackMonitor extends DynamicMBeanProvider { @Override public HelixCallbackMonitor register() throws JMException { List<DynamicMetric<?, ?>> attributeList = new ArrayList<>(); attributeList.add(_counter); attributeList.add(_unbatchedCounter); attributeList.add(_totalLatencyCounter); attributeList.add(_latencyGauge); doRegister(attributeList, MBEAN_DESCRIPTION, MonitorDomainNames.HelixCallback.name(), MONITOR_TYPE, _type.name(), MONITOR_KEY, _clusterName + (_instanceName == null ? "" : "." + _instanceName), MONITOR_CHANGE_TYPE, _changeType.name()); return this; } HelixCallbackMonitor(InstanceType type, String clusterName, String instanceName,
      HelixConstants.ChangeType changeType); @Override String getSensorName(); HelixConstants.ChangeType getChangeType(); void increaseCallbackCounters(long time); void increaseCallbackUnbatchedCounters(); @Override HelixCallbackMonitor register(); static final String MONITOR_TYPE; static final String MONITOR_KEY; static final String MONITOR_CHANGE_TYPE; }### Answer:
@Test public void testMBeanRegisteration() throws JMException { Set<HelixCallbackMonitor> monitors = new HashSet<>(); for (HelixConstants.ChangeType changeType : HelixConstants.ChangeType.values()) { monitors.add(new HelixCallbackMonitor(TEST_TYPE, TEST_CLUSTER, null, changeType).register()); Assert.assertTrue( _beanServer.isRegistered(buildObjectName(TEST_TYPE, TEST_CLUSTER, changeType))); } for (HelixConstants.ChangeType changeType : HelixConstants.ChangeType.values()) { monitors.add(new HelixCallbackMonitor(TEST_TYPE, TEST_CLUSTER, null, changeType).register()); Assert.assertTrue( _beanServer.isRegistered(buildObjectName(TEST_TYPE, TEST_CLUSTER, changeType, 1))); } for (HelixConstants.ChangeType changeType : HelixConstants.ChangeType.values()) { monitors.add(new HelixCallbackMonitor(TEST_TYPE, TEST_CLUSTER, null, changeType).register()); Assert.assertTrue( _beanServer.isRegistered(buildObjectName(TEST_TYPE, TEST_CLUSTER, changeType, 2))); } for (HelixCallbackMonitor monitor : monitors) { monitor.unregister(); } for (HelixConstants.ChangeType changeType : HelixConstants.ChangeType.values()) { Assert.assertFalse( _beanServer.isRegistered(buildObjectName(TEST_TYPE, TEST_CLUSTER, changeType))); Assert.assertFalse( _beanServer.isRegistered(buildObjectName(TEST_TYPE, TEST_CLUSTER, changeType, 1))); Assert.assertFalse( _beanServer.isRegistered(buildObjectName(TEST_TYPE, TEST_CLUSTER, changeType, 2))); } }