FileChangeIngestor implements Runnable, ChangeIngestor { @Override public void initialize(Properties properties, ConfigurationFileHolder configurationFileHolder, ConfigurationChangeNotifier configurationChangeNotifier) { final String rawPath = properties.getProperty(CONFIG_FILE_PATH_KEY); final String rawPollingDuration = properties.getProperty(POLLING_PERIOD_INTERVAL_KEY, Long.toString(DEFAULT_POLLING_PERIOD_INTERVAL)); if (rawPath == null || rawPath.isEmpty()) { throw new IllegalArgumentException("Property, " + CONFIG_FILE_PATH_KEY + ", for the path of the config file must be specified."); } try { setConfigFilePath(Paths.get(rawPath)); setPollingPeriod(Long.parseLong(rawPollingDuration), DEFAULT_POLLING_PERIOD_UNIT); setWatchService(initializeWatcher(configFilePath)); } catch (Exception e) { throw new IllegalStateException("Could not successfully initialize file change notifier.", e); } this.configurationChangeNotifier = configurationChangeNotifier; final String differentiatorName = properties.getProperty(DIFFERENTIATOR_KEY); if (differentiatorName != null && !differentiatorName.isEmpty()) { Supplier<Differentiator<InputStream>> differentiatorSupplier = DIFFERENTIATOR_CONSTRUCTOR_MAP.get(differentiatorName); if (differentiatorSupplier == null) { throw new IllegalArgumentException("Property, " + DIFFERENTIATOR_KEY + ", has value " + differentiatorName + " which does not " + "correspond to any in the PullHttpChangeIngestor Map:" + DIFFERENTIATOR_CONSTRUCTOR_MAP.keySet()); } differentiator = differentiatorSupplier.get(); } else { differentiator = WholeConfigDifferentiator.getInputStreamDifferentiator(); } differentiator.initialize(properties, configurationFileHolder); }  @Override void run(); @Override void initialize(Properties properties, ConfigurationFileHolder configurationFileHolder, ConfigurationChangeNotifier configurationChangeNotifier); @Override void start(); @Override void close(); static final String DIFFERENTIATOR_KEY; }
@Test(expected = IllegalStateException.class) public void testInitialize_invalidFile() throws Exception { testProperties.put(FileChangeIngestor.CONFIG_FILE_PATH_KEY, "/land/of/make/believe"); notifierSpy.initialize(testProperties, Mockito.mock(ConfigurationFileHolder.class), Mockito.mock(ConfigurationChangeNotifier.class)); }
@Test public void testInitialize_validFile() throws Exception { notifierSpy.initialize(testProperties, Mockito.mock(ConfigurationFileHolder.class), Mockito.mock(ConfigurationChangeNotifier.class)); }
@Test(expected = IllegalStateException.class) public void testInitialize_invalidPollingPeriod() throws Exception { testProperties.put(FileChangeIngestor.POLLING_PERIOD_INTERVAL_KEY, "abc"); notifierSpy.initialize(testProperties, Mockito.mock(ConfigurationFileHolder.class), Mockito.mock(ConfigurationChangeNotifier.class)); }
@Test public void testInitialize_useDefaultPolling() throws Exception { testProperties.remove(FileChangeIngestor.POLLING_PERIOD_INTERVAL_KEY); notifierSpy.initialize(testProperties, Mockito.mock(ConfigurationFileHolder.class), Mockito.mock(ConfigurationChangeNotifier.class)); }