Search in sources :

Example 1 with HostnamePort

use of org.neo4j.internal.helpers.HostnamePort in project neo4j by neo4j.

the class SettingTest method testHostnamePort.

@Test
void testHostnamePort() {
    var setting = (SettingImpl<HostnamePort>) setting("setting", HOSTNAME_PORT);
    assertEquals(new HostnamePort("localhost", 7474), setting.parse("localhost:7474"));
    assertEquals(new HostnamePort("localhost", 1000, 2000), setting.parse("localhost:1000-2000"));
    assertEquals(new HostnamePort("localhost"), setting.parse("localhost"));
    assertThrows(IllegalArgumentException.class, () -> setting.parse("localhost:5641:7474"));
    assertThrows(IllegalArgumentException.class, () -> setting.parse("localhost:foo"));
    assertThrows(IllegalArgumentException.class, () -> setting.parse("7474:localhost"));
}
Also used : HostnamePort(org.neo4j.internal.helpers.HostnamePort) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 2 with HostnamePort

use of org.neo4j.internal.helpers.HostnamePort in project neo4j by neo4j.

the class ConnectorPortRegisterTest method verifyAddress.

private void verifyAddress(String key, String expectedHostname, int expectedPort) {
    HostnamePort expectedAddress = new HostnamePort(expectedHostname, expectedPort);
    assertEquals(expectedAddress, portRegister.getLocalAddress(key));
}
Also used : HostnamePort(org.neo4j.internal.helpers.HostnamePort)

Example 3 with HostnamePort

use of org.neo4j.internal.helpers.HostnamePort 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 4 with HostnamePort

use of org.neo4j.internal.helpers.HostnamePort 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 5 with HostnamePort

use of org.neo4j.internal.helpers.HostnamePort in project neo4j by neo4j.

the class InProcessServerBuilderIT method shouldOpenBoltPort.

@Test
void shouldOpenBoltPort() {
    // given
    try (Neo4j neo4j = getTestBuilder(directory.homePath()).build()) {
        URI uri = neo4j.boltURI();
        // when
        assertDoesNotThrow(() -> new SocketConnection().connect(new HostnamePort(uri.getHost(), uri.getPort())));
    }
}
Also used : SocketConnection(org.neo4j.bolt.testing.client.SocketConnection) HostnamePort(org.neo4j.internal.helpers.HostnamePort) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Aggregations

HostnamePort (org.neo4j.internal.helpers.HostnamePort)18 Test (org.junit.jupiter.api.Test)7 SocketAddress (org.neo4j.configuration.helpers.SocketAddress)5 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)5 SocketConnection (org.neo4j.bolt.testing.client.SocketConnection)4 InputStream (java.io.InputStream)3 Socket (java.net.Socket)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 MapValueBuilder (org.neo4j.values.virtual.MapValueBuilder)3 URI (java.net.URI)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 DynamicTest (org.junit.jupiter.api.DynamicTest)1 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)1 DependencyResolver (org.neo4j.common.DependencyResolver)1