ConfigRetriever { public ConfigSnapshot getConfigs(Set<ConfigKey<? extends ConfigInstance>> componentConfigKeys, long leastGeneration, boolean restartOnRedeploy) { while (true) { Optional<ConfigSnapshot> maybeSnapshot = getConfigsOnce(componentConfigKeys, leastGeneration, restartOnRedeploy); if (maybeSnapshot.isPresent()) { var configSnapshot = maybeSnapshot.get(); resetComponentSubscriberIfBootstrap(configSnapshot); return configSnapshot; } } } ConfigRetriever(Set<ConfigKey<? extends ConfigInstance>> bootstrapKeys,
                           Function<Set<ConfigKey<? extends ConfigInstance>>, Subscriber> subscribe); ConfigSnapshot getConfigs(Set<ConfigKey<? extends ConfigInstance>> componentConfigKeys,
                                     long leastGeneration,
                                     boolean restartOnRedeploy); void shutdown(); long getBootstrapGeneration(); long getComponentsGeneration();  }
@Test public void require_that_bootstrap_configs_come_first() { writeConfigs(); ConfigRetriever retriever = createConfigRetriever(); ConfigSnapshot bootstrapConfigs = retriever.getConfigs(Collections.emptySet(), 0, false); assertThat(bootstrapConfigs, Matchers.instanceOf(BootstrapConfigs.class)); }
@Test @SuppressWarnings("unused") public void require_that_components_comes_after_bootstrap() { writeConfigs(); ConfigRetriever retriever = createConfigRetriever(); ConfigSnapshot bootstrapConfigs = retriever.getConfigs(Collections.emptySet(), 0, false); ConfigKey<? extends ConfigInstance> testConfigKey = new ConfigKey<>(TestConfig.class, dirConfigSource.configId()); ConfigSnapshot componentsConfigs = retriever.getConfigs(Collections.singleton(testConfigKey), 0); if (componentsConfigs instanceof ComponentsConfigs) { assertThat(componentsConfigs.size(), is(3)); } else { fail("ComponentsConfigs has unexpected type: " + componentsConfigs); } }
@Test public void require_that_empty_components_keys_after_bootstrap_returns_components_configs() { writeConfigs(); ConfigRetriever retriever = createConfigRetriever(); assertThat(retriever.getConfigs(Collections.emptySet(), 0), instanceOf(BootstrapConfigs.class)); assertThat(retriever.getConfigs(Collections.emptySet(), 0), instanceOf(ComponentsConfigs.class)); }