use of org.neo4j.configuration.helpers.SocketAddress in project neo4j by neo4j.
the class ConnectorPortRegisterTest method shouldReturnAddressByKey.
@Test
void shouldReturnAddressByKey() {
SocketAddress address1 = new SocketAddress("localhost", 7574);
SocketAddress address2 = new SocketAddress("neo4j.com", 8989);
SocketAddress address3 = new SocketAddress("8.8.8.8", 80);
portRegister.register("key1", address1);
portRegister.register("key2", address2);
portRegister.register("key3", address3);
verifyAddress("key1", "localhost", 7574);
verifyAddress("key2", "neo4j.com", 8989);
verifyAddress("key3", "8.8.8.8", 80);
}
use of org.neo4j.configuration.helpers.SocketAddress in project neo4j by neo4j.
the class ConnectorPortRegisterTest method shouldDeregister.
@Test
void shouldDeregister() {
SocketAddress address = new SocketAddress("neo4j.com", 42);
portRegister.register("key", address);
assertNotNull(portRegister.getLocalAddress("key"));
portRegister.deregister("key");
assertNull(portRegister.getLocalAddress("key"));
}
use of org.neo4j.configuration.helpers.SocketAddress 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.configuration.helpers.SocketAddress in project neo4j by neo4j.
the class SingleInstanceGetRoutingTableProcedureTest method shouldThrowWhenHostCtxIsInvalid.
@ParameterizedTest
@EnumSource(value = RoutingMode.class)
void shouldThrowWhenHostCtxIsInvalid(RoutingMode routingMode) {
// given
var ctxContents = new MapValueBuilder();
ctxContents.add(ADDRESS_CONTEXT_KEY, Values.stringValue("not a socket address"));
var ctx = ctxContents.build();
var config = newConfig(Config.defaults(SERVER_DEFAULTS), Duration.ofSeconds(100), new SocketAddress("neo4j.com", 7687));
config.set(routing_default_router, routingMode);
var portRegister = mock(ConnectorPortRegister.class);
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/then
assertThrows(ProcedureException.class, () -> invoke(procedure, ID, ctx), expectedMessage);
}
use of org.neo4j.configuration.helpers.SocketAddress in project neo4j by neo4j.
the class SingleInstanceGetRoutingTableProcedureTest method shouldReturnRoutingTable.
@RoutingConfigsTest
void shouldReturnRoutingTable(Config config, String clientAddress) throws Exception {
var portRegister = mock(ConnectorPortRegister.class);
config = newConfig(config, Duration.ofMinutes(42), new SocketAddress("neo4j.com", 7687));
var proc = newProcedure(portRegister, config);
var result = invoke(proc, clientAddress);
assertEquals(Duration.ofMinutes(42).toMillis(), result.ttlMillis());
var address = clientAddress != null ? socketAddressFor(clientAddress) : new SocketAddress("neo4j.com", 7687);
assertEquals(singletonList(address), result.readEndpoints());
assertEquals(expectedWriters(address), result.writeEndpoints());
assertEquals(singletonList(address), result.routeEndpoints());
}
Aggregations