### Question:
CompositeDataNodeConfigSource implements DataNodeConfigSource { @Override public DataNodeConfig get(String instanceName) { DataNodeConfig primaryResult = primarySource.get(instanceName); try { DataNodeConfig secondaryResult = secondarySource.get(instanceName); if (!Objects.equals(primaryResult, secondaryResult)) { metrics.getSwallowedErrorCount.inc(); LOGGER.error("Results differ for get({}). sourceOfTruth={}, secondarySource={}", instanceName, primaryResult, secondaryResult); } } catch (Exception e) { metrics.getSwallowedErrorCount.inc(); LOGGER.error("Error from secondarySource.get({})", instanceName, 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 testGetBothSuccess() { DataNodeConfig config = createConfig(1, 1); when(primarySource.get(any())).thenReturn(config); when(secondarySource.get(any())).thenReturn(config); assertEquals("Unexpected response", config, compositeSource.get(config.getInstanceName())); verify(primarySource).get(config.getInstanceName()); verify(secondarySource).get(config.getInstanceName()); }
@Test public void testGetResultsDifferent() { DataNodeConfig config = createConfig(1, 1); when(primarySource.get(any())).thenReturn(config); when(secondarySource.get(any())).thenReturn(createConfig(1, 1)); assertEquals("Expected response from primary", config, compositeSource.get(config.getInstanceName())); verify(primarySource).get(config.getInstanceName()); verify(secondarySource).get(config.getInstanceName()); assertEquals("Expected one inconsistency", 1, metrics.getSwallowedErrorCount.getCount()); }
@Test public void testGetException() throws Exception { when(primarySource.get(any())).thenThrow(new RuntimeException()); DataNodeConfig config = createConfig(1, 1); TestUtils.assertException(RuntimeException.class, () -> compositeSource.get(config.getInstanceName()), null); verify(primarySource).get(config.getInstanceName()); verify(secondarySource, never()).get(any()); reset(primarySource, secondarySource); when(primarySource.get(any())).thenReturn(config); when(secondarySource.get(any())).thenThrow(new RuntimeException()); assertEquals("Expected response from primary", config, compositeSource.get(config.getInstanceName())); verify(primarySource).get(config.getInstanceName()); verify(secondarySource).get(config.getInstanceName()); assertEquals("Expected one inconsistency", 1, metrics.getSwallowedErrorCount.getCount()); }