@Override protected void configure( GraphDatabaseBuilder builder ) { // Reduce the default page cache memory size to 8 mega-bytes for test databases. builder.setConfig( GraphDatabaseSettings.pagecache_memory, "8m" ); builder.setConfig( new BoltConnector( "bolt" ).type, BOLT.name() ); builder.setConfig( new BoltConnector( "bolt" ).enabled, "false" ); }
@Test public void validatesTlsLevel() { String key = "dbms.connector.bolt.tls_level"; assertEquals( stringMap( key, EncryptionLevel.DISABLED.name() ), cv.validate( stringMap( key, EncryptionLevel.DISABLED.name() ), warningConsumer ) ); assertEquals( stringMap( key, EncryptionLevel.OPTIONAL.name() ), cv.validate( stringMap( key, EncryptionLevel.OPTIONAL.name() ), warningConsumer ) ); assertEquals( stringMap( key, EncryptionLevel.REQUIRED.name() ), cv.validate( stringMap( key, EncryptionLevel.REQUIRED.name() ), warningConsumer ) ); key = "dbms.connector.bla.tls_level"; String type = "dbms.connector.bla.type"; assertEquals( stringMap( key, EncryptionLevel.DISABLED.name(), type, BOLT.name() ), cv.validate( stringMap( key, EncryptionLevel.DISABLED.name(), type, BOLT.name() ), warningConsumer ) ); assertEquals( stringMap( key, EncryptionLevel.OPTIONAL.name(), type, BOLT.name() ), cv.validate( stringMap( key, EncryptionLevel.OPTIONAL.name(), type, BOLT.name() ), warningConsumer ) ); assertEquals( stringMap( key, EncryptionLevel.REQUIRED.name(), type, BOLT.name() ), cv.validate( stringMap( key, EncryptionLevel.REQUIRED.name(), type, BOLT.name() ), warningConsumer ) ); expected.expect( InvalidSettingException.class ); expected.expectMessage( "Bad value 'BOBO' for setting 'dbms.connector.bla.tls_level': must be one of [REQUIRED, OPTIONAL, " + "DISABLED] case sensitive" ); cv.validate( stringMap( key, "BOBO", type, BOLT.name() ), warningConsumer ); }
@Test public void validatesAddress() { String key = "dbms.connector.http.address"; assertEquals( stringMap( key, "localhost:123" ), cv.validate( stringMap( key, "localhost:123" ), warningConsumer ) ); key = "dbms.connector.bla.address"; String type = "dbms.connector.bla.type"; assertEquals( stringMap( key, "localhost:123", type, HTTP.name() ), cv.validate( stringMap( key, "localhost:123", type, HTTP.name() ), warningConsumer ) ); assertEquals( stringMap( key, "localhost:123", type, HTTP.name() ), cv.validate( stringMap( key, "localhost:123", type, HTTP.name() ), warningConsumer ) ); expected.expect( InvalidSettingException.class ); expected.expectMessage( "Setting \"dbms.connector.bla.address\" must be in the format \"hostname:port\" or " + "\":port\". \"BOBO\" does not conform to these formats" ); cv.validate( stringMap( key, "BOBO", type, HTTP.name() ), warningConsumer ); }
@Test public void validatesAddress() { String key = "dbms.connector.bolt.address"; assertEquals( stringMap( key, "localhost:123" ), cv.validate( stringMap( key, "localhost:123" ), warningConsumer ) ); key = "dbms.connector.bla.address"; String type = "dbms.connector.bla.type"; assertEquals( stringMap( key, "localhost:123", type, BOLT.name() ), cv.validate( stringMap( key, "localhost:123", type, BOLT.name() ), warningConsumer ) ); assertEquals( stringMap( key, "localhost:123", type, BOLT.name() ), cv.validate( stringMap( key, "localhost:123", type, BOLT.name() ), warningConsumer ) ); expected.expect( InvalidSettingException.class ); expected.expectMessage( "Setting \"dbms.connector.bla.address\" must be in the format \"hostname:port\" or " + "\":port\". \"BOBO\" does not conform to these formats" ); cv.validate( stringMap( key, "BOBO", type, BOLT.name() ), warningConsumer ); }
@Test public void validatesAdvertisedAddress() { String key = "dbms.connector.http.advertised_address"; assertEquals( stringMap( key, "localhost:123" ), cv.validate( stringMap( key, "localhost:123" ), warningConsumer ) ); key = "dbms.connector.bla.advertised_address"; String type = "dbms.connector.bla.type"; assertEquals( stringMap( key, "localhost:123", type, HTTP.name() ), cv.validate( stringMap( key, "localhost:123", type, HTTP.name() ), warningConsumer ) ); assertEquals( stringMap( key, "localhost:123", type, HTTP.name() ), cv.validate( stringMap( key, "localhost:123", type, HTTP.name() ), warningConsumer ) ); expected.expect( InvalidSettingException.class ); expected.expectMessage( "Setting \"dbms.connector.bla.advertised_address\" must be in the format " + "\"hostname:port\" or \":port\". \"BOBO\" does not conform to these formats" ); cv.validate( stringMap( key, "BOBO", type, HTTP.name() ), warningConsumer ); }
@Test public void validatesListenAddress() { String key = "dbms.connector.http.listen_address"; assertEquals( stringMap( key, "localhost:123" ), cv.validate( stringMap( key, "localhost:123" ), warningConsumer ) ); key = "dbms.connector.bla.listen_address"; String type = "dbms.connector.bla.type"; assertEquals( stringMap( key, "localhost:123", type, HTTP.name() ), cv.validate( stringMap( key, "localhost:123", type, HTTP.name() ), warningConsumer ) ); assertEquals( stringMap( key, "localhost:123", type, HTTP.name() ), cv.validate( stringMap( key, "localhost:123", type, HTTP.name() ), warningConsumer ) ); expected.expect( InvalidSettingException.class ); expected.expectMessage( "Setting \"dbms.connector.bla.listen_address\" must be in the format " + "\"hostname:port\" or \":port\". \"BOBO\" does not conform to these formats" ); cv.validate( stringMap( key, "BOBO", type, HTTP.name() ), warningConsumer ); }
@Test public void validatesAdvertisedAddress() { String key = "dbms.connector.bolt.advertised_address"; assertEquals( stringMap( key, "localhost:123" ), cv.validate( stringMap( key, "localhost:123" ), warningConsumer ) ); key = "dbms.connector.bla.advertised_address"; String type = "dbms.connector.bla.type"; assertEquals( stringMap( key, "localhost:123", type, BOLT.name() ), cv.validate( stringMap( key, "localhost:123", type, BOLT.name() ), warningConsumer ) ); assertEquals( stringMap( key, "localhost:123", type, BOLT.name() ), cv.validate( stringMap( key, "localhost:123", type, BOLT.name() ), warningConsumer ) ); expected.expect( InvalidSettingException.class ); expected.expectMessage( "Setting \"dbms.connector.bla.advertised_address\" must be in the format " + "\"hostname:port\" or \":port\". \"BOBO\" does not conform to these formats" ); cv.validate( stringMap( key, "BOBO", type, BOLT.name() ), warningConsumer ); }
@Test public void validatesListenAddress() { String key = "dbms.connector.bolt.listen_address"; assertEquals( stringMap( key, "localhost:123" ), cv.validate( stringMap( key, "localhost:123" ), warningConsumer ) ); key = "dbms.connector.bla.listen_address"; String type = "dbms.connector.bla.type"; assertEquals( stringMap( key, "localhost:123", type, BOLT.name() ), cv.validate( stringMap( key, "localhost:123", type, BOLT.name() ), warningConsumer ) ); assertEquals( stringMap( key, "localhost:123", type, BOLT.name() ), cv.validate( stringMap( key, "localhost:123", type, BOLT.name() ), warningConsumer ) ); expected.expect( InvalidSettingException.class ); expected.expectMessage( "Setting \"dbms.connector.bla.listen_address\" must be in the format " + "\"hostname:port\" or \":port\". \"BOBO\" does not conform to these formats" ); cv.validate( stringMap( key, "BOBO", type, BOLT.name() ), warningConsumer ); }
@Test public void validatesEncryption() { String key = "dbms.connector.bla.encryption"; String type = "dbms.connector.bla.type"; assertEquals( stringMap( key, Encryption.NONE.name(), type, HTTP.name() ), cv.validate( stringMap( key, Encryption.NONE.name(), type, HTTP.name() ), warningConsumer ) ); assertEquals( stringMap( key, Encryption.TLS.name(), type, HTTP.name() ), cv.validate( stringMap( key, Encryption.TLS.name(), type, HTTP.name() ), warningConsumer ) ); expected.expect( InvalidSettingException.class ); expected.expectMessage( "Bad value 'BOBO' for setting 'dbms.connector.bla.encryption': must be one of [NONE, TLS] case " + "sensitive" ); cv.validate( stringMap( key, "BOBO", type, HTTP.name() ), warningConsumer ); }
@Test public void withConnectorsDisabled() { Connector httpConnector = new HttpConnector(); Connector boltConnector = new BoltConnector(); Config config = Config.builder() .withSetting( httpConnector.enabled, "true" ) .withSetting( httpConnector.type, Connector.ConnectorType.HTTP.name() ) .withSetting( boltConnector.enabled, "true" ) .withSetting( boltConnector.type, Connector.ConnectorType.BOLT.name() ) .withConnectorsDisabled().build(); assertFalse( config.get( httpConnector.enabled ) ); assertFalse( config.get( boltConnector.enabled ) ); }
@Test public void shouldLookupBoltPortInRegisterIfConfiguredTo0() throws Exception { BoltConnector bolt = new BoltConnector( "honestJakesBoltConnector" ); ConnectorPortRegister register = new ConnectorPortRegister(); register.register( bolt.key(), new InetSocketAddress( 1337 ) ); DiscoverableURIs uris = communityDiscoverableURIs( Config.builder() .withSetting( bolt.advertised_address, "apple.com:0" ) .withSetting( bolt.enabled, "true" ) .withSetting( bolt.type, BoltConnector.ConnectorType.BOLT.name() ) .build(), register ); assertEquals( "bolt://apple.com:1337", toMap(uris).get("bolt") ); }
private static Config createConfig() { Map<String, String> configProps = new HashMap<>(); configProps.put( new BoltConnector( CONNECTOR ).enabled.name(), "TRUE" ); configProps.put( new BoltConnector( CONNECTOR ).listen_address.name(), "localhost:0" ); configProps.put( new BoltConnector( CONNECTOR ).type.name(), BoltConnector.ConnectorType.BOLT.name() ); configProps.put( new BoltConnector( CONNECTOR ).thread_pool_min_size.name(), "5" ); configProps.put( new BoltConnector( CONNECTOR ).thread_pool_max_size.name(), "10" ); return Config.fromSettings( configProps ).build(); }
@Test public void requiresTypeWhenNameIsNotHttpOrHttps() { String randomEnabled = "dbms.connector.bla.enabled"; String randomType = "dbms.connector.bla.type"; assertEquals( stringMap( randomEnabled, "true", randomType, HTTP.name() ), cv.validate( stringMap( randomEnabled, "true", randomType, HTTP.name() ), warningConsumer ) ); expected.expect( InvalidSettingException.class ); expected.expectMessage( "Missing mandatory value for 'dbms.connector.bla.type'" ); cv.validate( stringMap( randomEnabled, "true" ), warningConsumer ); }
@Override protected void configure( GraphDatabaseBuilder builder ) { // Reduce the default page cache memory size to 8 mega-bytes for test databases. builder.setConfig( GraphDatabaseSettings.pagecache_memory, "8m" ); builder.setConfig( new BoltConnector( "bolt" ).type, BOLT.name() ); builder.setConfig( new BoltConnector( "bolt" ).enabled, "false" ); }
@Test public void requiresTypeWhenNameIsNotBolt() { String randomEnabled = "dbms.connector.bla.enabled"; String randomType = "dbms.connector.bla.type"; assertEquals( stringMap( randomEnabled, "true", randomType, BOLT.name() ), cv.validate( stringMap( randomEnabled, "true", randomType, BOLT.name() ), warningConsumer ) ); expected.expect( InvalidSettingException.class ); expected.expectMessage( "Missing mandatory value for 'dbms.connector.bla.type'" ); cv.validate( stringMap( randomEnabled, "true" ), warningConsumer ); }
protected Consumer<Map<String,String>> getSettingsFunction() { return settings -> { settings.put( GraphDatabaseSettings.auth_enabled.name(), "false" ); settings.put( new BoltConnector( DEFAULT_CONNECTOR_KEY ).enabled.name(), "TRUE" ); settings.put( new BoltConnector( DEFAULT_CONNECTOR_KEY ).listen_address.name(), "localhost:0" ); settings.put( new BoltConnector( DEFAULT_CONNECTOR_KEY ).type.name(), BoltConnector.ConnectorType.BOLT.name() ); settings.put( new BoltConnector( DEFAULT_CONNECTOR_KEY ).thread_pool_min_size.name(), "0" ); settings.put( new BoltConnector( DEFAULT_CONNECTOR_KEY ).thread_pool_max_size.name(), "2" ); }; }