Search in sources :

Example 36 with SocketAddress

use of org.neo4j.configuration.helpers.SocketAddress in project neo4j by neo4j.

the class CommunityDiscoverableURIsTest method shouldLookupBoltPortInRegisterIfConfigured.

@Test
void shouldLookupBoltPortInRegisterIfConfigured() {
    var register = new ConnectorPortRegister();
    register.register(BoltConnector.NAME, new InetSocketAddress(1337));
    var uris = communityDiscoverableURIs(Config.newBuilder().set(BoltConnector.advertised_address, new SocketAddress("apple.com", 0)).set(BoltConnector.enabled, true).build(), register);
    var map = toMap(uris);
    assertEquals("bolt://apple.com:1337", map.get("bolt_direct"));
    assertEquals("neo4j://apple.com:1337", map.get("bolt_routing"));
}
Also used : ConnectorPortRegister(org.neo4j.configuration.connectors.ConnectorPortRegister) InetSocketAddress(java.net.InetSocketAddress) SocketAddress(org.neo4j.configuration.helpers.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.jupiter.api.Test)

Example 37 with SocketAddress

use of org.neo4j.configuration.helpers.SocketAddress in project neo4j by neo4j.

the class SimpleUriBuilderTest method shouldIncludeScheme.

@Test
void shouldIncludeScheme() {
    var uri1 = SimpleUriBuilder.buildURI(new SocketAddress("neo4j.example.org", 443), false);
    var uri2 = SimpleUriBuilder.buildURI(new SocketAddress("neo4j.example.org", 80), true);
    assertEquals("http", uri1.getScheme());
    assertEquals("https", uri2.getScheme());
}
Also used : SocketAddress(org.neo4j.configuration.helpers.SocketAddress) Test(org.junit.jupiter.api.Test)

Example 38 with SocketAddress

use of org.neo4j.configuration.helpers.SocketAddress in project neo4j by neo4j.

the class SimpleUriBuilderTest method shouldIncludePortWhenNecessary.

@Test
void shouldIncludePortWhenNecessary() {
    var uri1 = SimpleUriBuilder.buildURI(new SocketAddress("neo4j.example.org", 80), false);
    var uri2 = SimpleUriBuilder.buildURI(new SocketAddress("neo4j.example.org", 443), true);
    var uri3 = SimpleUriBuilder.buildURI(new SocketAddress("neo4j.example.org", 443), false);
    var uri4 = SimpleUriBuilder.buildURI(new SocketAddress("neo4j.example.org", 80), true);
    var uri5 = SimpleUriBuilder.buildURI(new SocketAddress("neo4j.example.org", 7690), false);
    assertEquals(-1, uri1.getPort());
    assertEquals(-1, uri2.getPort());
    assertEquals(443, uri3.getPort());
    assertEquals(80, uri4.getPort());
    assertEquals(7690, uri5.getPort());
}
Also used : SocketAddress(org.neo4j.configuration.helpers.SocketAddress) Test(org.junit.jupiter.api.Test)

Example 39 with SocketAddress

use of org.neo4j.configuration.helpers.SocketAddress in project neo4j by neo4j.

the class Jetty9WebServerIT method shouldBeAbleToRestart.

@Test
public void shouldBeAbleToRestart() throws Throwable {
    // given
    webServer = new Jetty9WebServer(NullLogProvider.getInstance(), Config.defaults(), NetworkConnectionTracker.NO_OP, mock(ByteBufferPool.class));
    webServer.setHttpAddress(new SocketAddress("127.0.0.1", 7878));
    // when
    webServer.start();
    webServer.stop();
    webServer.start();
// then no exception
}
Also used : Jetty9WebServer(org.neo4j.server.web.Jetty9WebServer) SocketAddress(org.neo4j.configuration.helpers.SocketAddress) Test(org.junit.Test)

Example 40 with SocketAddress

use of org.neo4j.configuration.helpers.SocketAddress in project neo4j by neo4j.

the class SingleInstanceGetRoutingTableProcedureTest method shouldUseClientProvidedHostAndAdvertisedPortAsAdvertisedAddress.

@RoutingConfigsTest
void shouldUseClientProvidedHostAndAdvertisedPortAsAdvertisedAddress(Config config, String clientAddress) throws Exception {
    // given
    var advertisedBoldPort = 8776;
    var defaultBoltPort = 7687;
    var advertisedBoltAddress = new SocketAddress("neo4j.com", advertisedBoldPort);
    config.set(BoltConnector.advertised_address, advertisedBoltAddress);
    var clientProvidedHost = clientAddress == null ? "mydomain.com" : clientAddress.split(":")[0];
    var ctxContents = new MapValueBuilder();
    ctxContents.add(ADDRESS_CONTEXT_KEY, Values.stringValue(clientProvidedHost));
    var ctx = ctxContents.build();
    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, defaultBoltPort);
    // when
    var result = invoke(procedure, ID, ctx);
    // then
    assertEquals(singletonList(expectedAddress), result.readEndpoints());
    assertEquals(expectedWriters(expectedAddress), result.writeEndpoints());
    assertEquals(singletonList(expectedAddress), result.routeEndpoints());
}
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)

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