@Test
  public void testListenerExceptions() throws Exception {
    // exception during init
    DataNodeConfigChangeListener listener1 = mock(DataNodeConfigChangeListener.class);
    RuntimeException initException = new RuntimeException("Failure during init");
    doThrow(initException).when(listener1).onDataNodeConfigChange(any());
    assertException(RuntimeException.class, () -> source.addDataNodeConfigChangeListener(listener1),
        e -> assertEquals("Unexpected exception thrown", initException, e));
    checkListenerCall(listener1, Collections.emptySet());
    // no more calls to listener should occur
    reset(listener1);
    DataNodeConfig config = createConfig(1, 1);
    source.set(config);
    verify(listener1, never()).onDataNodeConfigChange(any());

    // exception during update call.
    DataNodeConfigChangeListener listener2 = mock(DataNodeConfigChangeListener.class);
    source.addDataNodeConfigChangeListener(listener2);
    checkListenerCall(listener2, Collections.singleton(config));
    reset(listener2);
    RuntimeException updateException = new RuntimeException("Failure during update");
    doThrow(updateException).when(listener2).onDataNodeConfigChange(any());
    config.getDisabledReplicas().add("partition1");
    source.set(config);
    checkListenerCall(listener2, Collections.singleton(config));
    // more updates should still create notifications
    config.getDisabledReplicas().add("partition2");
    source.set(config);
    checkListenerCall(listener2, Collections.singleton(config));
  }
Test handling of listener errors during initialization and updates.
ambry-clustermap/src/test/java/com/github/ambry/clustermap/PropertyStoreToDataNodeConfigAdapterTest.java