use of org.neo4j.internal.helpers.HostnamePort in project neo4j by neo4j.
the class ConnectionTrackingIT method connectSocketTo.
private TransportConnection connectSocketTo(URI uri) throws IOException {
SocketConnection connection = new SocketConnection();
connections.add(connection);
connection.connect(new HostnamePort(uri.getHost(), uri.getPort()));
return connection;
}
use of org.neo4j.internal.helpers.HostnamePort in project neo4j by neo4j.
the class DiscoveryServiceTest method init.
public void init(String description, String baseUri, Consumer<ConnectorPortRegister> portRegistryOverrider, Consumer<Config.Builder> configOverrider, String expectedBoltUri) throws URISyntaxException {
this.baseUri = new URI(baseUri);
this.dbUri = new URI("/db");
this.portRegistryOverrider = portRegistryOverrider;
this.configOverrider = configOverrider;
this.expectedDatabaseUri = this.baseUri.resolve(this.dbUri).toString();
this.expectedBoltUri = expectedBoltUri;
if (portRegistryOverrider != null) {
portRegistryOverrider.accept(portRegistry);
} else {
when(portRegistry.getLocalAddress("bolt")).thenReturn(new HostnamePort("localhost", 7687));
}
DependencyResolver dependencyResolver = mock(DependencyResolver.class);
when(dependencyResolver.resolveDependency(ConnectorPortRegister.class)).thenReturn(portRegistry);
}
use of org.neo4j.internal.helpers.HostnamePort in project neo4j by neo4j.
the class SingleInstanceGetRoutingTableProcedureTest method shouldUseClientProvidedHostAndAdvertisedPortAsAdvertisedAddress.
@RoutingConfigsTest
void shouldUseClientProvidedHostAndAdvertisedPortAsAdvertisedAddress(Config config, String clientAddress) throws Exception {
// given
var advertisedBoldPort = 8776;
var defaultBoltPort = 7687;
var advertisedBoltAddress = new SocketAddress("neo4j.com", advertisedBoldPort);
config.set(BoltConnector.advertised_address, advertisedBoltAddress);
var clientProvidedHost = clientAddress == null ? "mydomain.com" : clientAddress.split(":")[0];
var ctxContents = new MapValueBuilder();
ctxContents.add(ADDRESS_CONTEXT_KEY, Values.stringValue(clientProvidedHost));
var ctx = ctxContents.build();
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, defaultBoltPort);
// when
var result = invoke(procedure, ID, ctx);
// 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 shouldThrowIfClientProvidedPortIsNegative.
@ParameterizedTest
@EnumSource(value = RoutingMode.class)
void shouldThrowIfClientProvidedPortIsNegative(RoutingMode routingMode) {
// given
var advertisedBoldPort = 8776;
var clientProvidedPort = -5;
var advertisedBoltAddress = new SocketAddress("neo4j.com", advertisedBoldPort);
var clientProvidedHostPortStr = String.format("%s:%d", "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 SingleInstanceGetRoutingTableProcedureTest method shouldUseConfiguredAdvertisedAddressIfClientProvidedPortIsZero.
/**
* This tests a very specific non-documented behaviour - if the client provided address has the port explicitly set to zero then the returned routing table
* uses the advertised address. We make use of this behaviour in some internal tests. In "real life" we should never encounter a client provided address
* specifically set to zero so there's no particular reason to change this.
*/
@RoutingConfigsTest
void shouldUseConfiguredAdvertisedAddressIfClientProvidedPortIsZero(Config config, String clientAddress) throws Exception {
// given
var advertisedBoldPort = 8776;
var clientProvidedPort = 0;
var advertisedBoltAddress = new SocketAddress("neo4j.com", advertisedBoldPort);
config.set(BoltConnector.advertised_address, advertisedBoltAddress);
var clientProvidedHost = clientAddress == null ? "mydomain.com" : clientAddress.split(":")[0];
var clientProvidedHostPortStr = String.format("%s:%d", clientProvidedHost, clientProvidedPort);
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 = advertisedBoltAddress;
// when
RoutingResult result = invoke(procedure, clientProvidedHostPortStr);
// then
assertEquals(singletonList(expectedAddress), result.readEndpoints());
assertEquals(expectedWriters(expectedAddress), result.writeEndpoints());
assertEquals(singletonList(expectedAddress), result.routeEndpoints());
}
Aggregations