Search in sources :

Example 11 with SocketAddress

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);
}
Also used : MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder) HostnamePort(org.neo4j.internal.helpers.HostnamePort) SocketAddress(org.neo4j.configuration.helpers.SocketAddress) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with SocketAddress

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));
}
Also used : Config(org.neo4j.configuration.Config) SocketAddress(org.neo4j.configuration.helpers.SocketAddress) Test(org.junit.jupiter.api.Test)

Example 13 with 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);
}
Also used : AnyValue(org.neo4j.values.AnyValue) SocketAddress(org.neo4j.configuration.helpers.SocketAddress) Test(org.junit.jupiter.api.Test)

Example 14 with SocketAddress

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");
}
Also used : SocketAddress(org.neo4j.configuration.helpers.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.jupiter.api.Test)

Example 15 with SocketAddress

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");
}
Also used : SocketAddress(org.neo4j.configuration.helpers.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.jupiter.api.Test)

Aggregations

SocketAddress (org.neo4j.configuration.helpers.SocketAddress)54 Test (org.junit.jupiter.api.Test)27 InetSocketAddress (java.net.InetSocketAddress)12 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)11 Test (org.junit.Test)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 HostnamePort (org.neo4j.internal.helpers.HostnamePort)5 MapValueBuilder (org.neo4j.values.virtual.MapValueBuilder)5 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 SslPolicyConfig (org.neo4j.configuration.ssl.SslPolicyConfig)4 BeforeEach (org.junit.jupiter.api.BeforeEach)3 EnterpriseDatabaseManagementServiceBuilder (com.neo4j.dbms.api.EnterpriseDatabaseManagementServiceBuilder)2 IOException (java.io.IOException)2 ServerSocket (java.net.ServerSocket)2 HashMap (java.util.HashMap)2 DynamicTest (org.junit.jupiter.api.DynamicTest)2 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)2 Config (org.neo4j.configuration.Config)2 ConnectorPortRegister (org.neo4j.configuration.connectors.ConnectorPortRegister)2 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)2