@Test public void testWatchedSupplier() throws IOException { Database first = Database.builder() .setDriver("com.mysql.Driver") .build(); Database second = Database.builder() .setDriver("org.h2.Driver") .build(); File file = tmp.newFile().getAbsoluteFile().getCanonicalFile(); when((Pair) parser.parseConfig(file.toPath(), null)).thenReturn(Pair.create(first, ImmutableSet.of(file.toString()))); ArgumentCaptor<FileWatcher.Listener> watcherCapture = ArgumentCaptor.forClass(FileWatcher.Listener.class); doNothing().when(watcher).weakAddWatcher(eq(file.toPath()), watcherCapture.capture()); ProvidenceConfigSupplier<Database, Database._Field> supplier = new ProvidenceConfigSupplier<>(file, null, watcher, parser, clock); assertThat(supplier.get(), is(sameInstance(first))); assertThat(supplier.get(), is(sameInstance(first))); assertThat(supplier.get(), is(sameInstance(first))); verify(parser).parseConfig(file.toPath(), null); verify(watcher, atMost(5)).weakAddWatcher(eq(file.toPath()), any(FileWatcher.Listener.class)); verifyNoMoreInteractions(watcher, parser); reset(parser, watcher); when((Pair) parser.parseConfig(file.toPath(), null)).thenReturn(Pair.create(second, ImmutableSet.of(file.toString()))); doNothing().when(watcher).weakAddWatcher(eq(file.toPath()), watcherCapture.capture()); watcherCapture.getValue().onPathUpdate(file.toPath()); assertThat(supplier.get(), is(sameInstance(second))); assertThat(supplier.get(), is(sameInstance(second))); assertThat(supplier.get(), is(sameInstance(second))); verify(parser).parseConfig(file.toPath(), null); verifyNoMoreInteractions(parser, watcher); }
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("ProvidenceConfig{") .append(configFile.getName()); if (parentSupplier != null) { builder.append(", parent="); builder.append(parentSupplier.getName()); } builder.append("}"); return builder.toString(); }
ProvidenceConfigSupplier extends UpdatingConfigSupplier<Message, Field> { @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("ProvidenceConfig{") .append(configFile.getName()); if (parentSupplier != null) { builder.append(", parent="); builder.append(parentSupplier.getName()); } builder.append("}"); return builder.toString(); } }
ProvidenceConfigSupplier extends UpdatingConfigSupplier<Message, Field> { @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("ProvidenceConfig{") .append(configFile.getName()); if (parentSupplier != null) { builder.append(", parent="); builder.append(parentSupplier.getName()); } builder.append("}"); return builder.toString(); } ProvidenceConfigSupplier(@Nonnull File configFile,
                                    @Nullable ConfigSupplier<Message, Field> parentSupplier,
                                    @Nullable FileWatcher fileWatcher,
                                    @Nonnull ProvidenceConfigParser configParser,
                                    @Nonnull Clock clock); }
ProvidenceConfigSupplier extends UpdatingConfigSupplier<Message, Field> { @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("ProvidenceConfig{") .append(configFile.getName()); if (parentSupplier != null) { builder.append(", parent="); builder.append(parentSupplier.getName()); } builder.append("}"); return builder.toString(); } ProvidenceConfigSupplier(@Nonnull File configFile,
                                    @Nullable ConfigSupplier<Message, Field> parentSupplier,
                                    @Nullable FileWatcher fileWatcher,
                                    @Nonnull ProvidenceConfigParser configParser,
                                    @Nonnull Clock clock); @Override String toString(); @Override String getName(); }
ProvidenceConfigSupplier extends UpdatingConfigSupplier<Message, Field> { @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("ProvidenceConfig{") .append(configFile.getName()); if (parentSupplier != null) { builder.append(", parent="); builder.append(parentSupplier.getName()); } builder.append("}"); return builder.toString(); } ProvidenceConfigSupplier(@Nonnull File configFile,
                                    @Nullable ConfigSupplier<Message, Field> parentSupplier,
                                    @Nullable FileWatcher fileWatcher,
                                    @Nonnull ProvidenceConfigParser configParser,
                                    @Nonnull Clock clock); @Override String toString(); @Override String getName();  }