@Override public Neo4jRule withConfig( Setting<?> key, String value ) { builder = builder.withConfig( key, value ); return this; }
@Override public Neo4jRule withConfig( String key, String value ) { builder = builder.withConfig( key, value ); return this; }
private void testStartupWithConnectors( boolean httpEnabled, boolean httpsEnabled, boolean boltEnabled ) { TestServerBuilder serverBuilder = newInProcessBuilder( testDir.directory() ) .withConfig( "dbms.connector.http.enabled", Boolean.toString( httpEnabled ) ) .withConfig( "dbms.connector.http.listen_address", ":0" ) .withConfig( "dbms.connector.https.enabled", Boolean.toString( httpsEnabled ) ) .withConfig( "dbms.connector.https.listen_address", ":0" ) .withConfig( "dbms.connector.bolt.enabled", Boolean.toString( boltEnabled ) ) .withConfig( "dbms.connector.bolt.listen_address", ":0" ); try ( ServerControls server = serverBuilder.newServer() ) { GraphDatabaseService db = server.graph(); assertDbAccessible( db ); verifyConnector( db, "http", httpEnabled ); verifyConnector( db, "https", httpsEnabled ); verifyConnector( db, "bolt", boltEnabled ); } }
HttpConnector httpsConnector = new HttpConnector( "1", Encryption.TLS ); try ( ServerControls server = getTestServerBuilder( testDir.directory() ) .withConfig( httpConnector.type, "HTTP" ) .withConfig( httpConnector.enabled, "true" ) .withConfig( httpConnector.encryption, "NONE" ) .withConfig( httpConnector.listen_address, "localhost:0" ) .withConfig( httpsConnector.type, "HTTP" ) .withConfig( httpsConnector.enabled, "true" ) .withConfig( httpsConnector.encryption, "TLS" ) .withConfig( httpsConnector.listen_address, "localhost:0" ) .withConfig( GraphDatabaseSettings.dense_node_threshold, "20" ) .withConfig( "https.ssl_policy", "test" ) .withConfig( "dbms.ssl.policy.test.base_directory", testDir.directory( "certificates" ).getAbsolutePath() ) .withConfig( "dbms.ssl.policy.test.allow_key_generation", "true" ) .withConfig( "dbms.ssl.policy.test.ciphers", String.join( ",", defaultCiphers ) ) .withConfig( "dbms.ssl.policy.test.tls_versions", "TLSv1.2, TLSv1.1, TLSv1" ) .withConfig( "dbms.ssl.policy.test.client_auth", ClientAuth.NONE.name() ) .withConfig( "dbms.ssl.policy.test.trust_all", "true" ) .newServer() )
@Test public void shouldReturnBoltUriWhenMultipleBoltConnectorsConfigured() { TestServerBuilder serverBuilder = newInProcessBuilder( testDir.directory() ) .withConfig( "dbms.connector.another_bolt.type", "BOLT" ) .withConfig( "dbms.connector.another_bolt.enabled", "true" ) .withConfig( "dbms.connector.another_bolt.listen_address", ":0" ) .withConfig( "dbms.connector.bolt.enabled", "true" ) .withConfig( "dbms.connector.bolt.listen_address", ":0" ); try ( ServerControls server = serverBuilder.newServer() ) { HostnamePort boltHostPort = connectorAddress( server.graph(), "bolt" ); HostnamePort anotherBoltHostPort = connectorAddress( server.graph(), "another_bolt" ); assertNotNull( boltHostPort ); assertNotNull( anotherBoltHostPort ); assertNotEquals( boltHostPort, anotherBoltHostPort ); URI boltUri = server.boltURI(); assertEquals( "bolt", boltUri.getScheme() ); assertEquals( boltHostPort.getHost(), boltUri.getHost() ); assertEquals( boltHostPort.getPort(), boltUri.getPort() ); } }
private TestServerBuilder getServerBuilder( File targetFolder ) { TestServerBuilder serverBuilder = newInProcessBuilder( targetFolder ) .withConfig( LegacySslPolicyConfig.certificates_directory.name(), ServerTestUtils.getRelativePath( testDir.directory(), LegacySslPolicyConfig.certificates_directory ) ); return serverBuilder; }
@Test public void shouldReturnBoltUriWhenDefaultBoltConnectorOffAndOtherConnectorConfigured() { TestServerBuilder serverBuilder = newInProcessBuilder( testDir.directory() ) .withConfig( "dbms.connector.bolt.enabled", "false" ) .withConfig( "dbms.connector.another_bolt.type", "BOLT" ) .withConfig( "dbms.connector.another_bolt.enabled", "true" ) .withConfig( "dbms.connector.another_bolt.listen_address", ":0" ); try ( ServerControls server = serverBuilder.newServer() ) { HostnamePort boltHostPort = connectorAddress( server.graph(), "bolt" ); HostnamePort anotherBoltHostPort = connectorAddress( server.graph(), "another_bolt" ); assertNull( boltHostPort ); assertNotNull( anotherBoltHostPort ); URI boltUri = server.boltURI(); assertEquals( "bolt", boltUri.getScheme() ); assertEquals( anotherBoltHostPort.getHost(), boltUri.getHost() ); assertEquals( anotherBoltHostPort.getPort(), boltUri.getPort() ); } }
@Test public void shouldWorkWithInjectableFromKernelExtensionWithMorePower() throws Throwable { // When try ( ServerControls server = createServer( MyProceduresUsingMyCoreAPI.class ) .withConfig( GraphDatabaseSettings.record_id_batch_size, "1" ) .newServer() ) { // Then assertQueryGetsValue( server, "CALL makeNode(\\'Test\\')", 0L ); assertQueryGetsValue( server, "CALL makeNode(\\'Test\\')", 1L ); assertQueryGetsValue( server, "CALL makeNode(\\'Test\\')", 2L ); assertQueryGetsValue( server, "CALL countNodes", 3L ); assertQueryGetsError( server, "CALL willFail", "Write operations are not allowed" ); } }
@Override public Neo4jRule withConfig( String key, String value ) { builder = builder.withConfig( key, value ); return this; }
@Override public Neo4jRule withConfig( Setting<?> key, String value ) { builder = builder.withConfig( key, value ); return this; }
@BeforeClass public static void setUp() throws Exception { server = TestServerBuilders.newInProcessBuilder().withFixture(setup) .withConfig("dbms.security.auth_enabled", "false").newServer(); BOLT_URL = "'"+server.boltURI().toString()+"'"; db = new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().newGraphDatabase(); TestUtil.registerProcedure(db, Bolt.class); }
.withConfig("dbms.connector.bolt.type", "BOLT") .withConfig("dbms.connector.bolt.enabled", "true") .withConfig("dbms.connector.bolt.listen_address", "localhost:" + port) .newServer(); } else { TestServerBuilder builder = newInProcessBuilder() .withConfig("dbms.connector.http.type", "HTTP") .withConfig("dbms.connector.http.enabled", "true") .withConfig("dbms.connector.http.listen_address", "localhost:" + port) .withConfig("dbms.security.auth_enabled", Boolean.toString(enableAuthentication)) .withConfig("dbms.security.auth_provider", "native") .withConfig("dbms.transaction_timeout", Integer.toString(transactionTimeoutSeconds)) .withConfig("remote_shell_enabled", "false"); .withConfig("unsupported.dbms.security.auth_store.location", authStore.toAbsolutePath().toString());
/** * Returns TestServerBuilder based on what is present on classpath */ public static TestServerBuilder newInProcessBuilder() { // Use reflection here so there is no compile time dependency on neo4j-harness-enterprise TestServerBuilder builder; builder = instantiate("org.neo4j.harness.internal.EnterpriseInProcessServerBuilder"); if (builder == null) { // class name for Neo4j 3.1 builder = instantiate("org.neo4j.harness.EnterpriseInProcessServerBuilder"); } if (builder == null) { builder = instantiate("org.neo4j.harness.internal.InProcessServerBuilder"); } /* The property "unsupported.dbms.jmx_module.enabled=false" disables JMX monitoring We may start multiple instances of the server and without disabling this the 2nd instance would not start. */ builder = builder.withConfig("unsupported.dbms.jmx_module.enabled", "false"); LOGGER.info("Creating new instance of {}", builder.getClass()); return builder; }
private static void configureConnectors( int boltPort, int httpPort, int httpsPort, TestServerBuilder builder ) { builder.withConfig( new BoltConnector( "bolt" ).type.name(), "BOLT" ); builder.withConfig( new BoltConnector( "bolt" ).enabled.name(), "true" ); builder.withConfig( new BoltConnector( "bolt" ).listen_address.name(), specifyPortOnly( boltPort ) ); builder.withConfig( new BoltConnector( "bolt" ).advertised_address.name(), specifyPortOnly( boltPort ) ); builder.withConfig( new HttpConnector( "http", HttpConnector.Encryption.NONE ).type.name(), "HTTP" ); builder.withConfig( new HttpConnector( "http", HttpConnector.Encryption.NONE ).enabled.name(), "true" ); builder.withConfig( new HttpConnector( "http", HttpConnector.Encryption.NONE ).listen_address.name(), specifyPortOnly( httpPort ) ); builder.withConfig( new HttpConnector( "http", HttpConnector.Encryption.NONE ).advertised_address.name(), specifyPortOnly( httpPort ) ); builder.withConfig( new HttpConnector( "https", HttpConnector.Encryption.TLS ).type.name(), "HTTP" ); builder.withConfig( new HttpConnector( "https", HttpConnector.Encryption.TLS ).enabled.name(), "true" ); builder.withConfig( new HttpConnector( "https", HttpConnector.Encryption.TLS ).listen_address.name(), specifyPortOnly( httpsPort ) ); builder.withConfig( new HttpConnector( "https", HttpConnector.Encryption.TLS ).advertised_address.name(), specifyPortOnly( httpsPort ) ); }
builder.withConfig( GraphDatabaseSettings.neo4j_home.name(), homePath ); builder.withConfig( GraphDatabaseSettings.pagecache_memory.name(), "8m" ); builder.withConfig( EnterpriseEditionSettings.mode.name(), EnterpriseEditionSettings.Mode.CORE.name() ); builder.withConfig( CausalClusteringSettings.multi_dc_license.name(), "true" ); builder.withConfig( CausalClusteringSettings.initial_discovery_members.name(), String.join( ",", initialMembers ) ); builder.withConfig( CausalClusteringSettings.discovery_listen_address.name(), specifyPortOnly( hazelcastPort ) ); builder.withConfig( CausalClusteringSettings.transaction_listen_address.name(), specifyPortOnly( txPort ) ); builder.withConfig( CausalClusteringSettings.raft_listen_address.name(), specifyPortOnly( raftPort ) ); builder.withConfig( CausalClusteringSettings.database.name(), initialMembersToDatabase.get( coreId ) ); builder.withConfig( CausalClusteringSettings.minimum_core_cluster_size_at_formation.name(), String.valueOf( nCores ) ); builder.withConfig( CausalClusteringSettings.minimum_core_cluster_size_at_runtime.name(), String.valueOf( nCores ) ); builder.withConfig( CausalClusteringSettings.server_groups.name(), "core," + "core" + coreId ); configureConnectors( boltPort, httpPort, httpsPort, builder ); builder.withConfig( ServerSettings.jmx_module_enabled.name(), Settings.FALSE ); builder.withConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE ); builder.withConfig( GraphDatabaseSettings.neo4j_home.name(), homePath ); builder.withConfig( GraphDatabaseSettings.pagecache_memory.name(), "8m" ); builder.withConfig( EnterpriseEditionSettings.mode.name(), EnterpriseEditionSettings.Mode.READ_REPLICA.name() ); builder.withConfig( CausalClusteringSettings.initial_discovery_members.name(), String.join( ",", initialMembers ) ); builder.withConfig( CausalClusteringSettings.transaction_listen_address.name(), specifyPortOnly( txPort ) );
@Test public void testOgmPluginExtension() throws Exception { try (ServerControls controls = TestServer.newInProcessBuilder() .withConfig(GraphDatabaseSettings.auth_enabled, "false") .withExtension(TEST_PATH, TestOgmExtension.class) .newServer()) { URI testURI = controls.httpURI().resolve(TEST_PATH); HTTP.Response saveResponse = HTTP.POST(testURI.toString()); assertThat(saveResponse.status()).isEqualTo(200); HTTP.Response loadResponse = HTTP.GET(testURI.toString()); assertThat(loadResponse.rawContent()).isEqualTo("[{\"id\":0,\"name\":\"new user\"}]"); } }
@Test public void ogmExtensionShouldUseProvidedDatabase() throws Exception { try (ServerControls controls = TestServer.newInProcessBuilder() .withConfig(GraphDatabaseSettings.auth_enabled, "false") .withExtension(TEST_PATH, TestOgmExtension.class) .newServer()) { URI testURI = controls.httpURI().resolve(TEST_PATH); GraphDatabaseService service = controls.graph(); try (Transaction tx = service.beginTx()) { service.execute("CREATE (u:User {name:'new user'})"); tx.success(); } HTTP.Response loadResponse = HTTP.GET(testURI.toString()); assertThat(loadResponse.rawContent()).isEqualTo("[{\"id\":0,\"name\":\"new user\"}]"); } }