Search in sources :

Example 6 with SocketAddress

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

Example 7 with SocketAddress

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

Example 8 with SocketAddress

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

Example 9 with SocketAddress

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);
}
Also used : MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder) 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 10 with SocketAddress

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

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