Skip to content

Commit

Permalink
Removed IndexStorageFactory#shutdown()
Browse files Browse the repository at this point in the history
Method was used to close the DirectoryFactory which was passed in as a
constructor dependency. This was not a good idea because DirectoryFactory has
a completely different lifecycle than IndexStorageFactory. Closing of the
in-memory directory factory caused flaky tests because content of in-memory
lucene directories did not survive intentional database restarts.
  • Loading branch information
lutovich authored and MishaDemianenko committed Jan 21, 2016
1 parent 381858a commit e480e9b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
Expand Up @@ -98,7 +98,6 @@ public IndexAccessor getOnlineAccessor( long indexId, IndexConfiguration config,
@Override @Override
public void shutdown() throws Throwable public void shutdown() throws Throwable
{ // Nothing to shut down { // Nothing to shut down
indexStorageFactory.shutdown();
} }


@Override @Override
Expand Down
Expand Up @@ -25,25 +25,19 @@


public class IndexStorageFactory public class IndexStorageFactory
{ {
private final DirectoryFactory directoryFactory; private final DirectoryFactory dirFactory;
private final FileSystemAbstraction fileSystem; private final FileSystemAbstraction fileSystem;
private final File indexRootFolder; private final File indexRootFolder;


public IndexStorageFactory( DirectoryFactory directoryFactory, FileSystemAbstraction fileSystem, public IndexStorageFactory( DirectoryFactory dirFactory, FileSystemAbstraction fileSystem, File indexRootFolder )
File indexRootFolder )
{ {
this.directoryFactory = directoryFactory; this.dirFactory = dirFactory;
this.fileSystem = fileSystem; this.fileSystem = fileSystem;
this.indexRootFolder = indexRootFolder; this.indexRootFolder = indexRootFolder;
} }


public PartitionedIndexStorage indexStorageOf( long indexId ) public PartitionedIndexStorage indexStorageOf( long indexId )
{ {
return new PartitionedIndexStorage( directoryFactory, fileSystem, indexRootFolder, String.valueOf( indexId ) ); return new PartitionedIndexStorage( dirFactory, fileSystem, indexRootFolder, String.valueOf( indexId ) );
}

public void shutdown()
{
directoryFactory.close();
} }
} }
Expand Up @@ -19,24 +19,24 @@
*/ */
package org.neo4j.kernel.api.impl.index; package org.neo4j.kernel.api.impl.index;


import java.util.Arrays;
import java.util.Map;

import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;


import java.util.Arrays;
import java.util.Map;

import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label; import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction;
import org.neo4j.graphdb.schema.IndexDefinition; import org.neo4j.graphdb.schema.IndexDefinition;
import org.neo4j.graphdb.schema.Schema.IndexState; import org.neo4j.graphdb.schema.Schema.IndexState;
import org.neo4j.test.EphemeralFileSystemRule;
import org.neo4j.test.TestGraphDatabaseFactory; import org.neo4j.test.TestGraphDatabaseFactory;


import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;

import static org.neo4j.graphdb.Label.label; import static org.neo4j.graphdb.Label.label;
import static org.neo4j.graphdb.Neo4jMatchers.containsOnly; import static org.neo4j.graphdb.Neo4jMatchers.containsOnly;
import static org.neo4j.graphdb.Neo4jMatchers.createIndex; import static org.neo4j.graphdb.Neo4jMatchers.createIndex;
Expand All @@ -51,7 +51,9 @@


public class SchemaIndexAcceptanceTest public class SchemaIndexAcceptanceTest
{ {
private EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction(); @Rule
public final EphemeralFileSystemRule fsRule = new EphemeralFileSystemRule();

private GraphDatabaseService db; private GraphDatabaseService db;
private final Label label = label( "PERSON" ); private final Label label = label( "PERSON" );
private final String propertyKey = "key"; private final String propertyKey = "key";
Expand Down Expand Up @@ -172,15 +174,12 @@ public void recoveryAfterCreateAndDropIndex() throws Exception


private GraphDatabaseService newDb() private GraphDatabaseService newDb()
{ {
return new TestGraphDatabaseFactory().setFileSystem( fs ).newImpermanentDatabase(); return new TestGraphDatabaseFactory().setFileSystem( fsRule.get() ).newImpermanentDatabase();
} }


private void crashAndRestart() private void crashAndRestart()
{ {
EphemeralFileSystemAbstraction snapshot = fs.snapshot(); fsRule.snapshot( db::shutdown );
db.shutdown();
fs.shutdown();
fs = snapshot;
db = newDb(); db = newDb();
} }


Expand Down

0 comments on commit e480e9b

Please sign in to comment.