/** * Convenient method for starting building from a file. */ @Nonnull public static Builder fromFile( @Nullable final File configFile ) { return builder().withFile( configFile ); }
/** * Convenient method for starting building from a file. */ @Nonnull public static Builder fromFile( @Nonnull final Path configFile ) { return builder().withFile( configFile ); }
/** * Convenient method for starting building from initial settings. */ @Nonnull public static Builder fromSettings( final Map<String,String> initialSettings ) { return builder().withSettings( initialSettings ); }
/** * @return a configuration with default values. */ @Nonnull public static Config defaults() { return builder().build(); }
/** * Constructs a <code>Config</code> with default values and sets the supplied <code>setting</code> to the <code>value</code>. * @param setting The initial setting to use. * @param value The initial value to give the setting. */ @Nonnull public static Config defaults( @Nonnull final Setting<?> setting, final String value ) { return builder().withSetting( setting, value ).build(); }
/** * @param initialSettings a map with settings to be present in the config. * @return a configuration with default values augmented with the provided <code>initialSettings</code>. */ @Nonnull public static Config defaults( @Nonnull final Map<String,String> initialSettings ) { return builder().withSettings( initialSettings ).build(); }
@Test public void configValuesContainsConnectors() { Config config = Config.builder().withServerDefaults().build(); List<String> connectorSettings = config.getConfigValues().entrySet().stream() .map( Entry::getKey ) .filter( c -> c.startsWith( "dbms.connector" ) ) .filter( c -> c.endsWith( ".enabled" ) ) .collect( toList() ); assertThat( connectorSettings, containsInAnyOrder( "dbms.connector.http.enabled", "dbms.connector.https.enabled", "dbms.connector.bolt.enabled" ) ); }
@Test public void webServerThreadCountDefaultShouldBeDocumented() { Config config = Config.builder().withServerDefaults().build(); String documentedDefaultValue = config.getConfigValues().entrySet().stream() .filter( c -> c.getKey().equals( ServerSettings.webserver_max_threads.name() ) ) .map( Entry::getValue ) .findAny() .orElseThrow( () -> new RuntimeException( "Setting not present!" ) ) .documentedDefaultValue() .orElseThrow( () -> new RuntimeException( "Default value not present!" ) ); assertEquals( "Number of available processors, or 500 for machines which have more than 500 processors.", documentedDefaultValue ); }
public Config config( LoadableConfig settingsClasses ) { return Config.builder().withSettings( configuration ).withConfigClasses( Collections.singletonList( settingsClasses ) ).build(); }
@Test public void shouldBeFoundInServerDefaults() { // given Config serverDefaultConfig = Config.builder().withServerDefaults().build(); // when Stream<ConfigValue> cvStream = serverDefaultConfig.getConfigValues().values().stream(); // then assertEquals( 1, cvStream.filter( c -> c.name().equals( certificates_directory.name() ) ).count() ); } }
@Test public void connectorSettingHasItsOwnValues() { Config config = Config.builder().withServerDefaults() .withSetting( new HttpConnector( "http" ).address, "localhost:123" ).build(); ConfigValue address = config.getConfigValues().entrySet().stream() .filter( c -> c.getKey().equals( "dbms.connector.http.address" ) ) .map( Entry::getValue ) .findAny() .orElseThrow( () -> new RuntimeException( "Setting not present!" ) ); assertTrue( address.deprecated() ); assertEquals( Optional.of( "dbms.connector.http.listen_address" ), address.replacement() ); } }
@Test public void shouldOmitBoltIfNoConnectorConfigured() throws Exception { DiscoverableURIs uris = communityDiscoverableURIs( Config.builder().build(), null ); assertFalse( toMap( uris ).containsKey( "bolt" ) ); }
@Test public void updateDynamicShouldInformRegisteredListeners() { Config config = Config.builder().withConfigClasses( singletonList( new MyDynamicSettings() ) ).build(); AtomicInteger counter = new AtomicInteger( 0 ); config.registerDynamicUpdateListener( MyDynamicSettings.boolSetting, ( previous, update ) -> { counter.getAndIncrement(); assertTrue( previous ); assertFalse( update ); } ); config.updateDynamicSetting( MyDynamicSettings.boolSetting.name(), "false", ORIGIN ); assertThat( counter.get(), is( 1 ) ); }
@Test public void updateDynamicShouldThrowIfSettingIsNotDynamic() { Config config = Config.builder().withConfigClasses( singletonList( mySettingsWithDefaults ) ).build(); expect.expect( IllegalArgumentException.class ); config.updateDynamicSetting( MySettingsWithDefaults.hello.name(), "hello", ORIGIN ); }
@Test public void registeringUpdateListenerOnNonDynamicSettingMustThrow() { Config config = Config.builder().withConfigClasses( singletonList( mySettingsWithDefaults ) ).build(); expect.expect( IllegalArgumentException.class ); config.registerDynamicUpdateListener( MySettingsWithDefaults.hello, ( a, b ) -> fail( "never called" ) ); }
@Test void shouldEnableBoltByDefault() { // given Config config = Config.builder().withServerDefaults().build(); // when BoltConnector boltConnector = config.boltConnectors().get( 0 ); ListenSocketAddress listenSocketAddress = config.get( boltConnector.listen_address ); // then assertEquals( new ListenSocketAddress( "127.0.0.1", 7687 ), listenSocketAddress ); }
@Test public void updateDynamicShouldNotAllowInvalidSettings() { Config config = Config.builder().withConfigClasses( singletonList( new MyDynamicSettings() ) ).build(); expect.expect( InvalidSettingException.class ); config.updateDynamicSetting( MyDynamicSettings.boolSetting.name(), "this is not a boolean", ORIGIN ); }
@Test public void shouldSetInternalParameter() { // Given Config config = Config.builder() .withSetting( MySettingsWithDefaults.secretSetting, "false" ) .withSetting( MySettingsWithDefaults.hello, "ABC" ) .withConfigClasses( Arrays.asList( mySettingsWithDefaults, myMigratingSettings ) ) .build(); // Then assertTrue( config.getConfigValues().get( MySettingsWithDefaults.secretSetting.name() ).internal() ); assertFalse( config.getConfigValues().get( MySettingsWithDefaults.hello.name() ).internal() ); }
@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") ); }
@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 ) ); }