}
@Test
public void testSasl() {
ClientConfiguration conf = new ClientConfiguration(Collections. emptyList());
assertEquals("false", conf.get(ClientProperty.INSTANCE_RPC_SASL_ENABLED));
conf.withSasl(false);
assertEquals("false", conf.get(ClientProperty.INSTANCE_RPC_SASL_ENABLED));
conf.withSasl(true);
assertEquals("true", conf.get(ClientProperty.INSTANCE_RPC_SASL_ENABLED));
final String primary = "accumulo";
conf.withSasl(true, primary);
assertEquals(primary, conf.get(ClientProperty.KERBEROS_SERVER_PRIMARY));
}
@Test
public void testMultipleValues() throws ConfigurationException {
String val = "comma,separated,list";
// not the recommended way to construct a client configuration, but it works
PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
propertiesConfiguration.setDelimiterParsingDisabled(true);
propertiesConfiguration.addProperty(ClientProperty.INSTANCE_ZK_HOST.getKey(), val);
propertiesConfiguration.load(new StringReader(ClientProperty.TRACE_SPAN_RECEIVERS.getKey() + "=" + val));
ClientConfiguration conf = new ClientConfiguration(propertiesConfiguration);
assertEquals(val, conf.get(ClientProperty.INSTANCE_ZK_HOST));
assertEquals(1, conf.getList(ClientProperty.INSTANCE_ZK_HOST.getKey()).size());
assertEquals(val, conf.get(ClientProperty.TRACE_SPAN_RECEIVERS));
assertEquals(1, conf.getList(ClientProperty.TRACE_SPAN_RECEIVERS.getKey()).size());
// incorrect usage that results in not being able to use multi-valued properties
conf = new ClientConfiguration(new PropertiesConfiguration("multi-valued.client.conf"));
assertNotEquals(val, conf.get(ClientProperty.INSTANCE_ZK_HOST));
assertEquals(3, conf.getList(ClientProperty.INSTANCE_ZK_HOST.getKey()).size());
assertNotEquals(val, conf.get(ClientProperty.TRACE_SPAN_RECEIVERS));
assertEquals(3, conf.getList(ClientProperty.TRACE_SPAN_RECEIVERS.getKey()).size());
// recommended usage
conf = new ClientConfiguration("multi-valued.client.conf");
assertEquals(val, conf.get(ClientProperty.INSTANCE_ZK_HOST));
assertEquals(1, conf.getList(ClientProperty.INSTANCE_ZK_HOST.getKey()).size());
assertEquals(val, conf.get(ClientProperty.TRACE_SPAN_RECEIVERS));
assertEquals(1, conf.getList(ClientProperty.TRACE_SPAN_RECEIVERS.getKey()).size());
// only used internally
Map map = new HashMap<>();
map.put(ClientProperty.INSTANCE_ZK_HOST.getKey(), val);
map.put(ClientProperty.TRACE_SPAN_RECEIVERS.getKey(), val);
conf = new ClientConfiguration(new MapConfiguration(map));
assertEquals(val, conf.get(ClientProperty.INSTANCE_ZK_HOST));
assertEquals(1, conf.getList(ClientProperty.INSTANCE_ZK_HOST.getKey()).size());
assertEquals(val, conf.get(ClientProperty.TRACE_SPAN_RECEIVERS));
assertEquals(1, conf.getList(ClientProperty.TRACE_SPAN_RECEIVERS.getKey()).size());
}
} |