Search in sources :

Example 1 with SimplePropertyDefinition

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());
}
Also used : SimplePropertyDefinition(com.hazelcast.config.properties.SimplePropertyDefinition) HashMap(java.util.HashMap) SimplePropertyDefinition(com.hazelcast.config.properties.SimplePropertyDefinition) PropertyDefinition(com.hazelcast.config.properties.PropertyDefinition) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with SimplePropertyDefinition

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));
}
Also used : SimplePropertyDefinition(com.hazelcast.config.properties.SimplePropertyDefinition) SimplePropertyDefinition(com.hazelcast.config.properties.SimplePropertyDefinition) PropertyDefinition(com.hazelcast.config.properties.PropertyDefinition) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with SimplePropertyDefinition

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));
}
Also used : TypeConverter(com.hazelcast.core.TypeConverter) SimplePropertyDefinition(com.hazelcast.config.properties.SimplePropertyDefinition) HashMap(java.util.HashMap) SimplePropertyDefinition(com.hazelcast.config.properties.SimplePropertyDefinition) PropertyDefinition(com.hazelcast.config.properties.PropertyDefinition) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with SimplePropertyDefinition

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"));
}
Also used : SimplePropertyDefinition(com.hazelcast.config.properties.SimplePropertyDefinition) HashMap(java.util.HashMap) SimplePropertyDefinition(com.hazelcast.config.properties.SimplePropertyDefinition) PropertyDefinition(com.hazelcast.config.properties.PropertyDefinition) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with SimplePropertyDefinition

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
}
Also used : ValidationException(com.hazelcast.config.properties.ValidationException) SimplePropertyDefinition(com.hazelcast.config.properties.SimplePropertyDefinition) HashMap(java.util.HashMap) SimplePropertyDefinition(com.hazelcast.config.properties.SimplePropertyDefinition) PropertyDefinition(com.hazelcast.config.properties.PropertyDefinition) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

PropertyDefinition (com.hazelcast.config.properties.PropertyDefinition)5 SimplePropertyDefinition (com.hazelcast.config.properties.SimplePropertyDefinition)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 ValidationException (com.hazelcast.config.properties.ValidationException)1 TypeConverter (com.hazelcast.core.TypeConverter)1