@Test public void mustNotWarnAboutDuplicateJvmAdditionalSettings() throws Exception { Log log = mock( Log.class ); File confFile = testDirectory.createFile( "test.conf" ); Files.write( confFile.toPath(), Arrays.asList( ExternalSettings.additionalJvm.name() + "=-Dsysprop=val", ExternalSettings.additionalJvm.name() + "=-XX:+UseG1GC", ExternalSettings.additionalJvm.name() + "=-XX:+AlwaysPreTouch" ) ); Config config = Config.fromFile( confFile ).build(); config.setLogger( log ); // The ExternalSettings.additionalJvm setting is allowed to be specified more than once. verifyNoMoreInteractions( log ); }
@Test public void shouldLogIfConfigFileCouldNotBeRead() throws IOException { Log log = mock( Log.class ); File confFile = testDirectory.file( "test.conf" ); assertTrue( confFile.createNewFile() ); assumeTrue( confFile.setReadable( false ) ); Config config = Config.fromFile( confFile ).withNoThrowOnFileLoadFailure().build(); config.setLogger( log ); verify( log ).error( "Unable to load config file [%s]: %s", confFile, confFile + " (Permission denied)" ); }
@Test public void shouldLogIfConfigFileCouldNotBeFound() { Log log = mock( Log.class ); File confFile = testDirectory.file( "test.conf" ); // Note: we don't create the file. Config config = Config.fromFile( confFile ).withNoThrowOnFileLoadFailure().build(); config.setLogger( log ); verify( log ).warn( "Config file [%s] does not exist.", confFile ); }
@Test public void updateDynamicShouldLogExceptionsFromUpdateListeners() { Config config = Config.builder().withConfigClasses( singletonList( new MyDynamicSettings() ) ).build(); IllegalStateException exception = new IllegalStateException( "Boo" ); config.registerDynamicUpdateListener( MyDynamicSettings.boolSetting, ( a, b ) -> { throw exception; } ); Log log = mock( Log.class ); config.setLogger( log ); String settingName = MyDynamicSettings.boolSetting.name(); config.updateDynamicSetting( settingName, "", ORIGIN ); verify( log ).error( "Failure when notifying listeners after dynamic setting change; " + "new setting might not have taken effect: Boo", exception ); }
config.setLogger( log );
@Test public void updateDynamicShouldLogChanges() { String settingName = MyDynamicSettings.boolSetting.name(); String changedMessage = "Setting changed: '%s' changed from '%s' to '%s' via '%s'"; Config config = Config.builder().withConfigClasses( singletonList( new MyDynamicSettings() ) ).build(); Log log = mock( Log.class ); config.setLogger( log ); config.updateDynamicSetting( settingName, "false", ORIGIN ); config.updateDynamicSetting( settingName, "true", ORIGIN ); config.updateDynamicSetting( settingName, "", ORIGIN ); InOrder order = inOrder( log ); order.verify( log ).info( changedMessage, settingName, "default (true)", "false", "test" ); order.verify( log ).info( changedMessage, settingName, "false", "true", "test" ); order.verify( log ).info( changedMessage, settingName, "true", "default (true)", "test" ); verifyNoMoreInteractions( log ); }
@Test public void shouldWarnAndDiscardUnknownOptionsInReservedNamespaceAndPassOnBufferedLogInWithMethods() throws Exception { // Given Log log = mock( Log.class ); File confFile = testDirectory.file( "test.conf" ); assertTrue( confFile.createNewFile() ); Config config = Config.fromFile( confFile ) .withSetting( GraphDatabaseSettings.strict_config_validation, "false" ) .withSetting( "ha.jibberish", "baah" ) .withSetting( "dbms.jibberish", "booh" ).build(); // When config.setLogger( log ); config.augment( "causal_clustering.jibberish", "baah" ); // Then verify( log ).warn( "Unknown config option: %s", "dbms.jibberish" ); verify( log ).warn( "Unknown config option: %s", "ha.jibberish" ); verifyNoMoreInteractions( log ); }
dependencies = dependencies.userLogProvider( userLogProvider ); log = userLogProvider.getLog( getClass() ); config.setLogger( log );
@Test public void mustWarnIfFileContainsDuplicateSettings() throws Exception { Log log = mock( Log.class ); File confFile = testDirectory.createFile( "test.conf" ); Files.write( confFile.toPath(), Arrays.asList( ExternalSettings.initialHeapSize.name() + "=5g", ExternalSettings.initialHeapSize.name() + "=4g", ExternalSettings.initialHeapSize.name() + "=3g", ExternalSettings.maxHeapSize.name() + "=10g", ExternalSettings.maxHeapSize.name() + "=10g" ) ); Config config = Config.fromFile( confFile ).build(); config.setLogger( log ); // We should only log the warning once for each. verify( log ).warn( "The '%s' setting is specified more than once. Settings only be specified once, to avoid ambiguity. " + "The setting value that will be used is '%s'.", ExternalSettings.initialHeapSize.name(), "5g" ); verify( log ).warn( "The '%s' setting is specified more than once. Settings only be specified once, to avoid ambiguity. " + "The setting value that will be used is '%s'.", ExternalSettings.maxHeapSize.name(), "10g" ); }
@Test public void shouldLogDeprecationWarnings() throws Exception { // Given Log log = mock( Log.class ); File confFile = testDirectory.file( "test.conf" ); assertTrue( confFile.createNewFile() ); Config config = Config.fromFile( confFile ) .withSetting( MySettingsWithDefaults.oldHello, "baah" ) .withSetting( MySettingsWithDefaults.oldSetting, "booh" ) .withConfigClasses( Arrays.asList( mySettingsWithDefaults, myMigratingSettings, new GraphDatabaseSettings() ) ) .build(); // When config.setLogger( log ); // Then verify( log ).warn( "%s is deprecated. Replaced by %s", MySettingsWithDefaults.oldHello.name(), MySettingsWithDefaults.hello.name() ); verify( log ).warn( "%s is deprecated.", MySettingsWithDefaults.oldSetting.name() ); verifyNoMoreInteractions( log ); }
public CommunityNeoServer build() throws IOException { if ( dataDir == null && persistent ) { throw new IllegalStateException( "Must specify path" ); } final File configFile = buildBefore(); Log log = logProvider.getLog( getClass() ); Config config = Config.fromFile( configFile ).withServerDefaults().build(); config.setLogger( log ); return build( configFile, config, GraphDatabaseDependencies.newDependencies().userLogProvider( logProvider ) .monitors( new Monitors() ) ); }
config.setLogger( logging.getInternalLog( Config.class ) );
dependencies = dependencies.userLogProvider( userLogProvider ); log = userLogProvider.getLog( getClass() ); config.setLogger( log );
config.setLogger( logging.getInternalLog( Config.class ) );