use of com.hazelcast.config.properties.SimplePropertyDefinition in project hazelcast by hazelcast.
the class DiscoverySpiTest method test_AbstractDiscoveryStrategy_getOrNull.
@Test
public void test_AbstractDiscoveryStrategy_getOrNull() throws Exception {
PropertyDefinition first = new SimplePropertyDefinition("first", PropertyTypeConverter.STRING);
PropertyDefinition second = new SimplePropertyDefinition("second", BOOLEAN);
PropertyDefinition third = new SimplePropertyDefinition("third", PropertyTypeConverter.INTEGER);
PropertyDefinition fourth = new SimplePropertyDefinition("fourth", true, PropertyTypeConverter.STRING);
PropertyDefinition onlyInEnv = new SimplePropertyDefinition("only_in_env", true, PropertyTypeConverter.INTEGER);
Map<String, Comparable> properties = new HashMap<>();
properties.put("first", "value-first");
properties.put("second", Boolean.FALSE);
properties.put("third", 100);
Map<String, String> environmentVariables = new HashMap<>();
// system property > system environment > configuration
// property 'first' => "value-first"
// property 'second' => true
environmentVariables.put("test.second", "true");
// property 'third' => 300
environmentVariables.put("test.third", "200");
System.setProperty("test.third", "300");
// property 'fourth' => null
environmentVariables.put("test.only_in_env", "500");
PropertyDiscoveryStrategy strategy = new PropertyDiscoveryStrategy(LOGGER, properties, environmentVariables::get);
// without lookup of environment
assertEquals("value-first", strategy.getOrNull(first));
assertEquals(Boolean.FALSE, strategy.getOrNull(second));
assertEquals(100, ((Integer) strategy.getOrNull(third)).intValue());
assertNull(strategy.getOrNull(fourth));
assertEquals("value-first", strategy.getOrNull("test", first));
assertEquals(Boolean.TRUE, strategy.getOrNull("test", second));
assertEquals(300, ((Integer) strategy.getOrNull("test", third)).intValue());
assertNull(strategy.getOrNull("test", fourth));
assertEquals(500, ((Integer) strategy.getOrNull("test", onlyInEnv)).intValue());
}
use of com.hazelcast.config.properties.SimplePropertyDefinition in project hazelcast by hazelcast.
the class DiscoverySpiTest method test_AbstractDiscoveryStrategy_getOrDefault.
@Test
public void test_AbstractDiscoveryStrategy_getOrDefault() throws Exception {
PropertyDefinition value = new SimplePropertyDefinition("value", PropertyTypeConverter.INTEGER);
Map<String, Comparable> properties = Collections.emptyMap();
PropertyDiscoveryStrategy strategy = new PropertyDiscoveryStrategy(LOGGER, properties);
assertEquals(1111, (long) strategy.getOrDefault(value, 1111));
assertEquals(1111, (long) strategy.getOrDefault("test", value, 1111));
}
use of com.hazelcast.config.properties.SimplePropertyDefinition in project hazelcast by hazelcast.
the class DiscoveryServicePropertiesUtilTest method nullProperty.
@Test
public void nullProperty() {
// given
Map<String, Comparable> properties = new HashMap<>(singletonMap(PROPERTY_KEY_1, null));
TypeConverter typeConverter = new TypeConverter() {
@Override
public Comparable convert(Comparable value) {
return value == null ? "hazel" : "cast";
}
};
Collection<PropertyDefinition> propertyDefinitions = singletonList((PropertyDefinition) new SimplePropertyDefinition(PROPERTY_KEY_1, true, typeConverter));
// when
Map<String, Comparable> result = prepareProperties(properties, propertyDefinitions);
// then
assertEquals("hazel", result.get(PROPERTY_KEY_1));
}
use of com.hazelcast.config.properties.SimplePropertyDefinition in project hazelcast by hazelcast.
the class DiscoveryServicePropertiesUtilTest method correctDashlessPropertyConversion.
@Test
public void correctDashlessPropertyConversion() {
// given
Map<String, Comparable> properties = new HashMap<>(singletonMap("customproperty", PROPERTY_VALUE_1));
Collection<PropertyDefinition> propertyDefinitions = singletonList(new SimplePropertyDefinition("custom-property", STRING));
// when
Map<String, Comparable> result = prepareProperties(properties, propertyDefinitions);
// then
assertEquals(PROPERTY_VALUE_1, result.get("custom-property"));
}
use of com.hazelcast.config.properties.SimplePropertyDefinition in project hazelcast by hazelcast.
the class DiscoveryServicePropertiesUtilTest method invalidProperty.
@Test(expected = ValidationException.class)
public void invalidProperty() {
// given
Map<String, Comparable> properties = new HashMap<>(singletonMap(PROPERTY_KEY_1, (Comparable) PROPERTY_VALUE_1));
ValueValidator<String> valueValidator = mock(ValueValidator.class);
willThrow(new ValidationException("Invalid property")).given(valueValidator).validate(PROPERTY_VALUE_1);
Collection<PropertyDefinition> propertyDefinitions = singletonList((PropertyDefinition) new SimplePropertyDefinition(PROPERTY_KEY_1, false, STRING, new DummyValidator()));
// when
prepareProperties(properties, propertyDefinitions);
// then
// throw exception
}
Aggregations