Skip to content

Commit

Permalink
More resilient QueryLoggerIT, use correct database directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Aug 31, 2018
1 parent f158ed8 commit ecd7d67
Showing 1 changed file with 45 additions and 30 deletions.
Expand Up @@ -22,6 +22,7 @@
*/ */
package org.neo4j.kernel.impl.query; package org.neo4j.kernel.impl.query;


import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
Expand Down Expand Up @@ -103,6 +104,8 @@ public class QueryLoggerIT


private File logsDirectory; private File logsDirectory;
private File logFilename; private File logFilename;
private EmbeddedInteraction db;
private GraphDatabaseService database;


@Before @Before
public void setUp() public void setUp()
Expand All @@ -113,7 +116,20 @@ public void setUp()
databaseBuilder = new TestEnterpriseGraphDatabaseFactory() databaseBuilder = new TestEnterpriseGraphDatabaseFactory()
.setFileSystem( new UncloseableDelegatingFileSystemAbstraction( fileSystem.get() ) ) .setFileSystem( new UncloseableDelegatingFileSystemAbstraction( fileSystem.get() ) )
.setInternalLogProvider( inMemoryLog ) .setInternalLogProvider( inMemoryLog )
.newImpermanentDatabaseBuilder( testDirectory.storeDir() ); .newImpermanentDatabaseBuilder( testDirectory.databaseDir() );
}

@After
public void tearDown()
{
if ( db != null )
{
db.tearDown();
}
if ( database != null )
{
database.shutdown();
}
} }


@Test @Test
Expand All @@ -123,7 +139,7 @@ public void shouldLogCustomUserName() throws Throwable
final Map<String, String> config = stringMap( final Map<String, String> config = stringMap(
logs_directory.name(), logsDirectory.getPath(), logs_directory.name(), logsDirectory.getPath(),
log_queries.name(), Settings.TRUE ); log_queries.name(), Settings.TRUE );
EmbeddedInteraction db = new EmbeddedInteraction( databaseBuilder, config ); db = new EmbeddedInteraction( databaseBuilder, config );


// create users // create users
db.getLocalUserManager().newUser( "mats", "neo4j", false ); db.getLocalUserManager().newUser( "mats", "neo4j", false );
Expand Down Expand Up @@ -158,7 +174,7 @@ public void shouldLogTXMetaDataInQueryLog() throws Throwable
// turn on query logging // turn on query logging
databaseBuilder.setConfig( logs_directory, logsDirectory.getPath() ); databaseBuilder.setConfig( logs_directory, logsDirectory.getPath() );
databaseBuilder.setConfig( log_queries, Settings.TRUE ); databaseBuilder.setConfig( log_queries, Settings.TRUE );
EmbeddedInteraction db = new EmbeddedInteraction( databaseBuilder, Collections.emptyMap() ); db = new EmbeddedInteraction( databaseBuilder, Collections.emptyMap() );
GraphDatabaseFacade graph = db.getLocalGraph(); GraphDatabaseFacade graph = db.getLocalGraph();


db.getLocalUserManager().setUserPassword( "neo4j", "123", false ); db.getLocalUserManager().setUserPassword( "neo4j", "123", false );
Expand Down Expand Up @@ -206,7 +222,7 @@ public void shouldLogTXMetaDataInQueryLog() throws Throwable
@Test @Test
public void shouldLogQuerySlowerThanThreshold() throws Exception public void shouldLogQuerySlowerThanThreshold() throws Exception
{ {
GraphDatabaseService database = databaseBuilder.setConfig( log_queries, Settings.TRUE ) database = databaseBuilder.setConfig( log_queries, Settings.TRUE )
.setConfig( logs_directory, logsDirectory.getPath() ) .setConfig( logs_directory, logsDirectory.getPath() )
.setConfig( GraphDatabaseSettings.log_queries_parameter_logging_enabled, Settings.FALSE ) .setConfig( GraphDatabaseSettings.log_queries_parameter_logging_enabled, Settings.FALSE )
.newGraphDatabase(); .newGraphDatabase();
Expand All @@ -222,7 +238,7 @@ public void shouldLogQuerySlowerThanThreshold() throws Exception
@Test @Test
public void shouldLogParametersWhenNestedMap() throws Exception public void shouldLogParametersWhenNestedMap() throws Exception
{ {
GraphDatabaseService database = databaseBuilder.setConfig( log_queries, Settings.TRUE ) database = databaseBuilder.setConfig( log_queries, Settings.TRUE )
.setConfig( logs_directory, logsDirectory.getPath() ) .setConfig( logs_directory, logsDirectory.getPath() )
.setConfig( GraphDatabaseSettings.log_queries_parameter_logging_enabled, Settings.TRUE ) .setConfig( GraphDatabaseSettings.log_queries_parameter_logging_enabled, Settings.TRUE )
.newGraphDatabase(); .newGraphDatabase();
Expand Down Expand Up @@ -251,7 +267,7 @@ public void shouldLogParametersWhenNestedMap() throws Exception
@Test @Test
public void shouldLogRuntime() throws Exception public void shouldLogRuntime() throws Exception
{ {
GraphDatabaseService database = databaseBuilder.setConfig( GraphDatabaseSettings.log_queries, Settings.TRUE ) database = databaseBuilder.setConfig( GraphDatabaseSettings.log_queries, Settings.TRUE )
.setConfig( GraphDatabaseSettings.logs_directory, logsDirectory.getPath() ) .setConfig( GraphDatabaseSettings.logs_directory, logsDirectory.getPath() )
.setConfig( GraphDatabaseSettings.log_queries_runtime_logging_enabled, Settings.TRUE ) .setConfig( GraphDatabaseSettings.log_queries_runtime_logging_enabled, Settings.TRUE )
.newGraphDatabase(); .newGraphDatabase();
Expand All @@ -267,15 +283,10 @@ public void shouldLogRuntime() throws Exception
query ) ) ); query ) ) );
} }


private static String clientConnectionInfo()
{
return ClientConnectionInfo.EMBEDDED_CONNECTION.withUsername( AUTH_DISABLED.username() ).asConnectionDetails();
}

@Test @Test
public void shouldLogParametersWhenList() throws Exception public void shouldLogParametersWhenList() throws Exception
{ {
GraphDatabaseService database = databaseBuilder.setConfig( log_queries, Settings.TRUE ) database = databaseBuilder.setConfig( log_queries, Settings.TRUE )
.setConfig( logs_directory, logsDirectory.getPath() ) .setConfig( logs_directory, logsDirectory.getPath() )
.newGraphDatabase(); .newGraphDatabase();


Expand All @@ -294,7 +305,7 @@ public void shouldLogParametersWhenList() throws Exception
@Test @Test
public void disabledQueryLogging() public void disabledQueryLogging()
{ {
GraphDatabaseService database = databaseBuilder.setConfig( log_queries, Settings.FALSE ) database = databaseBuilder.setConfig( log_queries, Settings.FALSE )
.setConfig( GraphDatabaseSettings.log_queries_filename, logFilename.getPath() ) .setConfig( GraphDatabaseSettings.log_queries_filename, logFilename.getPath() )
.newGraphDatabase(); .newGraphDatabase();


Expand All @@ -309,7 +320,7 @@ public void disabledQueryLogRotation() throws Exception
final File logsDirectory = new File( testDirectory.storeDir(), "logs" ); final File logsDirectory = new File( testDirectory.storeDir(), "logs" );
final File logFilename = new File( logsDirectory, "query.log" ); final File logFilename = new File( logsDirectory, "query.log" );
final File shiftedLogFilename1 = new File( logsDirectory, "query.log.1" ); final File shiftedLogFilename1 = new File( logsDirectory, "query.log.1" );
GraphDatabaseService database = databaseBuilder.setConfig( log_queries, Settings.TRUE ) database = databaseBuilder.setConfig( log_queries, Settings.TRUE )
.setConfig( logs_directory, logsDirectory.getPath() ) .setConfig( logs_directory, logsDirectory.getPath() )
.setConfig( log_queries_rotation_threshold, "0" ) .setConfig( log_queries_rotation_threshold, "0" )
.newGraphDatabase(); .newGraphDatabase();
Expand Down Expand Up @@ -337,7 +348,7 @@ public void queryLogRotation()
.setConfig( logs_directory, logsDirectory.getPath() ) .setConfig( logs_directory, logsDirectory.getPath() )
.setConfig( log_queries_max_archives, "100" ) .setConfig( log_queries_max_archives, "100" )
.setConfig( log_queries_rotation_threshold, "1" ); .setConfig( log_queries_rotation_threshold, "1" );
GraphDatabaseService database = databaseBuilder.newGraphDatabase(); database = databaseBuilder.newGraphDatabase();


// Logging is done asynchronously, and it turns out it's really hard to make it all work the same on Linux // Logging is done asynchronously, and it turns out it's really hard to make it all work the same on Linux
// and on Windows, so just write many times to make sure we rotate several times. // and on Windows, so just write many times to make sure we rotate several times.
Expand Down Expand Up @@ -382,26 +393,26 @@ public void queryLogRotation()
@Test @Test
public void shouldNotLogPassword() throws Exception public void shouldNotLogPassword() throws Exception
{ {
GraphDatabaseFacade database = (GraphDatabaseFacade) databaseBuilder database = databaseBuilder
.setConfig( log_queries, Settings.TRUE ) .setConfig( log_queries, Settings.TRUE )
.setConfig( logs_directory, logsDirectory.getPath() ) .setConfig( logs_directory, logsDirectory.getPath() )
.setConfig( GraphDatabaseSettings.auth_enabled, Settings.TRUE ) .setConfig( GraphDatabaseSettings.auth_enabled, Settings.TRUE )
.newGraphDatabase(); .newGraphDatabase();
GraphDatabaseFacade facade = (GraphDatabaseFacade) this.database;


EnterpriseAuthManager authManager = database.getDependencyResolver().resolveDependency( EnterpriseAuthManager.class ); EnterpriseAuthManager authManager = facade.getDependencyResolver().resolveDependency( EnterpriseAuthManager.class );
EnterpriseLoginContext neo = authManager.login( AuthToken.newBasicAuthToken( "neo4j", "neo4j" ) ); EnterpriseLoginContext neo = authManager.login( AuthToken.newBasicAuthToken( "neo4j", "neo4j" ) );


String query = "CALL dbms.security.changePassword('abc123')"; String query = "CALL dbms.security.changePassword('abc123')";
try ( InternalTransaction tx = database try ( InternalTransaction tx = facade.beginTransaction( KernelTransaction.Type.explicit, neo ) )
.beginTransaction( KernelTransaction.Type.explicit, neo ) )
{ {
Result res = database.execute( tx, query, VirtualValues.EMPTY_MAP ); Result res = facade.execute( tx, query, VirtualValues.EMPTY_MAP );
res.close(); res.close();
tx.success(); tx.success();
} }
finally finally
{ {
database.shutdown(); facade.shutdown();
} }


List<String> logLines = readAllLines( logFilename ); List<String> logLines = readAllLines( logFilename );
Expand All @@ -415,7 +426,7 @@ public void shouldNotLogPassword() throws Exception
@Test @Test
public void canBeEnabledAndDisabledAtRuntime() throws Exception public void canBeEnabledAndDisabledAtRuntime() throws Exception
{ {
GraphDatabaseService database = databaseBuilder.setConfig( log_queries, Settings.FALSE ).setConfig( GraphDatabaseSettings.log_queries_filename, database = databaseBuilder.setConfig( log_queries, Settings.FALSE ).setConfig( GraphDatabaseSettings.log_queries_filename,
logFilename.getPath() ).newGraphDatabase(); logFilename.getPath() ).newGraphDatabase();
List<String> strings; List<String> strings;


Expand Down Expand Up @@ -468,27 +479,31 @@ public void logQueriesWithSystemTimeZoneIsConfigured()


private void executeSingleQueryWithTimeZoneLog() private void executeSingleQueryWithTimeZoneLog()
{ {
GraphDatabaseFacade database = database = databaseBuilder.setConfig( log_queries, Settings.TRUE )
(GraphDatabaseFacade) databaseBuilder.setConfig( log_queries, Settings.TRUE ) .setConfig( GraphDatabaseSettings.db_timezone, LogTimeZone.SYSTEM.name() )
.setConfig( GraphDatabaseSettings.db_timezone, LogTimeZone.SYSTEM.name() ) .setConfig( logs_directory, logsDirectory.getPath() )
.setConfig( logs_directory, logsDirectory.getPath() ) .newGraphDatabase();
.newGraphDatabase();
database.execute( QUERY ).close(); database.execute( QUERY ).close();
database.shutdown(); database.shutdown();
} }


private void executeQueryAndShutdown( GraphDatabaseService database ) private static void executeQueryAndShutdown( GraphDatabaseService database )
{ {
executeQueryAndShutdown( database, QUERY, Collections.emptyMap() ); executeQueryAndShutdown( database, QUERY, Collections.emptyMap() );
} }


private void executeQueryAndShutdown( GraphDatabaseService database, String query, Map<String,Object> params ) private static void executeQueryAndShutdown( GraphDatabaseService database, String query, Map<String,Object> params )
{ {
Result execute = database.execute( query, params ); Result execute = database.execute( query, params );
execute.close(); execute.close();
database.shutdown(); database.shutdown();
} }


private static String clientConnectionInfo()
{
return ClientConnectionInfo.EMBEDDED_CONNECTION.withUsername( AUTH_DISABLED.username() ).asConnectionDetails();
}

private List<String> readAllLinesSilent( File logFilename ) private List<String> readAllLinesSilent( File logFilename )
{ {
try try
Expand All @@ -506,7 +521,7 @@ private List<String> readAllLines( File logFilename ) throws IOException
return readAllLines( fileSystem.get(), logFilename ); return readAllLines( fileSystem.get(), logFilename );
} }


public static List<String> readAllLines( FileSystemAbstraction fs, File logFilename ) throws IOException static List<String> readAllLines( FileSystemAbstraction fs, File logFilename ) throws IOException
{ {
List<String> logLines = new ArrayList<>(); List<String> logLines = new ArrayList<>();
// this is needed as the EphemeralFSA is broken, and creates a new file when reading a non-existent file from // this is needed as the EphemeralFSA is broken, and creates a new file when reading a non-existent file from
Expand Down

0 comments on commit ecd7d67

Please sign in to comment.