### Question:
CompositeDataNodeConfigSource implements DataNodeConfigSource { @Override public boolean set(DataNodeConfig config) { boolean primaryResult = primarySource.set(config); try { boolean secondaryResult = secondarySource.set(config); if (primaryResult != secondaryResult) { metrics.setSwallowedErrorCount.inc(); LOGGER.error("Results differ for set({}). sourceOfTruth={}, secondarySource={}", config, primaryResult, secondaryResult); } } catch (Exception e) { metrics.setSwallowedErrorCount.inc(); LOGGER.error("Error from secondarySource.set({})", config, e); } return primaryResult; } CompositeDataNodeConfigSource(DataNodeConfigSource primarySource, DataNodeConfigSource secondarySource,
      Time time, DataNodeConfigSourceMetrics metrics); @Override void addDataNodeConfigChangeListener(DataNodeConfigChangeListener listener); @Override boolean set(DataNodeConfig config); @Override DataNodeConfig get(String instanceName); @Override void close();  }### Answer:
@Test public void testSetBothSuccess() { when(primarySource.set(any())).thenReturn(true); when(secondarySource.set(any())).thenReturn(true); DataNodeConfig config = createConfig(1, 1); assertTrue("Expected success response", compositeSource.set(config)); verify(primarySource).set(config); verify(secondarySource).set(config); }
@Test public void testSetResultsDifferent() { when(primarySource.set(any())).thenReturn(true); when(secondarySource.set(any())).thenReturn(false); DataNodeConfig config = createConfig(1, 1); assertTrue("Expected response from primary", compositeSource.set(config)); verify(primarySource).set(config); verify(secondarySource).set(config); assertEquals("Expected one inconsistency", 1, metrics.setSwallowedErrorCount.getCount()); }
@Test public void testSetException() throws Exception { when(primarySource.set(any())).thenThrow(new RuntimeException()); DataNodeConfig config = createConfig(1, 1); TestUtils.assertException(RuntimeException.class, () -> compositeSource.set(config), null); verify(primarySource).set(config); verify(secondarySource, never()).set(any()); reset(primarySource, secondarySource); when(primarySource.set(any())).thenReturn(true); when(secondarySource.set(any())).thenThrow(new RuntimeException()); assertTrue("Expected response from primary", compositeSource.set(config)); verify(primarySource).set(config); verify(secondarySource).set(config); assertEquals("Expected one inconsistency", 1, metrics.setSwallowedErrorCount.getCount()); }