Search in sources :

Example 1 with DirSource

use of com.yahoo.config.subscription.DirSource in project vespa by vespa-engine.

the class FileConfigSubscriptionTest method require_that_dir_config_id_reference_is_not_changed.

@Test
public void require_that_dir_config_id_reference_is_not_changed() {
    final String cfgDir = "src/test/resources/configs/foo";
    final String cfgId = "dir:" + cfgDir;
    final ConfigKey<TestReferenceConfig> key = new ConfigKey<>(TestReferenceConfig.class, cfgId);
    ConfigSubscriber subscriber = new ConfigSubscriber();
    ConfigSubscription<TestReferenceConfig> sub = ConfigSubscription.get(key, subscriber, new DirSource(new File(cfgDir)), new TimingValues());
    assertTrue(sub.nextConfig(1000));
    assertThat(sub.getConfigState().getConfig().configId(), is(cfgId));
}
Also used : TestReferenceConfig(com.yahoo.foo.TestReferenceConfig) ConfigKey(com.yahoo.vespa.config.ConfigKey) ConfigSubscriber(com.yahoo.config.subscription.ConfigSubscriber) TimingValues(com.yahoo.vespa.config.TimingValues) DirSource(com.yahoo.config.subscription.DirSource) File(java.io.File) Test(org.junit.Test)

Example 2 with DirSource

use of com.yahoo.config.subscription.DirSource in project vespa by vespa-engine.

the class ConfigSubscription method getDirFileSub.

private static <T extends ConfigInstance> ConfigSubscription<T> getDirFileSub(ConfigKey<T> key, ConfigSubscriber subscriber, ConfigSource source) {
    String dir = key.getConfigId().replace("dir:", "");
    if (source instanceof DirSource) {
        dir = ((DirSource) source).getDir().toString();
    }
    if (!dir.endsWith(File.separator))
        dir = dir + File.separator;
    String name = getConfigFilenameNoVersion(key);
    File file = new File(dir + name);
    if (!file.exists()) {
        throw new IllegalArgumentException("Could not find a config file for '" + key.getName() + "' in '" + dir + "'");
    }
    return new FileConfigSubscription<>(key, subscriber, file);
}
Also used : DirSource(com.yahoo.config.subscription.DirSource) File(java.io.File)

Aggregations

DirSource (com.yahoo.config.subscription.DirSource)2 File (java.io.File)2 ConfigSubscriber (com.yahoo.config.subscription.ConfigSubscriber)1 TestReferenceConfig (com.yahoo.foo.TestReferenceConfig)1 ConfigKey (com.yahoo.vespa.config.ConfigKey)1 TimingValues (com.yahoo.vespa.config.TimingValues)1 Test (org.junit.Test)1