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));
}
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());
}
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());
}
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
}
}
}
}
Aggregations