Skip to content

Commit

Permalink
Fix all the tests that were broken my the change in the default behav…
Browse files Browse the repository at this point in the history
…iour of Config.fromFile.
  • Loading branch information
chrisvest committed Nov 27, 2018
1 parent 771994d commit 94a0271
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,11 @@ private static void checkDbState( DatabaseLayout databaseLayout, Config addition

private static Config loadNeo4jConfig( Path homeDir, Path configDir, String databaseName, Config additionalConfig )
{
Config config = Config.fromFile( configDir.resolve( Config.DEFAULT_CONFIG_FILE_NAME ) ).withHome( homeDir ).withConnectorsDisabled().build();
Config config = Config.fromFile( configDir.resolve( Config.DEFAULT_CONFIG_FILE_NAME ) )
.withHome( homeDir )
.withConnectorsDisabled()
.withNoThrowOnFileLoadFailure()
.build();
config.augment( additionalConfig );
config.augment( GraphDatabaseSettings.active_database, databaseName );
return config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ private Config buildConfig( String databaseName )
return Config.fromFile( configDir.resolve( Config.DEFAULT_CONFIG_FILE_NAME ) )
.withHome( homeDir )
.withConnectorsDisabled()
.withNoThrowOnFileLoadFailure()
.withSetting( GraphDatabaseSettings.active_database, databaseName )
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@ private static Config loadAdditionalConfig( Optional<Path> additionalConfigFile

private static Config loadNeo4jConfig( Path homeDir, Path configDir, String databaseName, Config additionalConfig )
{
Config config = Config.fromFile( configDir.resolve( Config.DEFAULT_CONFIG_FILE_NAME ) ).withHome( homeDir ).withConnectorsDisabled().build();
Config config = Config.fromFile( configDir.resolve( Config.DEFAULT_CONFIG_FILE_NAME ) )
.withHome( homeDir )
.withConnectorsDisabled()
.withNoThrowOnFileLoadFailure()
.build();
config.augment( additionalConfig );
config.augment( GraphDatabaseSettings.active_database, databaseName );
return config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ private Config buildConfig( String databaseName )
return Config.fromFile( configDir.resolve( Config.DEFAULT_CONFIG_FILE_NAME ) )
.withHome( homeDir )
.withConnectorsDisabled()
.withNoThrowOnFileLoadFailure()
.withSetting( GraphDatabaseSettings.active_database, databaseName )
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ private static void loadFromFile( @Nonnull File file, @Nonnull Log log, boolean
{
if ( throwOnFileLoadFailure )
{
throw new UncheckedIOException( new IOException( "Config file [" + file + "] does not exist." ) );
throw new ConfigLoadIOException( new IOException( "Config file [" + file + "] does not exist." ) );
}
log.warn( "Config file [%s] does not exist.", file );
return;
Expand Down Expand Up @@ -857,7 +857,7 @@ public Object put( Object key, Object val )
{
if ( throwOnFileLoadFailure )
{
throw new UncheckedIOException( "Unable to load config file [" + file + "].", e );
throw new ConfigLoadIOException( "Unable to load config file [" + file + "].", e );
}
log.error( "Unable to load config file [%s]: %s", file, e.getMessage() );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2002-2018 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.configuration;

import java.io.IOException;
import java.io.UncheckedIOException;

/**
* Thrown when a {@link Config} instance could not be loaded from a specified file.
*/
public class ConfigLoadIOException extends UncheckedIOException
{
public ConfigLoadIOException( String message, IOException cause )
{
super( message, cause );
}

public ConfigLoadIOException( IOException cause )
{
super( cause );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ public void shouldLogIfConfigFileCouldNotBeRead() throws IOException
verify( log ).error( "Unable to load config file [%s]: %s", confFile, confFile + " (Permission denied)" );
}

@Test( expected = UncheckedIOException.class )
@Test( expected = ConfigLoadIOException.class )
public void mustThrowIfConfigFileCouldNotBeFound()
{
File confFile = testDirectory.file( "test.conf" );

Config.fromFile( confFile ).build();
}

@Test( expected = UncheckedIOException.class )
@Test( expected = ConfigLoadIOException.class )
public void mustThrowIfConfigFileCoutNotBeRead() throws IOException
{
File confFile = testDirectory.file( "test.conf" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ Config loadNeo4jConfig()
{
return Config.fromFile( configDir.resolve( Config.DEFAULT_CONFIG_FILE_NAME ) )
.withHome( homeDir )
.withConnectorsDisabled().build();
.withConnectorsDisabled()
.withNoThrowOnFileLoadFailure()
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public final int start( File homeDir, Optional<File> configFile, Map<String, Str
.withSettings( configOverrides )
.withHome(homeDir)
.withValidators( configurationValidators() )
.withNoThrowOnFileLoadFailure() // TODO 4.0: Remove this, and require a neo4j.conf file to be present?
.withServerDefaults().build();

LogProvider userLogProvider = setupLogging( config );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.List;

import org.neo4j.dbms.DatabaseManagementSystemSettings;
Expand Down Expand Up @@ -201,7 +202,19 @@ public void shouldRetainRegistrationOrderOfThirdPartyJaxRsPackages()
assertEquals( "/extension1", thirdpartyJaxRsPackages.get( 0 ).getMountPoint() );
assertEquals( "/extension2", thirdpartyJaxRsPackages.get( 1 ).getMountPoint() );
assertEquals( "/extension3", thirdpartyJaxRsPackages.get( 2 ).getMountPoint() );
}

@Test( expected = UncheckedIOException.class )
public void shouldThrowWhenSpecifiedConfigFileDoesNotExist()
{
// Given
File nonExistentConfigFile = new File( "/tmp/" + System.currentTimeMillis() );

// When
Config config = Config.fromFile( nonExistentConfigFile ).withHome( folder.getRoot() ).build();

// Then
assertNotNull( config );
}

@Test
Expand All @@ -211,7 +224,7 @@ public void shouldWorkFineWhenSpecifiedConfigFileDoesNotExist()
File nonExistentConfigFile = new File( "/tmp/" + System.currentTimeMillis() );

// When
Config config = Config.fromFile( nonExistentConfigFile ).withHome( folder.getRoot() ).build();
Config config = Config.fromFile( nonExistentConfigFile ).withHome( folder.getRoot() ).withNoThrowOnFileLoadFailure().build();

// Then
assertNotNull( config );
Expand Down

0 comments on commit 94a0271

Please sign in to comment.