Search in sources :

Example 51 with SocketAddress

use of org.neo4j.configuration.helpers.SocketAddress in project neo4j by neo4j.

the class GraphDatabaseSettingsTest method testServerDefaultSettings.

@Test
void testServerDefaultSettings() {
    // given
    Config config = Config.newBuilder().setDefaults(GraphDatabaseSettings.SERVER_DEFAULTS).build();
    // then
    assertEquals(new SocketAddress("localhost", 7474), config.get(HttpConnector.listen_address));
    assertEquals(new SocketAddress("localhost", 7473), config.get(HttpsConnector.listen_address));
    assertEquals(new SocketAddress("localhost", 7687), config.get(BoltConnector.listen_address));
    assertTrue(config.get(HttpConnector.enabled));
    assertFalse(config.get(HttpsConnector.enabled));
    assertTrue(config.get(BoltConnector.enabled));
}
Also used : SocketAddress(org.neo4j.configuration.helpers.SocketAddress) Test(org.junit.jupiter.api.Test)

Example 52 with SocketAddress

use of org.neo4j.configuration.helpers.SocketAddress in project neo4j by neo4j.

the class SettingMigratorsTest method testAddrMigration.

private static void testAddrMigration(Setting<SocketAddress> listenAddr, Setting<SocketAddress> advertisedAddr) {
    Config config1 = Config.newBuilder().setRaw(Map.of(listenAddr.name(), "foo:111")).build();
    Config config2 = Config.newBuilder().setRaw(Map.of(listenAddr.name(), ":222")).build();
    Config config3 = Config.newBuilder().setRaw(Map.of(listenAddr.name(), ":333", advertisedAddr.name(), "bar")).build();
    Config config4 = Config.newBuilder().setRaw(Map.of(listenAddr.name(), "foo:444", advertisedAddr.name(), ":555")).build();
    Config config5 = Config.newBuilder().setRaw(Map.of(listenAddr.name(), "foo", advertisedAddr.name(), "bar")).build();
    Config config6 = Config.newBuilder().setRaw(Map.of(listenAddr.name(), "foo:666", advertisedAddr.name(), "bar:777")).build();
    var logProvider = new AssertableLogProvider();
    config1.setLogger(logProvider.getLog(Config.class));
    config2.setLogger(logProvider.getLog(Config.class));
    config3.setLogger(logProvider.getLog(Config.class));
    config4.setLogger(logProvider.getLog(Config.class));
    config5.setLogger(logProvider.getLog(Config.class));
    config6.setLogger(logProvider.getLog(Config.class));
    assertEquals(new SocketAddress("localhost", 111), config1.get(advertisedAddr));
    assertEquals(new SocketAddress("localhost", 222), config2.get(advertisedAddr));
    assertEquals(new SocketAddress("bar", 333), config3.get(advertisedAddr));
    assertEquals(new SocketAddress("localhost", 555), config4.get(advertisedAddr));
    assertEquals(new SocketAddress("bar", advertisedAddr.defaultValue().getPort()), config5.get(advertisedAddr));
    assertEquals(new SocketAddress("bar", 777), config6.get(advertisedAddr));
    String msg = "Note that since you did not explicitly set the port in %s Neo4j automatically set it to %s to match %s." + " This behavior may change in the future and we recommend you to explicitly set it.";
    var warnMatcher = assertThat(logProvider).forClass(Config.class).forLevel(WARN);
    var infoMatcher = assertThat(logProvider).forClass(Config.class).forLevel(INFO);
    infoMatcher.containsMessageWithArguments(msg, advertisedAddr.name(), 111, listenAddr.name());
    infoMatcher.containsMessageWithArguments(msg, advertisedAddr.name(), 222, listenAddr.name());
    warnMatcher.containsMessageWithArguments(msg, advertisedAddr.name(), 333, listenAddr.name());
    warnMatcher.doesNotContainMessageWithArguments(msg, advertisedAddr.name(), 444, listenAddr.name());
    infoMatcher.doesNotContainMessageWithArguments(msg, advertisedAddr.name(), 555, listenAddr.name());
    warnMatcher.doesNotContainMessageWithArguments(msg, advertisedAddr.name(), 666, listenAddr.name());
}
Also used : SslPolicyConfig(org.neo4j.configuration.ssl.SslPolicyConfig) SocketAddress(org.neo4j.configuration.helpers.SocketAddress) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider)

Example 53 with SocketAddress

use of org.neo4j.configuration.helpers.SocketAddress in project neo4j by neo4j.

the class ConnectorPortRegisterTest method shouldRegisterSocketAddress.

@Test
void shouldRegisterSocketAddress() {
    SocketAddress address = new SocketAddress("neo4j.com", 12345);
    portRegister.register("key", address);
    verifyAddress("key", address.getHostname(), address.getPort());
}
Also used : SocketAddress(org.neo4j.configuration.helpers.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.jupiter.api.Test)

Example 54 with SocketAddress

use of org.neo4j.configuration.helpers.SocketAddress in project neo4j by neo4j.

the class SettingMigrators method migrateAdvertisedAddressInheritanceChange.

public static void migrateAdvertisedAddressInheritanceChange(Map<String, String> values, Map<String, String> defaultValues, Log log, String listenAddress, String advertisedAddress) {
    String listenValue = values.get(listenAddress);
    if (isNotBlank(listenValue)) {
        String advertisedValue = values.get(advertisedAddress);
        boolean advertisedAlreadyHasPort = false;
        try {
            if (isNotBlank(advertisedValue)) {
                advertisedAlreadyHasPort = SOCKET_ADDRESS.parse(advertisedValue).getPort() >= 0;
            }
        } catch (RuntimeException e) {
        // If we cant parse the advertised address we act as if it has no port specified
        // If invalid hostname config will report the error
        }
        if (!advertisedAlreadyHasPort) {
            try {
                int port = SOCKET_ADDRESS.parse(listenValue).getPort();
                if (// valid port on listen, and none on advertised, migrate!
                port >= 0) {
                    SocketAddress newAdvertised = new SocketAddress(advertisedValue, port);
                    String msg = "Note that since you did not explicitly set the port in %s Neo4j automatically set it to %s to match %s." + " This behavior may change in the future and we recommend you to explicitly set it.";
                    if (isNotBlank(advertisedValue)) {
                        // If advertised has an address set (not inherited or default value we treat this as a warning, since is is likely to be used.
                        log.warn(msg, advertisedAddress, port, listenAddress);
                    } else {
                        // No value was set, likely the user does not care or won't use this. Just provide the info
                        log.info(msg, advertisedAddress, port, listenAddress);
                    }
                    defaultValues.put(advertisedAddress, newAdvertised.toString());
                }
            } catch (RuntimeException e) {
            // If we cant parse the listen address we have no information on how to proceed with the migration
            // The config will handle the error later
            }
        }
    }
}
Also used : SocketAddress(org.neo4j.configuration.helpers.SocketAddress)

Aggregations

SocketAddress (org.neo4j.configuration.helpers.SocketAddress)54 Test (org.junit.jupiter.api.Test)27 InetSocketAddress (java.net.InetSocketAddress)12 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)11 Test (org.junit.Test)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 HostnamePort (org.neo4j.internal.helpers.HostnamePort)5 MapValueBuilder (org.neo4j.values.virtual.MapValueBuilder)5 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 SslPolicyConfig (org.neo4j.configuration.ssl.SslPolicyConfig)4 BeforeEach (org.junit.jupiter.api.BeforeEach)3 EnterpriseDatabaseManagementServiceBuilder (com.neo4j.dbms.api.EnterpriseDatabaseManagementServiceBuilder)2 IOException (java.io.IOException)2 ServerSocket (java.net.ServerSocket)2 HashMap (java.util.HashMap)2 DynamicTest (org.junit.jupiter.api.DynamicTest)2 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)2 Config (org.neo4j.configuration.Config)2 ConnectorPortRegister (org.neo4j.configuration.connectors.ConnectorPortRegister)2 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)2