Search in sources :

Example 1 with ConfigLoader

use of org.apache.samza.config.ConfigLoader in project samza by apache.

the class TestPropertiesConfigLoader method testCanReadPropertiesConfigFiles.

@Test
public void testCanReadPropertiesConfigFiles() {
    ConfigLoader loader = new PropertiesConfigLoaderFactory().getLoader(new MapConfig(Collections.singletonMap("path", getClass().getResource("/test.properties").getPath())));
    Config config = loader.getConfig();
    assertEquals("bar", config.get("foo"));
}
Also used : ConfigLoader(org.apache.samza.config.ConfigLoader) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) MapConfig(org.apache.samza.config.MapConfig) Test(org.junit.Test)

Example 2 with ConfigLoader

use of org.apache.samza.config.ConfigLoader in project samza by apache.

the class ConfigUtil method loadConfig.

/**
 * Load full job config with {@link ConfigLoaderFactory} when present.
 *
 * @param original config
 * @return full job config
 */
public static Config loadConfig(Config original) {
    JobConfig jobConfig = new JobConfig(original);
    if (!jobConfig.getConfigLoaderFactory().isPresent()) {
        throw new ConfigException("Missing key " + JobConfig.CONFIG_LOADER_FACTORY + ".");
    }
    ConfigLoaderFactory factory = ReflectionUtil.getObj(jobConfig.getConfigLoaderFactory().get(), ConfigLoaderFactory.class);
    ConfigLoader loader = factory.getLoader(original.subset(ConfigLoaderFactory.CONFIG_LOADER_PROPERTIES_PREFIX));
    // overrides config loaded with original config, which may contain overridden values.
    return rewriteConfig(override(loader.getConfig(), original));
}
Also used : ConfigLoader(org.apache.samza.config.ConfigLoader) ConfigLoaderFactory(org.apache.samza.config.ConfigLoaderFactory) ConfigException(org.apache.samza.config.ConfigException) JobConfig(org.apache.samza.config.JobConfig)

Example 3 with ConfigLoader

use of org.apache.samza.config.ConfigLoader in project samza by apache.

the class TestPropertiesConfigLoader method testCanNotReadWithoutPath.

@Test(expected = SamzaException.class)
public void testCanNotReadWithoutPath() {
    ConfigLoader loader = new PropertiesConfigLoaderFactory().getLoader(new MapConfig());
    loader.getConfig();
}
Also used : ConfigLoader(org.apache.samza.config.ConfigLoader) MapConfig(org.apache.samza.config.MapConfig) Test(org.junit.Test)

Aggregations

ConfigLoader (org.apache.samza.config.ConfigLoader)3 MapConfig (org.apache.samza.config.MapConfig)2 Test (org.junit.Test)2 Config (org.apache.samza.config.Config)1 ConfigException (org.apache.samza.config.ConfigException)1 ConfigLoaderFactory (org.apache.samza.config.ConfigLoaderFactory)1 JobConfig (org.apache.samza.config.JobConfig)1