use of org.neo4j.internal.helpers.HostnamePort in project neo4j by neo4j.
the class SettingTest method testHostnamePort.
@Test
void testHostnamePort() {
var setting = (SettingImpl<HostnamePort>) setting("setting", HOSTNAME_PORT);
assertEquals(new HostnamePort("localhost", 7474), setting.parse("localhost:7474"));
assertEquals(new HostnamePort("localhost", 1000, 2000), setting.parse("localhost:1000-2000"));
assertEquals(new HostnamePort("localhost"), setting.parse("localhost"));
assertThrows(IllegalArgumentException.class, () -> setting.parse("localhost:5641:7474"));
assertThrows(IllegalArgumentException.class, () -> setting.parse("localhost:foo"));
assertThrows(IllegalArgumentException.class, () -> setting.parse("7474:localhost"));
}
use of org.neo4j.internal.helpers.HostnamePort in project neo4j by neo4j.
the class ConnectorPortRegisterTest method verifyAddress.
private void verifyAddress(String key, String expectedHostname, int expectedPort) {
HostnamePort expectedAddress = new HostnamePort(expectedHostname, expectedPort);
assertEquals(expectedAddress, portRegister.getLocalAddress(key));
}
use of org.neo4j.internal.helpers.HostnamePort in project neo4j by neo4j.
the class SingleInstanceGetRoutingTableProcedureTest method whenServerRoutingEnabledShouldUseClientProvidedHostAndDefaultPortAsAdvertisedAddress.
@Test
void whenServerRoutingEnabledShouldUseClientProvidedHostAndDefaultPortAsAdvertisedAddress() throws Exception {
// given
var advertisedBoldPort = 8776;
var advertisedBoltAddress = new SocketAddress("neo4j.com", advertisedBoldPort);
var clientProvidedHost = "my.neo4j-service.com";
var config = newConfig(Config.defaults(SERVER_DEFAULTS), Duration.ofSeconds(100), advertisedBoltAddress);
config.set(GraphDatabaseSettings.routing_default_router, GraphDatabaseSettings.RoutingMode.SERVER);
var portRegister = mock(ConnectorPortRegister.class);
when(portRegister.getLocalAddress(BoltConnector.NAME)).thenReturn(new HostnamePort("neo4j.com", advertisedBoldPort));
var databaseManager = databaseManagerMock(config, true);
var logProvider = new AssertableLogProvider();
var procedure = newProcedure(databaseManager, portRegister, config, logProvider);
var expectedAddress = new SocketAddress(clientProvidedHost, 7687);
// when
RoutingResult result = invoke(procedure, clientProvidedHost);
// then
assertEquals(singletonList(expectedAddress), result.readEndpoints());
assertEquals(expectedWriters(expectedAddress), result.writeEndpoints());
assertEquals(singletonList(expectedAddress), result.routeEndpoints());
}
use of org.neo4j.internal.helpers.HostnamePort in project neo4j by neo4j.
the class SingleInstanceGetRoutingTableProcedureTest method shouldThrowIfClientProvidedPortIsNotANumber.
@ParameterizedTest
@EnumSource(value = RoutingMode.class)
void shouldThrowIfClientProvidedPortIsNotANumber(RoutingMode routingMode) {
// given
var advertisedBoldPort = 8776;
var clientProvidedPort = "bolt";
var advertisedBoltAddress = new SocketAddress("neo4j.com", advertisedBoldPort);
var clientProvidedHostPortStr = String.format("%s:%s", "my.neo4j-service.com", clientProvidedPort);
var ctxContents = new MapValueBuilder();
ctxContents.add(ADDRESS_CONTEXT_KEY, Values.stringValue(clientProvidedHostPortStr));
var ctx = ctxContents.build();
var portRegister = mock(ConnectorPortRegister.class);
when(portRegister.getLocalAddress(BoltConnector.NAME)).thenReturn(new HostnamePort("neo4j.com", advertisedBoldPort));
var config = newConfig(Config.defaults(SERVER_DEFAULTS), Duration.ofSeconds(100), advertisedBoltAddress);
config.set(routing_default_router, routingMode);
var databaseManager = databaseManagerMock(config, true);
var logProvider = new AssertableLogProvider();
var procedure = newProcedure(databaseManager, portRegister, config, logProvider);
var expectedMessage = "An address key is included in the query string provided to the GetRoutingTableProcedure, but its value could not be parsed.";
// when
assertThrows(ProcedureException.class, () -> invoke(procedure, ID, ctx), expectedMessage);
}
use of org.neo4j.internal.helpers.HostnamePort in project neo4j by neo4j.
the class InProcessServerBuilderIT method shouldOpenBoltPort.
@Test
void shouldOpenBoltPort() {
// given
try (Neo4j neo4j = getTestBuilder(directory.homePath()).build()) {
URI uri = neo4j.boltURI();
// when
assertDoesNotThrow(() -> new SocketConnection().connect(new HostnamePort(uri.getHost(), uri.getPort())));
}
}
Aggregations