Skip to content

Commit

Permalink
Do not explicitly load the bloom procedures
Browse files Browse the repository at this point in the history
As this causes the DB to crash on startup when starting with the plugin
jar. The procedures are picked up separately and explicitly loading them
as well leads to a conflict. This also means that we need to load the
procedures manually in the integration test.
  • Loading branch information
ragadeeshu committed Sep 27, 2017
1 parent b625815 commit dd1a748
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
Expand Up @@ -89,7 +89,6 @@ public void start() throws IOException, KernelException


provider.init(); provider.init();
procedures.registerComponent( FulltextProvider.class, context -> provider, true ); procedures.registerComponent( FulltextProvider.class, context -> provider, true );
procedures.registerProcedure( BloomProcedures.class );
} }
} }


Expand Down
Expand Up @@ -39,12 +39,15 @@
import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.config.InvalidSettingException; import org.neo4j.graphdb.config.InvalidSettingException;
import org.neo4j.graphdb.factory.GraphDatabaseBuilder; import org.neo4j.graphdb.factory.GraphDatabaseBuilder;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.helpers.collection.Iterators; import org.neo4j.helpers.collection.Iterators;
import org.neo4j.helpers.progress.ProgressMonitorFactory; import org.neo4j.helpers.progress.ProgressMonitorFactory;
import org.neo4j.kernel.api.exceptions.KernelException;
import org.neo4j.kernel.api.impl.fulltext.FulltextProvider; import org.neo4j.kernel.api.impl.fulltext.FulltextProvider;
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.proc.Procedures;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.logging.NullLogProvider; import org.neo4j.logging.NullLogProvider;
import org.neo4j.test.TestGraphDatabaseFactory;
import org.neo4j.test.mockito.matcher.RootCauseMatcher; import org.neo4j.test.mockito.matcher.RootCauseMatcher;
import org.neo4j.test.rule.TestDirectory; import org.neo4j.test.rule.TestDirectory;
import org.neo4j.test.rule.fs.DefaultFileSystemRule; import org.neo4j.test.rule.fs.DefaultFileSystemRule;
Expand Down Expand Up @@ -76,17 +79,23 @@ public class BloomIT
@Before @Before
public void before() throws Exception public void before() throws Exception
{ {
TestGraphDatabaseFactory factory = new TestGraphDatabaseFactory(); GraphDatabaseFactory factory = new GraphDatabaseFactory();
factory.setFileSystem( fs.get() );
builder = factory.newEmbeddedDatabaseBuilder( testDirectory.graphDbDir() ); builder = factory.newEmbeddedDatabaseBuilder( testDirectory.graphDbDir() );
builder.setConfig( bloom_enabled, "true" ); builder.setConfig( bloom_enabled, "true" );
} }


private GraphDatabaseService getDb() throws KernelException
{
GraphDatabaseService db = builder.newGraphDatabase();
((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency( Procedures.class ).registerProcedure( BloomProcedures.class );
return db;
}

@Test @Test
public void shouldPopulateAndQueryIndexes() throws Exception public void shouldPopulateAndQueryIndexes() throws Exception
{ {
builder.setConfig( bloom_indexed_properties, "prop, relprop" ); builder.setConfig( bloom_indexed_properties, "prop, relprop" );
db = builder.newGraphDatabase(); db = getDb();
try ( Transaction transaction = db.beginTx() ) try ( Transaction transaction = db.beginTx() )
{ {
Node node1 = db.createNode(); Node node1 = db.createNode();
Expand All @@ -112,7 +121,7 @@ public void shouldBeAbleToConfigureAnalyzer() throws Exception
{ {
builder.setConfig( bloom_indexed_properties, "prop" ); builder.setConfig( bloom_indexed_properties, "prop" );
builder.setConfig( BloomFulltextConfig.bloom_analyzer, "org.apache.lucene.analysis.sv.SwedishAnalyzer" ); builder.setConfig( BloomFulltextConfig.bloom_analyzer, "org.apache.lucene.analysis.sv.SwedishAnalyzer" );
db = builder.newGraphDatabase(); db = getDb();
try ( Transaction transaction = db.beginTx() ) try ( Transaction transaction = db.beginTx() )
{ {
Node node1 = db.createNode(); Node node1 = db.createNode();
Expand All @@ -138,7 +147,7 @@ public void shouldBeAbleToConfigureAnalyzer() throws Exception
public void shouldPopulateIndexWithExistingDataOnIndexCreate() throws Exception public void shouldPopulateIndexWithExistingDataOnIndexCreate() throws Exception
{ {
builder.setConfig( bloom_indexed_properties, "something" ); builder.setConfig( bloom_indexed_properties, "something" );
db = builder.newGraphDatabase(); db = getDb();


long nodeId; long nodeId;
try ( Transaction tx = db.beginTx() ) try ( Transaction tx = db.beginTx() )
Expand All @@ -154,7 +163,7 @@ public void shouldPopulateIndexWithExistingDataOnIndexCreate() throws Exception


builder.setConfig( bloom_indexed_properties, "prop" ); builder.setConfig( bloom_indexed_properties, "prop" );
builder.setConfig( BloomFulltextConfig.bloom_analyzer, "org.apache.lucene.analysis.da.DanishAnalyzer" ); builder.setConfig( BloomFulltextConfig.bloom_analyzer, "org.apache.lucene.analysis.da.DanishAnalyzer" );
db = builder.newGraphDatabase(); db = getDb();


db.execute( "CALL db.fulltext.bloomAwaitPopulation" ).close(); db.execute( "CALL db.fulltext.bloomAwaitPopulation" ).close();


Expand All @@ -169,7 +178,7 @@ public void startupPopulationShouldNotCauseDuplicates() throws Exception
{ {
builder.setConfig( bloom_indexed_properties, "prop" ); builder.setConfig( bloom_indexed_properties, "prop" );


db = builder.newGraphDatabase(); db = getDb();
long nodeId; long nodeId;
try ( Transaction tx = db.beginTx() ) try ( Transaction tx = db.beginTx() )
{ {
Expand All @@ -187,7 +196,7 @@ public void startupPopulationShouldNotCauseDuplicates() throws Exception
assertFalse( result.hasNext() ); assertFalse( result.hasNext() );


db.shutdown(); db.shutdown();
db = builder.newGraphDatabase(); db = getDb();


// Verify it's STILL indexed exactly once // Verify it's STILL indexed exactly once
db.execute( "CALL db.fulltext.bloomAwaitPopulation" ).close(); db.execute( "CALL db.fulltext.bloomAwaitPopulation" ).close();
Expand All @@ -202,7 +211,7 @@ public void staleDataFromEntityDeleteShouldNotBeAccessibleAfterConfigurationChan
{ {
builder.setConfig( bloom_indexed_properties, "prop" ); builder.setConfig( bloom_indexed_properties, "prop" );


db = builder.newGraphDatabase(); db = getDb();
long nodeId; long nodeId;
try ( Transaction tx = db.beginTx() ) try ( Transaction tx = db.beginTx() )
{ {
Expand All @@ -214,7 +223,7 @@ public void staleDataFromEntityDeleteShouldNotBeAccessibleAfterConfigurationChan


db.shutdown(); db.shutdown();
builder.setConfig( bloom_indexed_properties, "not-prop" ); builder.setConfig( bloom_indexed_properties, "not-prop" );
db = builder.newGraphDatabase(); db = getDb();


try ( Transaction tx = db.beginTx() ) try ( Transaction tx = db.beginTx() )
{ {
Expand All @@ -225,7 +234,7 @@ public void staleDataFromEntityDeleteShouldNotBeAccessibleAfterConfigurationChan


db.shutdown(); db.shutdown();
builder.setConfig( bloom_indexed_properties, "prop" ); builder.setConfig( bloom_indexed_properties, "prop" );
db = builder.newGraphDatabase(); db = getDb();


// Verify that the node is no longer indexed // Verify that the node is no longer indexed
db.execute( "CALL db.fulltext.bloomAwaitPopulation" ).close(); db.execute( "CALL db.fulltext.bloomAwaitPopulation" ).close();
Expand All @@ -239,7 +248,7 @@ public void staleDataFromPropertyRemovalShouldNotBeAccessibleAfterConfigurationC
{ {
builder.setConfig( bloom_indexed_properties, "prop" ); builder.setConfig( bloom_indexed_properties, "prop" );


db = builder.newGraphDatabase(); db = getDb();
long nodeId; long nodeId;
try ( Transaction tx = db.beginTx() ) try ( Transaction tx = db.beginTx() )
{ {
Expand All @@ -251,7 +260,7 @@ public void staleDataFromPropertyRemovalShouldNotBeAccessibleAfterConfigurationC


db.shutdown(); db.shutdown();
builder.setConfig( bloom_indexed_properties, "not-prop" ); builder.setConfig( bloom_indexed_properties, "not-prop" );
db = builder.newGraphDatabase(); db = getDb();


try ( Transaction tx = db.beginTx() ) try ( Transaction tx = db.beginTx() )
{ {
Expand All @@ -262,7 +271,7 @@ public void staleDataFromPropertyRemovalShouldNotBeAccessibleAfterConfigurationC


db.shutdown(); db.shutdown();
builder.setConfig( bloom_indexed_properties, "prop" ); builder.setConfig( bloom_indexed_properties, "prop" );
db = builder.newGraphDatabase(); db = getDb();


// Verify that the node is no longer indexed // Verify that the node is no longer indexed
db.execute( "CALL db.fulltext.bloomAwaitPopulation" ).close(); db.execute( "CALL db.fulltext.bloomAwaitPopulation" ).close();
Expand All @@ -275,7 +284,7 @@ public void staleDataFromPropertyRemovalShouldNotBeAccessibleAfterConfigurationC
public void updatesAreAvailableToConcurrentReadTransactions() throws Exception public void updatesAreAvailableToConcurrentReadTransactions() throws Exception
{ {
builder.setConfig( bloom_indexed_properties, "prop" ); builder.setConfig( bloom_indexed_properties, "prop" );
db = builder.newGraphDatabase(); db = getDb();


try ( Transaction tx = db.beginTx() ) try ( Transaction tx = db.beginTx() )
{ {
Expand Down Expand Up @@ -312,22 +321,22 @@ public void updatesAreAvailableToConcurrentReadTransactions() throws Exception
public void shouldNotBeAbleToStartWithoutConfiguringProperties() throws Exception public void shouldNotBeAbleToStartWithoutConfiguringProperties() throws Exception
{ {
expectedException.expect( new RootCauseMatcher<>( RuntimeException.class, "Properties to index must be configured for bloom fulltext" ) ); expectedException.expect( new RootCauseMatcher<>( RuntimeException.class, "Properties to index must be configured for bloom fulltext" ) );
db = builder.newGraphDatabase(); db = getDb();
} }


@Test @Test
public void shouldNotBeAbleToStartWithIllegalPropertyKey() throws Exception public void shouldNotBeAbleToStartWithIllegalPropertyKey() throws Exception
{ {
expectedException.expect( InvalidSettingException.class ); expectedException.expect( InvalidSettingException.class );
builder.setConfig( bloom_indexed_properties, "prop, " + FulltextProvider.FIELD_ENTITY_ID + ", hello" ); builder.setConfig( bloom_indexed_properties, "prop, " + FulltextProvider.FIELD_ENTITY_ID + ", hello" );
db = builder.newGraphDatabase(); db = getDb();
} }


@Test @Test
public void shouldBeAbleToRunConsistencyCheck() throws Exception public void shouldBeAbleToRunConsistencyCheck() throws Exception
{ {
builder.setConfig( bloom_indexed_properties, "prop" ); builder.setConfig( bloom_indexed_properties, "prop" );
db = builder.newGraphDatabase(); db = getDb();


try ( Transaction tx = db.beginTx() ) try ( Transaction tx = db.beginTx() )
{ {
Expand All @@ -354,7 +363,7 @@ public void shouldReindexNodesWhenAnalyzerIsChanged() throws Exception
builder.setConfig( bloom_indexed_properties, "prop" ); builder.setConfig( bloom_indexed_properties, "prop" );
builder.setConfig( BloomFulltextConfig.bloom_analyzer, ENGLISH ); builder.setConfig( BloomFulltextConfig.bloom_analyzer, ENGLISH );


db = builder.newGraphDatabase(); db = getDb();
try ( Transaction tx = db.beginTx() ) try ( Transaction tx = db.beginTx() )
{ {
db.createNode().setProperty( "prop", "Hello and hello again." ); db.createNode().setProperty( "prop", "Hello and hello again." );
Expand All @@ -376,7 +385,7 @@ public void shouldReindexNodesWhenAnalyzerIsChanged() throws Exception


db.shutdown(); db.shutdown();
builder.setConfig( BloomFulltextConfig.bloom_analyzer, SWEDISH ); builder.setConfig( BloomFulltextConfig.bloom_analyzer, SWEDISH );
db = builder.newGraphDatabase(); db = getDb();
db.execute( "CALL db.fulltext.bloomAwaitPopulation" ).close(); db.execute( "CALL db.fulltext.bloomAwaitPopulation" ).close();


try ( Transaction ignore = db.beginTx() ) try ( Transaction ignore = db.beginTx() )
Expand All @@ -398,7 +407,7 @@ public void shouldReindexAfterBeingTemporarilyDisabled() throws Exception
builder.setConfig( bloom_indexed_properties, "prop" ); builder.setConfig( bloom_indexed_properties, "prop" );


// Create a node while the index is enabled. // Create a node while the index is enabled.
db = builder.newGraphDatabase(); db = getDb();
try ( Transaction tx = db.beginTx() ) try ( Transaction tx = db.beginTx() )
{ {
db.createNode().setProperty( "prop", "Hello and hello again." ); db.createNode().setProperty( "prop", "Hello and hello again." );
Expand All @@ -420,7 +429,7 @@ public void shouldReindexAfterBeingTemporarilyDisabled() throws Exception
// Re-enable the index and restart. Wait for the index to rebuild. // Re-enable the index and restart. Wait for the index to rebuild.
db.shutdown(); db.shutdown();
builder.setConfig( bloom_enabled, "true" ); builder.setConfig( bloom_enabled, "true" );
db = builder.newGraphDatabase(); db = getDb();
db.execute( "CALL db.fulltext.bloomAwaitPopulation" ).close(); db.execute( "CALL db.fulltext.bloomAwaitPopulation" ).close();


// Now we should be able to find the node that was added while the index was disabled. // Now we should be able to find the node that was added while the index was disabled.
Expand Down

0 comments on commit dd1a748

Please sign in to comment.