@Test(expected = IllegalStateException.class) public void testInitBadValue() throws Exception { ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1); RouteReloader<TrivialFactory> subject = new RouteReloader<TrivialFactory>(executor, TrivialFactory::new); String initialFileContents = badValue; String input = rawCreateConf(initialFileContents, inputJsonFilename); TrivialFactory initialValue = subject.init(input); }
@Test public void testInitHappyPath() throws Exception { ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1); RouteReloader<TrivialFactory> subject = new RouteReloader<TrivialFactory>(executor, TrivialFactory::new); String initialFileContents = helloWorldValue; String input = rawCreateConf(initialFileContents, inputJsonFilename); TrivialFactory initialValue = subject.init(input); assertEquals(initialFileContents, initialValue.inputString); }
@Test public void testStartHappyPath() throws Exception { AtomicBoolean fireUpdatedCalled = new AtomicBoolean(false); ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1); RouteReloader<TrivialFactory> subject = new RouteReloader<TrivialFactory>(executor, TrivialFactory::new); String initialFileContents = helloWorldValue; String input = rawCreateConf(initialFileContents, inputJsonFilename); TrivialFactory initialValue = subject.init(input); assertEquals(initialFileContents, initialValue.inputString); TrivialState state = new TrivialState() { @Override public void fireUpdated() { fireUpdatedCalled.set(true); } }; // this should NOT throw an exception because we called init before calling start subject.start(state::update); executor.shutdown(); } }
String input = rawCreateConf(initialFileContents, inputJsonFilename); TrivialFactory initialValue = subject.init(input);
@Test public void testReload_WhenWatchedFilesDoNotChange() throws Exception { AtomicBoolean fireUpdatedCalled = new AtomicBoolean(false); ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1); RouteReloader<TrivialFactory> subject = new RouteReloader<TrivialFactory>(executor, TrivialFactory::new); String initialFileContents = helloWorldValue; String input = rawCreateConf(initialFileContents, inputJsonFilename); // init the subject with an file that contains the helloworldvalue TrivialFactory initialValue = subject.init(input); // the result from the init should be the baseline TrivialFactory output and it should match the helloworldvalue assertEquals(initialFileContents, initialValue.inputString); TrivialState state = new TrivialState() { @Override public void fireUpdated() { fireUpdatedCalled.set(true); } }; // start the threaded update subject.start(state::update); Thread.sleep(5000); // since we did not change any files we should not get an update assertFalse(fireUpdatedCalled.get()); // the update should have never been called and these values should not be set assertEquals(null, state.oldValue); assertEquals(null, state.newValue); executor.shutdown(); }
String input = rawCreateConf(initialFileContents, inputJsonFilename); TrivialFactory initialValue = subject.init(input);
String input = rawCreateConf(initialFileContents, inputJsonFilename); TrivialFactory initialValue = subject.init(input);