Search in sources :

Example 16 with SocketAddress

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

the class JettyThreadLimitIT method shouldHaveConfigurableJettyThreadPoolSize.

@Test
void shouldHaveConfigurableJettyThreadPoolSize() throws Exception {
    Jetty9WebServer server = new Jetty9WebServer(NullLogProvider.getInstance(), Config.defaults(), NetworkConnectionTracker.NO_OP, mock(ByteBufferPool.class));
    int numCores = 1;
    // 12 is the new min max Threads value, for one core
    int configuredMaxThreads = 12;
    // In this configuration, 1 thread will become an acceptor...
    int acceptorThreads = 1;
    // ... and 1 thread will become a selector...
    int selectorThreads = 1;
    // ... and the rest are job threads
    int jobThreads = configuredMaxThreads - acceptorThreads - selectorThreads;
    server.setMaxThreads(numCores);
    server.setHttpAddress(new SocketAddress("localhost", 0));
    try {
        server.start();
        QueuedThreadPool threadPool = (QueuedThreadPool) server.getJetty().getThreadPool();
        threadPool.start();
        CountDownLatch startLatch = new CountDownLatch(jobThreads);
        CountDownLatch endLatch = loadThreadPool(threadPool, configuredMaxThreads + 1, startLatch);
        // Wait for threadPool to create threads
        startLatch.await();
        int threads = threadPool.getThreads();
        assertEquals(configuredMaxThreads, threads, "Wrong number of threads in pool");
        endLatch.countDown();
    } finally {
        server.stop();
    }
}
Also used : ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) SocketAddress(org.neo4j.configuration.helpers.SocketAddress) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 17 with SocketAddress

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

the class InProcessServerBuilderIT method shouldAllowCustomServerAndDbConfig.

@Test
void shouldAllowCustomServerAndDbConfig() throws Exception {
    // Given
    trustAllSSLCerts();
    // Get default trusted cypher suites
    SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
    List<String> defaultCiphers = Arrays.asList(ssf.getDefaultCipherSuites());
    // When
    SslPolicyConfig pem = SslPolicyConfig.forScope(HTTPS);
    var certificates = directory.directory("certificates");
    SelfSignedCertificateFactory.create(certificates, "private.key", "public.crt");
    Files.createDirectories(certificates.resolve("trusted"));
    Files.createDirectories(certificates.resolve("revoked"));
    try (Neo4j neo4j = getTestBuilder(directory.homePath()).withConfig(HttpConnector.enabled, true).withConfig(HttpConnector.listen_address, new SocketAddress("localhost", 0)).withConfig(HttpsConnector.enabled, true).withConfig(HttpsConnector.listen_address, new SocketAddress("localhost", 0)).withConfig(GraphDatabaseSettings.dense_node_threshold, 20).withConfig(pem.enabled, Boolean.TRUE).withConfig(pem.base_directory, certificates).withConfig(pem.ciphers, defaultCiphers).withConfig(pem.tls_versions, List.of("TLSv1.2", "TLSv1.1", "TLSv1")).withConfig(pem.client_auth, ClientAuth.NONE).withConfig(pem.trust_all, true).build()) {
        // Then
        assertThat(HTTP.GET(neo4j.httpURI().toString()).status()).isEqualTo(200);
        assertThat(HTTP.GET(neo4j.httpsURI().toString()).status()).isEqualTo(200);
        Config config = ((GraphDatabaseAPI) neo4j.defaultDatabaseService()).getDependencyResolver().resolveDependency(Config.class);
        assertEquals(20, config.get(GraphDatabaseSettings.dense_node_threshold));
    }
}
Also used : SslPolicyConfig(org.neo4j.configuration.ssl.SslPolicyConfig) SslPolicyConfig(org.neo4j.configuration.ssl.SslPolicyConfig) Config(org.neo4j.configuration.Config) SSLServerSocketFactory(javax.net.ssl.SSLServerSocketFactory) SocketAddress(org.neo4j.configuration.helpers.SocketAddress) Test(org.junit.jupiter.api.Test)

Example 18 with SocketAddress

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

the class Neo4jWithSocket method configure.

private Map<Setting<?>, Object> configure(Consumer<Map<Setting<?>, Object>> overrideSettingsFunction) {
    Map<Setting<?>, Object> settings = new HashMap<>();
    settings.put(GraphDatabaseSettings.auth_enabled, false);
    settings.put(BoltConnector.enabled, true);
    settings.put(BoltConnector.listen_address, new SocketAddress("localhost", 0));
    settings.put(BoltConnector.encryption_level, DISABLED);
    configure.accept(settings);
    overrideSettingsFunction.accept(settings);
    return settings;
}
Also used : HashMap(java.util.HashMap) Setting(org.neo4j.graphdb.config.Setting) SocketAddress(org.neo4j.configuration.helpers.SocketAddress)

Example 19 with SocketAddress

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

the class MultipleBoltServerPortsStressTest method setUp.

@BeforeEach
void setUp(TestInfo testInfo) throws IOException {
    server.setGraphDatabaseFactory(new SharedAuthManagerDbmsBuilder());
    server.setConfigure(settings -> {
        settings.put(BoltConnector.enabled, true);
        settings.put(BoltConnector.listen_address, new SocketAddress(0));
        settings.put(GraphDatabaseSettings.routing_enabled, true);
        settings.put(GraphDatabaseSettings.routing_listen_address, new SocketAddress(0));
    });
    server.init(testInfo);
    util = new TransportTestUtil(newMessageEncoder());
}
Also used : TransportTestUtil(org.neo4j.bolt.testing.TransportTestUtil) SocketAddress(org.neo4j.configuration.helpers.SocketAddress) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 20 with SocketAddress

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

the class OcspStaplingIT method setup.

@BeforeEach
void setup(TestInfo testInfo) throws IOException {
    server.setConfigure(settings -> {
        SslPolicyConfig policy = SslPolicyConfig.forScope(BOLT);
        settings.put(policy.enabled, true);
        settings.put(policy.public_certificate, endUserCertFile.toAbsolutePath());
        settings.put(policy.private_key, endUserKeyFile.toAbsolutePath());
        settings.put(BoltConnector.enabled, true);
        settings.put(BoltConnector.encryption_level, OPTIONAL);
        settings.put(CommonConnectorConfig.ocsp_stapling_enabled, true);
        settings.put(BoltConnector.listen_address, new SocketAddress("localhost", 0));
    });
    server.init(testInfo);
}
Also used : SslPolicyConfig(org.neo4j.configuration.ssl.SslPolicyConfig) SocketAddress(org.neo4j.configuration.helpers.SocketAddress) BeforeEach(org.junit.jupiter.api.BeforeEach)

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