private static ExpiringCredentialRefreshConfig refreshConfigThatPerformsReloginEveryGivenPercentageOfLifetime( double refreshWindowFactor, short minPeriodSeconds, short bufferSeconds, boolean clientReloginAllowedBeforeLogout) { Map<Object, Object> configs = new HashMap<>(); configs.put(SaslConfigs.SASL_LOGIN_REFRESH_WINDOW_FACTOR, refreshWindowFactor); configs.put(SaslConfigs.SASL_LOGIN_REFRESH_WINDOW_JITTER, 0); configs.put(SaslConfigs.SASL_LOGIN_REFRESH_MIN_PERIOD_SECONDS, minPeriodSeconds); configs.put(SaslConfigs.SASL_LOGIN_REFRESH_BUFFER_SECONDS, bufferSeconds); return new ExpiringCredentialRefreshConfig(new ConfigDef().withClientSaslSupport().parse(configs), clientReloginAllowedBeforeLogout); } }
@Test(expected = ConfigException.class) public void testSaslLoginRefreshWindowJitterMinValueIsReallyMinimum() { Map<Object, Object> props = new HashMap<>(); props.put(SaslConfigs.SASL_LOGIN_REFRESH_WINDOW_JITTER, "-0.000001"); new ConfigDef().withClientSaslSupport().parse(props); }
@Test(expected = ConfigException.class) public void testSaslLoginRefreshBufferSecondsMinValueIsReallyMinimum() { Map<Object, Object> props = new HashMap<>(); props.put(SaslConfigs.SASL_LOGIN_REFRESH_BUFFER_SECONDS, "-1"); new ConfigDef().withClientSaslSupport().parse(props); }
@Test public void testNestedClass() { // getName(), not getSimpleName() or getCanonicalName(), is the version that should be able to locate the class Map<String, Object> props = Collections.<String, Object>singletonMap("name", NestedClass.class.getName()); new ConfigDef().define("name", Type.CLASS, Importance.HIGH, "docs").parse(props); }
@Test(expected = ConfigException.class) public void testSaslLoginRefreshWindowFactorMinValueIsReallyMinimum() { Map<Object, Object> props = new HashMap<>(); props.put(SaslConfigs.SASL_LOGIN_REFRESH_WINDOW_FACTOR, "0.499999"); new ConfigDef().withClientSaslSupport().parse(props); }
@Test(expected = ConfigException.class) public void testSaslLoginRefreshWindowFactorMaxValueIsReallyMaximum() { Map<Object, Object> props = new HashMap<>(); props.put(SaslConfigs.SASL_LOGIN_REFRESH_WINDOW_FACTOR, "1.0001"); new ConfigDef().withClientSaslSupport().parse(props); }
@Test(expected = ConfigException.class) public void testSaslLoginRefreshWindowJitterMaxValueIsReallyMaximum() { Map<Object, Object> props = new HashMap<>(); props.put(SaslConfigs.SASL_LOGIN_REFRESH_WINDOW_JITTER, "0.251"); new ConfigDef().withClientSaslSupport().parse(props); }
@Test(expected = ConfigException.class) public void testSaslLoginRefreshMinPeriodSecondsMinValueIsReallyMinimum() { Map<Object, Object> props = new HashMap<>(); props.put(SaslConfigs.SASL_LOGIN_REFRESH_MIN_PERIOD_SECONDS, "-1"); new ConfigDef().withClientSaslSupport().parse(props); }
@Test(expected = ConfigException.class) public void testSaslLoginRefreshMinPeriodSecondsMaxValueIsReallyMaximum() { Map<Object, Object> props = new HashMap<>(); props.put(SaslConfigs.SASL_LOGIN_REFRESH_MIN_PERIOD_SECONDS, "901"); new ConfigDef().withClientSaslSupport().parse(props); }
@Test(expected = ConfigException.class) public void testSaslLoginRefreshBufferSecondsMaxValueIsReallyMaximum() { Map<Object, Object> props = new HashMap<>(); props.put(SaslConfigs.SASL_LOGIN_REFRESH_BUFFER_SECONDS, "3601"); new ConfigDef().withClientSaslSupport().parse(props); } }
@Test(expected = ConfigException.class) public void testMissingDependentConfigs() { // Should not be possible to parse a config if a dependent config has not been defined final ConfigDef configDef = new ConfigDef() .define("parent", Type.STRING, Importance.HIGH, "parent docs", "group", 1, Width.LONG, "Parent", Collections.singletonList("child")); configDef.parse(Collections.emptyMap()); }
@Test public void testBaseConfigDefDependents() { // Creating a ConfigDef based on another should compute the correct number of configs with no parent, even // if the base ConfigDef has already computed its parentless configs final ConfigDef baseConfigDef = new ConfigDef().define("a", Type.STRING, Importance.LOW, "docs"); assertEquals(new HashSet<>(Arrays.asList("a")), baseConfigDef.getConfigsWithNoParent()); final ConfigDef configDef = new ConfigDef(baseConfigDef) .define("parent", Type.STRING, Importance.HIGH, "parent docs", "group", 1, Width.LONG, "Parent", Collections.singletonList("child")) .define("child", Type.STRING, Importance.HIGH, "docs"); assertEquals(new HashSet<>(Arrays.asList("a", "parent")), configDef.getConfigsWithNoParent()); }
@Test public void testParsingEmptyDefaultValueForStringFieldShouldSucceed() { new ConfigDef().define("a", Type.STRING, "", ConfigDef.Importance.HIGH, "docs") .parse(new HashMap<String, Object>()); }
@Test(expected = ConfigException.class) public void testMissingRequired() { new ConfigDef().define("a", Type.INT, Importance.HIGH, "docs").parse(new HashMap<String, Object>()); }
@Test public void testNullDefault() { ConfigDef def = new ConfigDef().define("a", Type.INT, null, null, null, "docs"); Map<String, Object> vals = def.parse(new Properties()); assertEquals(null, vals.get("a")); }
@Test public void testNullDefaultWithValidator() { final String key = "enum_test"; ConfigDef def = new ConfigDef(); def.define(key, Type.STRING, ConfigDef.NO_DEFAULT_VALUE, ValidString.in("ONE", "TWO", "THREE"), Importance.HIGH, "docs"); Properties props = new Properties(); props.put(key, "ONE"); Map<String, Object> vals = def.parse(props); assertEquals("ONE", vals.get(key)); }
@Test public void testSaslLoginRefreshDefaults() { Map<String, Object> vals = new ConfigDef().withClientSaslSupport().parse(Collections.emptyMap()); assertEquals(SaslConfigs.DEFAULT_LOGIN_REFRESH_WINDOW_FACTOR, vals.get(SaslConfigs.SASL_LOGIN_REFRESH_WINDOW_FACTOR)); assertEquals(SaslConfigs.DEFAULT_LOGIN_REFRESH_WINDOW_JITTER, vals.get(SaslConfigs.SASL_LOGIN_REFRESH_WINDOW_JITTER)); assertEquals(SaslConfigs.DEFAULT_LOGIN_REFRESH_MIN_PERIOD_SECONDS, vals.get(SaslConfigs.SASL_LOGIN_REFRESH_MIN_PERIOD_SECONDS)); assertEquals(SaslConfigs.DEFAULT_LOGIN_REFRESH_BUFFER_SECONDS, vals.get(SaslConfigs.SASL_LOGIN_REFRESH_BUFFER_SECONDS)); }
@Test public void testCanAddInternalConfig() throws Exception { final String configName = "internal.config"; final ConfigDef configDef = new ConfigDef().defineInternal(configName, Type.STRING, "", Importance.LOW); final HashMap<String, String> properties = new HashMap<>(); properties.put(configName, "value"); final List<ConfigValue> results = configDef.validate(properties); final ConfigValue configValue = results.get(0); assertEquals("value", configValue.value()); assertEquals(configName, configValue.name()); }
@Test public void testEmptyList() { AbstractConfig conf; ConfigDef configDef = new ConfigDef().define("a", Type.LIST, "", new ConfigDef.NonNullValidator(), Importance.HIGH, "doc"); conf = new AbstractConfig(configDef, Collections.emptyMap()); assertEquals(Collections.emptyList(), conf.getList("a")); conf = new AbstractConfig(configDef, Collections.singletonMap("a", "")); assertEquals(Collections.emptyList(), conf.getList("a")); conf = new AbstractConfig(configDef, Collections.singletonMap("a", "b,c,d")); assertEquals(Arrays.asList("b", "c", "d"), conf.getList("a")); }
@Test public void testInternalConfigDoesntShowUpInDocs() throws Exception { final String name = "my.config"; final ConfigDef configDef = new ConfigDef().defineInternal(name, Type.STRING, "", Importance.LOW); assertFalse(configDef.toHtmlTable().contains("my.config")); assertFalse(configDef.toEnrichedRst().contains("my.config")); assertFalse(configDef.toRst().contains("my.config")); }