/** * Augment the existing config with new settings, ignoring any conflicting settings. * * @param setting settings to add and override * @throws InvalidSettingException when and invalid setting is found and {@link * GraphDatabaseSettings#strict_config_validation} is true. */ public void augmentDefaults( Setting<?> setting, String value ) throws InvalidSettingException { overriddenDefaults.put( setting.name(), value ); params.putIfAbsent( setting.name(), value ); }
@Test public void durationAlwaysListedWithUnit() throws Exception { // When List<Object[]> config = callListConfig( GraphDatabaseSettings.transaction_timeout.name() ); assertEquals( 1, config.size() ); assertArrayEquals( new Object[]{ "dbms.transaction.timeout", "The maximum time interval of a transaction within which it should be completed.", "0ms", true }, config.get( 0 ) ); }
@Test public void shouldNotAllowLegacyPolicyToBeConfigured() { // given Map<String,String> params = stringMap(); SslPolicyConfig policyConfig = new SslPolicyConfig( LegacySslPolicyConfig.LEGACY_POLICY_NAME ); params.put( neo4j_home.name(), home.getAbsolutePath() ); params.put( policyConfig.base_directory.name(), "certificates/default" ); Config config = Config.defaults( params ); try { // when SslPolicyLoader.create( config, NullLogProvider.getInstance() ); fail(); } catch ( IllegalArgumentException e ) { // expected } } }
@Test public void shouldRegisterASingleUri() throws Exception { WebServer webServer = mock( WebServer.class ); CommunityNeoServer neoServer = mock( CommunityNeoServer.class ); when( neoServer.baseUri() ).thenReturn( new URI( "http://localhost:7575" ) ); when( neoServer.getWebServer() ).thenReturn( webServer ); Map<String, String> params = new HashMap<>(); String managementPath = "/db/manage"; params.put( ServerSettings.management_api_path.name(), managementPath ); Config config = Config.defaults( params ); when( neoServer.getConfig() ).thenReturn( config ); ManagementApiModule module = new ManagementApiModule( webServer, config ); module.start(); verify( webServer ).addJAXRSClasses( anyListOf( String.class ), anyString(), any() ); } }
@Test public void shouldParseExplicitSettingValueWhenProvided() { // given Map<String,String> config = stringMap( GraphDatabaseSettings.default_listen_address.name(), "server1.example.com", listen_address_setting.name(), "server1.internal:4000" ); // when ListenSocketAddress listenSocketAddress = listen_address_setting.apply( config::get ); // then assertEquals( "server1.internal", listenSocketAddress.getHostname() ); assertEquals( 4000, listenSocketAddress.getPort() ); }
protected Map<String,String> settings( String... strings ) { Map<String, String> defaults = new HashMap<>(); defaults.put( GraphDatabaseSettings.pagecache_memory.name(), "8m" ); defaults.put( GraphDatabaseSettings.record_format.name(), getRecordFormatName() ); defaults.put( "dbms.backup.enabled", "false" ); return stringMap( defaults, strings ); }
@Test public void canSpecifyConfigFile() throws Throwable { // Given File configFile = tempDir.newFile( Config.DEFAULT_CONFIG_FILE_NAME ); Map<String,String> properties = stringMap( forced_kernel_id.name(), "ourcustomvalue" ); properties.putAll( ServerTestUtils.getDefaultRelativeProperties() ); properties.putAll( connectorsOnRandomPortsConfig() ); store( properties, configFile ); // When ServerBootstrapper.start( bootstrapper, "--home-dir", tempDir.newFolder( "home-dir" ).getAbsolutePath(), "--config-dir", configFile.getParentFile().getAbsolutePath() ); // Then assertThat( bootstrapper.getServer().getConfig().get( forced_kernel_id ), equalTo( "ourcustomvalue" ) ); }
@Test public void listDynamicSetting() throws ProcedureException { List<Object[]> config = callListConfig( GraphDatabaseSettings.check_point_iops_limit.name() ); assertEquals( 1, config.size() ); assertTrue( (Boolean) config.get(0)[3] ); }
@Test public void shouldThrowIfPolicyNameDoesNotExist() { // given Map<String,String> params = stringMap(); SslPolicyConfig policyConfig = new SslPolicyConfig( "default" ); params.put( neo4j_home.name(), home.getAbsolutePath() ); params.put( policyConfig.base_directory.name(), "certificates/default" ); Config config = Config.defaults( params ); SslPolicyLoader sslPolicyLoader = SslPolicyLoader.create( config, NullLogProvider.getInstance() ); // when try { sslPolicyLoader.getPolicy( "unknown" ); fail(); } catch ( IllegalArgumentException e ) { // expected } }
@Test public void shouldRegisterASingleUri() { // Given WebServer webServer = mock( WebServer.class ); Map<String, String> params = new HashMap<>(); String path = "/db/data"; params.put( ServerSettings.rest_api_path.name(), path ); Config config = Config.defaults( params ); // When RESTApiModule module = new RESTApiModule( webServer, config, () -> new UsageData( mock( JobScheduler.class ) ), NullLogProvider.getInstance() ); module.start(); // Then verify( webServer ).addJAXRSClasses( anyListOf( String.class ), anyString(), any() ); } }
@Test public void shouldParseExplicitSettingValueWhenProvided() { // given Map<String,String> config = stringMap( GraphDatabaseSettings.default_advertised_address.name(), "server1.example.com", advertised_address_setting.name(), "server1.internal:4000" ); // when AdvertisedSocketAddress advertisedSocketAddress = advertised_address_setting.apply( config::get ); // then assertEquals( "server1.internal", advertisedSocketAddress.getHostname() ); assertEquals( 4000, advertisedSocketAddress.getPort() ); }
private void shouldComplainIfMissingFile( File file ) { // given FileUtils.deleteFile( file ); Map<String,String> params = stringMap(); SslPolicyConfig policyConfig = new SslPolicyConfig( "default" ); params.put( neo4j_home.name(), home.getAbsolutePath() ); params.put( policyConfig.base_directory.name(), "certificates/default" ); Config config = Config.defaults( params ); // when try { SslPolicyLoader.create( config, NullLogProvider.getInstance() ); fail(); } catch ( Exception e ) { assertTrue( e.getCause() instanceof FileNotFoundException ); } }
@Test public void canOverrideConfigValues() throws Throwable { // Given File configFile = tempDir.newFile( Config.DEFAULT_CONFIG_FILE_NAME ); Map<String,String> properties = stringMap( forced_kernel_id.name(), "thisshouldnotshowup" ); properties.putAll( ServerTestUtils.getDefaultRelativeProperties() ); properties.putAll( connectorsOnRandomPortsConfig() ); store( properties, configFile ); // When ServerBootstrapper.start( bootstrapper, "--home-dir", tempDir.newFolder( "home-dir" ).getAbsolutePath(), "--config-dir", configFile.getParentFile().getAbsolutePath(), "-c", configOption( forced_kernel_id, "mycustomvalue" ) ); // Then assertThat( bootstrapper.getServer().getConfig().get( forced_kernel_id ), equalTo( "mycustomvalue" ) ); }