use of org.neo4j.configuration.helpers.SocketAddress 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.configuration.helpers.SocketAddress in project neo4j by neo4j.
the class SimpleClientRoutingDomainCheckerTest method shouldRespondToConfigChanges.
@Test
void shouldRespondToConfigChanges() {
// given
String clientRoutingDomain = "foo.com";
Config config = Config.defaults();
var checker = checkerFromConfig(config);
SocketAddress socketAddress = SocketAddressParser.socketAddress(clientRoutingDomain, SocketAddress::new);
// then
assertTrue(checker.isEmpty());
assertFalse(checker.shouldGetClientRouting(socketAddress));
// when
config.setDynamic(GraphDatabaseSettings.client_side_router_enforce_for_domains, Set.of(clientRoutingDomain), this.getClass().getName());
// then
assertFalse(checker.isEmpty());
assertTrue(checker.shouldGetClientRouting(socketAddress));
// when
config.setDynamic(GraphDatabaseSettings.client_side_router_enforce_for_domains, Set.of(), this.getClass().getName());
// then
assertTrue(checker.isEmpty());
assertFalse(checker.shouldGetClientRouting(socketAddress));
}
use of org.neo4j.configuration.helpers.SocketAddress in project neo4j by neo4j.
the class RoutingResultFormatTest method shouldSerializeToAndFromRecordFormat.
@Test
void shouldSerializeToAndFromRecordFormat() {
// given
List<SocketAddress> writers = asList(new SocketAddress("write", 1), new SocketAddress("write", 2), new SocketAddress("write", 3));
List<SocketAddress> readers = asList(new SocketAddress("read", 4), new SocketAddress("read", 5), new SocketAddress("read", 6), new SocketAddress("read", 7));
List<SocketAddress> routers = singletonList(new SocketAddress("route", 8));
long ttlSeconds = 5;
RoutingResult original = new RoutingResult(routers, writers, readers, ttlSeconds * 1000);
// when
AnyValue[] record = RoutingResultFormat.build(original);
// then
RoutingResult parsed = RoutingResultFormat.parse(record);
assertEquals(original, parsed);
}
use of org.neo4j.configuration.helpers.SocketAddress in project neo4j by neo4j.
the class DiscoverableURIsTest method shouldSetBoltHostAndPortWithDefaultAdvertisedAddress.
@Test
void shouldSetBoltHostAndPortWithDefaultAdvertisedAddress() {
var config = Config.newBuilder().set(Map.of(BoltConnector.enabled, true, GraphDatabaseSettings.default_advertised_address, new SocketAddress("myCat.com"))).build();
var discoverables = new DiscoverableURIs.Builder().addBoltEndpoint(config, portRegister).build();
discoverables.forEach(consumer);
verify(consumer).accept("bolt_direct", "bolt://myCat.com:7687");
verify(consumer).accept("bolt_routing", "neo4j://myCat.com:7687");
}
use of org.neo4j.configuration.helpers.SocketAddress in project neo4j by neo4j.
the class DiscoverableURIsTest method shouldSetBoltHostWhenHostIsExplicitlySet.
@Test
void shouldSetBoltHostWhenHostIsExplicitlySet() {
var config = Config.newBuilder().set(Map.of(BoltConnector.enabled, true, BoltConnector.advertised_address, new SocketAddress("myCat.com", 1234))).build();
var discoverables = new DiscoverableURIs.Builder().addBoltEndpoint(config, portRegister).build();
discoverables.forEach(consumer);
verify(consumer).accept("bolt_direct", "bolt://myCat.com:1234");
verify(consumer).accept("bolt_routing", "neo4j://myCat.com:1234");
}
Aggregations