Search in sources :

Example 6 with Setting

use of org.neo4j.graphdb.config.Setting in project neo4j by neo4j.

the class BoltConnectorValidatorTest method setsDeprecationFlagOnType.

@Test
public void setsDeprecationFlagOnType() throws Exception {
    Setting setting = cv.getSettingFor("dbms.connector.bolt.type", Collections.emptyMap()).orElseThrow(() -> new RuntimeException("missing setting!"));
    assertTrue(setting.deprecated());
    assertEquals(Optional.empty(), setting.replacement());
}
Also used : Setting(org.neo4j.graphdb.config.Setting) Test(org.junit.Test)

Example 7 with Setting

use of org.neo4j.graphdb.config.Setting in project neo4j by neo4j.

the class DefaultUdcInformationCollector method determineClusterNameHash.

private Integer determineClusterNameHash() {
    try {
        Class<?> settings = Class.forName("org.neo4j.cluster.ClusterSettings");
        Setting setting = (Setting) settings.getField("cluster_name").get(null);
        Object name = config.get(setting);
        return name != null ? Math.abs(name.hashCode() % Integer.MAX_VALUE) : null;
    } catch (Exception e) {
        return null;
    }
}
Also used : Setting(org.neo4j.graphdb.config.Setting) IOException(java.io.IOException)

Example 8 with Setting

use of org.neo4j.graphdb.config.Setting in project neo4j by neo4j.

the class SystemPropertiesConfiguration method apply.

public Map<String, String> apply(Map<String, String> config) {
    // Create test config with base plus system props on top
    Map<String, String> systemProperties = new HashMap<>(config);
    for (Map.Entry<Object, Object> prop : System.getProperties().entrySet()) {
        systemProperties.put(prop.getKey().toString(), prop.getValue().toString());
    }
    // For each system property, see if it passes validation
    // If so, add it to result set
    Map<String, String> result = new HashMap<String, String>(config);
    Function<String, String> systemPropertiesFunction = systemProperties::get;
    for (Map.Entry<Object, Object> prop : System.getProperties().entrySet()) {
        String key = (String) prop.getKey();
        for (Class<?> settingsClass : settingsClasses) {
            for (Field field : settingsClass.getFields()) {
                try {
                    Setting<Object> setting = (Setting<Object>) field.get(null);
                    if (setting.name().equals(key)) {
                        setting.apply(systemPropertiesFunction);
                        // Valid setting, copy it from system properties
                        result.put(key, (String) prop.getValue());
                    }
                } catch (Throwable e) {
                    continue;
                }
            }
        }
    }
    return result;
}
Also used : Field(java.lang.reflect.Field) HashMap(java.util.HashMap) Setting(org.neo4j.graphdb.config.Setting) Map(java.util.Map) HashMap(java.util.HashMap)

Example 9 with Setting

use of org.neo4j.graphdb.config.Setting in project neo4j by neo4j.

the class GraphDatabaseSettingsTest method noDuplicateSettingsAreAllowed.

@Test
public void noDuplicateSettingsAreAllowed() throws Exception {
    final HashMap<String, String> fields = new HashMap<>();
    for (Field field : GraphDatabaseSettings.class.getDeclaredFields()) {
        if (field.getType() == Setting.class) {
            Setting setting = (Setting) field.get(null);
            assertFalse(String.format("'%s' in %s has already been defined in %s", setting.name(), field.getName(), fields.get(setting.name())), fields.containsKey(setting.name()));
            fields.put(setting.name(), field.getName());
        }
    }
}
Also used : Field(java.lang.reflect.Field) HashMap(java.util.HashMap) Setting(org.neo4j.graphdb.config.Setting) Test(org.junit.Test)

Example 10 with Setting

use of org.neo4j.graphdb.config.Setting in project neo4j by neo4j.

the class BoltConnectorValidatorTest method setsDeprecationFlagOnCustomNamedBoltConnectors.

@Test
public void setsDeprecationFlagOnCustomNamedBoltConnectors() throws Exception {
    List<Setting<Object>> settings = cv.settings(stringMap("dbms.connector.0.type", "BOLT", "dbms.connector.0.enabled", "false", "dbms.connector.0.listen_address", "1.2.3.4:123", "dbms.connector.0.advertised_address", "localhost:123", "dbms.connector.0.tls_level", EncryptionLevel.OPTIONAL.toString()));
    assertEquals(5, settings.size());
    for (Setting s : settings) {
        assertTrue("every setting should be deprecated: " + s.name(), s.deprecated());
        String[] parts = s.name().split("\\.");
        if (!"type".equals(parts[3])) {
            assertEquals(Optional.of(format("%s.%s.%s.%s", parts[0], parts[1], "bolt", parts[3])), s.replacement());
        }
    }
}
Also used : Setting(org.neo4j.graphdb.config.Setting) Test(org.junit.Test)

Aggregations

Setting (org.neo4j.graphdb.config.Setting)15 Test (org.junit.Test)10 HashMap (java.util.HashMap)4 Field (java.lang.reflect.Field)2 Map (java.util.Map)2 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)2 IOException (java.io.IOException)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Statement (org.junit.runners.model.Statement)1 Authentication (org.neo4j.bolt.security.auth.Authentication)1 BasicAuthentication (org.neo4j.bolt.security.auth.BasicAuthentication)1 BoltFactoryImpl (org.neo4j.bolt.v1.runtime.BoltFactoryImpl)1 BoltStateMachine (org.neo4j.bolt.v1.runtime.BoltStateMachine)1 DependencyResolver (org.neo4j.graphdb.DependencyResolver)1 GraphDatabaseBuilder (org.neo4j.graphdb.factory.GraphDatabaseBuilder)1 MapUtil.stringMap (org.neo4j.helpers.collection.MapUtil.stringMap)1 AuthManager (org.neo4j.kernel.api.security.AuthManager)1 UserManagerSupplier (org.neo4j.kernel.api.security.UserManagerSupplier)1 TestGraphDatabaseBuilder (org.neo4j.test.TestGraphDatabaseBuilder)1 UsageData (org.neo4j.udc.UsageData)1