use of org.apache.kafka.common.config.ConfigData in project kafka by apache.
the class DirectoryConfigProviderTest method testGetSetOfKeysAtPath.
@Test
public void testGetSetOfKeysAtPath() {
Set<String> keys = toSet(asList(foo.getName(), "baz"));
ConfigData configData = provider.get(dir.getAbsolutePath(), keys);
assertEquals(Collections.singleton(foo.getName()), configData.data().keySet());
assertEquals("FOO", configData.data().get(foo.getName()));
assertNull(configData.ttl());
}
use of org.apache.kafka.common.config.ConfigData in project kafka by apache.
the class FileConfigProvider method get.
/**
* Retrieves the data with the given keys at the given Properties file.
*
* @param path the file where the data resides
* @param keys the keys whose values will be retrieved
* @return the configuration data
*/
public ConfigData get(String path, Set<String> keys) {
Map<String, String> data = new HashMap<>();
if (path == null || path.isEmpty()) {
return new ConfigData(data);
}
try (Reader reader = reader(path)) {
Properties properties = new Properties();
properties.load(reader);
for (String key : keys) {
String value = properties.getProperty(key);
if (value != null) {
data.put(key, value);
}
}
return new ConfigData(data);
} catch (IOException e) {
log.error("Could not read properties from file {}", path, e);
throw new ConfigException("Could not read properties from file " + path);
}
}
use of org.apache.kafka.common.config.ConfigData in project kafka by apache.
the class FileConfigProvider method get.
/**
* Retrieves the data at the given Properties file.
*
* @param path the file where the data resides
* @return the configuration data
*/
public ConfigData get(String path) {
Map<String, String> data = new HashMap<>();
if (path == null || path.isEmpty()) {
return new ConfigData(data);
}
try (Reader reader = reader(path)) {
Properties properties = new Properties();
properties.load(reader);
Enumeration<Object> keys = properties.keys();
while (keys.hasMoreElements()) {
String key = keys.nextElement().toString();
String value = properties.getProperty(key);
if (value != null) {
data.put(key, value);
}
}
return new ConfigData(data);
} catch (IOException e) {
log.error("Could not read properties from file {}", path, e);
throw new ConfigException("Could not read properties from file " + path);
}
}
use of org.apache.kafka.common.config.ConfigData in project kafka by apache.
the class DirectoryConfigProviderTest method testEmptyPathWithKey.
@Test
public void testEmptyPathWithKey() {
ConfigData configData = provider.get("", Collections.singleton("foo"));
assertTrue(configData.data().isEmpty());
assertNull(configData.ttl());
}
use of org.apache.kafka.common.config.ConfigData in project kafka by apache.
the class DirectoryConfigProviderTest method testNullPath.
@Test
public void testNullPath() {
ConfigData configData = provider.get(null);
assertTrue(configData.data().isEmpty());
assertNull(configData.ttl());
}
Aggregations