use of org.apache.kafka.common.config.ConfigException in project kafka by apache.
the class HasHeaderKeyTest method testNameRequiredInConfig.
@Test
public void testNameRequiredInConfig() {
Map<String, String> props = new HashMap<>();
ConfigException e = assertThrows(ConfigException.class, () -> config(props));
assertTrue(e.getMessage().contains("Missing required configuration \"name\""));
}
use of org.apache.kafka.common.config.ConfigException in project kafka by apache.
the class RaftConfig method parseVoterConnections.
public static Map<Integer, AddressSpec> parseVoterConnections(List<String> voterEntries) {
Map<Integer, AddressSpec> voterMap = new HashMap<>();
for (String voterMapEntry : voterEntries) {
String[] idAndAddress = voterMapEntry.split("@");
if (idAndAddress.length != 2) {
throw new ConfigException("Invalid configuration value for " + QUORUM_VOTERS_CONFIG + ". Each entry should be in the form `{id}@{host}:{port}`.");
}
Integer voterId = parseVoterId(idAndAddress[0]);
String host = Utils.getHost(idAndAddress[1]);
if (host == null) {
throw new ConfigException("Failed to parse host name from entry " + voterMapEntry + " for the configuration " + QUORUM_VOTERS_CONFIG + ". Each entry should be in the form `{id}@{host}:{port}`.");
}
Integer port = Utils.getPort(idAndAddress[1]);
if (port == null) {
throw new ConfigException("Failed to parse host port from entry " + voterMapEntry + " for the configuration " + QUORUM_VOTERS_CONFIG + ". Each entry should be in the form `{id}@{host}:{port}`.");
}
InetSocketAddress address = new InetSocketAddress(host, port);
if (address.equals(NON_ROUTABLE_ADDRESS)) {
voterMap.put(voterId, UNKNOWN_ADDRESS_SPEC_INSTANCE);
} else {
voterMap.put(voterId, new InetAddressSpec(address));
}
}
return voterMap;
}
use of org.apache.kafka.common.config.ConfigException in project connect-utils by jcustenborder.
the class ValidHostAndPort method ensureValid.
@Override
public void ensureValid(final String setting, final Object value) {
if (value instanceof String) {
final String input = (String) value;
validate(setting, input);
} else if (value instanceof List) {
final List<String> inputs = (List<String>) value;
for (String input : inputs) {
validate(setting, input);
}
} else {
throw new ConfigException(String.format("'%s' must be a String or List", setting));
}
}
use of org.apache.kafka.common.config.ConfigException in project connect-utils by jcustenborder.
the class ValidHostnameAndPort method ensureValid.
@Override
public void ensureValid(String key, Object value) {
log.trace("ensureValid('{}', '{}')", key, value);
if (value instanceof String) {
try {
Matcher matcher = HOSTNAME_PATTERN.matcher((CharSequence) value);
Preconditions.checkState(matcher.matches(), "'%s' does not match pattern '%s'.", key, HOSTNAME_PATTERN.pattern());
final int port = Integer.parseInt(matcher.group(2));
Preconditions.checkState(port >= 1 && port <= 65535, "'%s' port value %s is out of range. Port must be between 1 and 65535.", key, port);
} catch (Exception ex) {
throw new ConfigException(String.format("'%s' is not a valid hostname and port.", key), ex);
}
} else if (value instanceof List) {
List<String> list = (List<String>) value;
for (String s : list) {
ensureValid(key, s);
}
} else {
throw new ConfigException(String.format("'%s' must be a string or a list.", key));
}
}
use of org.apache.kafka.common.config.ConfigException in project connect-utils by jcustenborder.
the class ValidCharsetTest method invalid.
@Test
public void invalid() {
ConfigException configException = assertThrows(ConfigException.class, () -> {
ConfigDef.Validator validator = new ValidCharset();
validator.ensureValid("testing", 1234);
});
}
Aggregations