From 65acc5b2fcc0d4c24ffc1cb8fab871074310541d Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Tue, 19 Sep 2017 14:05:41 +0200 Subject: [PATCH] Start the fulltext index applier background thread via the JobScheduler --- .../api/impl/fulltext/FulltextProvider.java | 7 +- .../impl/fulltext/FulltextUpdateApplier.java | 34 +++-- .../bloom/BloomKernelExtension.java | 10 +- .../bloom/BloomKernelExtensionFactory.java | 19 ++- .../impl/fulltext/FulltextAnalyzerTest.java | 27 ++-- .../fulltext/LuceneFulltextUpdaterTest.java | 116 ++++++++++++------ 6 files changed, 141 insertions(+), 72 deletions(-) diff --git a/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/FulltextProvider.java b/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/FulltextProvider.java index 85df70386f4d2..2ea287311732f 100644 --- a/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/FulltextProvider.java +++ b/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/FulltextProvider.java @@ -29,6 +29,7 @@ import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.kernel.AvailabilityGuard; import org.neo4j.logging.Log; +import org.neo4j.scheduler.JobScheduler; /** * Provider class that manages and provides fulltext indices. This is the main entry point for the fulltext addon. @@ -52,12 +53,14 @@ public class FulltextProvider implements AutoCloseable * @param db Database that this provider should work with. * @param log For logging errors. * @param availabilityGuard Used for waiting with populating the index until the database is available. + * @param scheduler */ - public FulltextProvider( GraphDatabaseService db, Log log, AvailabilityGuard availabilityGuard ) + public FulltextProvider( GraphDatabaseService db, Log log, AvailabilityGuard availabilityGuard, + JobScheduler scheduler ) { this.db = db; this.log = log; - applier = new FulltextUpdateApplier( log, availabilityGuard ); + applier = new FulltextUpdateApplier( log, availabilityGuard, scheduler ); applier.start(); fulltextTransactionEventUpdater = new FulltextTransactionEventUpdater( this, log, applier ); nodeProperties = new HashSet<>(); diff --git a/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/FulltextUpdateApplier.java b/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/FulltextUpdateApplier.java index 54cefc13b1fb7..ab421af1669e2 100644 --- a/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/FulltextUpdateApplier.java +++ b/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/FulltextUpdateApplier.java @@ -28,6 +28,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.ExecutionException; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; import java.util.function.Predicate; @@ -45,6 +46,7 @@ import org.neo4j.kernel.AvailabilityGuard; import org.neo4j.kernel.api.impl.schema.writer.PartitionedIndexWriter; import org.neo4j.logging.Log; +import org.neo4j.scheduler.JobScheduler; import static org.neo4j.kernel.api.impl.fulltext.LuceneFulltextDocumentStructure.documentForPopulation; import static org.neo4j.kernel.api.impl.fulltext.LuceneFulltextDocumentStructure.documentRepresentingProperties; @@ -54,16 +56,20 @@ class FulltextUpdateApplier { private static final FulltextIndexUpdate STOP_SIGNAL = () -> null; private static final int POPULATING_BATCH_SIZE = 10_000; + private static final JobScheduler.Group UPDATE_APPLIER = new JobScheduler.Group( "FulltextIndexUpdateApplier" ); + private static final String APPLIER_THREAD_NAME = "Fulltext Index Add-On Applier Thread"; private final LinkedBlockingQueue workQueue; private final Log log; private final AvailabilityGuard availabilityGuard; - private ApplierThread workerThread; + private final JobScheduler scheduler; + private JobScheduler.JobHandle workerThread; - FulltextUpdateApplier( Log log, AvailabilityGuard availabilityGuard ) + FulltextUpdateApplier( Log log, AvailabilityGuard availabilityGuard, JobScheduler scheduler ) { this.log = log; this.availabilityGuard = availabilityGuard; + this.scheduler = scheduler; workQueue = new LinkedBlockingQueue<>(); } @@ -203,10 +209,9 @@ void start() { if ( workerThread != null ) { - throw new IllegalStateException( workerThread.getName() + " already started." ); + throw new IllegalStateException( APPLIER_THREAD_NAME + " already started." ); } - workerThread = new ApplierThread( workQueue, log, availabilityGuard ); - workerThread.start(); + workerThread = scheduler.schedule( UPDATE_APPLIER, new ApplierWorker( workQueue, log, availabilityGuard ) ); } void stop() @@ -220,12 +225,16 @@ void stop() try { - workerThread.join(); + workerThread.waitTermination(); workerThread = null; } catch ( InterruptedException e ) { - log.error( "Interrupted before " + workerThread.getName() + " could shut down.", e ); + log.error( "Interrupted before " + APPLIER_THREAD_NAME + " could shut down.", e ); + } + catch ( ExecutionException e ) + { + log.error( "Exception while waiting for " + APPLIER_THREAD_NAME + " to shut down.", e ); } } @@ -234,25 +243,24 @@ private interface FulltextIndexUpdate Pair applyUpdateAndReturnIndex() throws IOException; } - private static class ApplierThread extends Thread + private static class ApplierWorker implements Runnable { private LinkedBlockingQueue workQueue; private final Log log; private final AvailabilityGuard availabilityGuard; - ApplierThread( LinkedBlockingQueue workQueue, Log log, + ApplierWorker( LinkedBlockingQueue workQueue, Log log, AvailabilityGuard availabilityGuard ) { - super( "Fulltext Index Add-On Applier Thread" ); this.workQueue = workQueue; this.log = log; this.availabilityGuard = availabilityGuard; - setDaemon( true ); } @Override public void run() { + Thread.currentThread().setName( APPLIER_THREAD_NAME ); waitForDatabaseToBeAvailable(); Set refreshableSet = Collections.newSetFromMap( new IdentityHashMap<>() ); List latches = new ArrayList<>(); @@ -324,7 +332,7 @@ private FulltextIndexUpdate getNextUpdate() } catch ( InterruptedException e ) { - log.debug( getName() + " decided to ignore an interrupt.", e ); + log.debug( APPLIER_THREAD_NAME + " decided to ignore an interrupt.", e ); } } while ( update == null ); @@ -358,7 +366,7 @@ private void refreshIndex( WritableFulltext index ) } catch ( IOException e ) { - log.error( "Failed to refresh fulltext after updates", e ); + log.error( "Failed to refresh fulltext after updates.", e ); } } } diff --git a/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/integrations/bloom/BloomKernelExtension.java b/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/integrations/bloom/BloomKernelExtension.java index cb207a1d75e85..5db438fbbb7e5 100644 --- a/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/integrations/bloom/BloomKernelExtension.java +++ b/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/integrations/bloom/BloomKernelExtension.java @@ -35,6 +35,8 @@ import org.neo4j.kernel.impl.logging.LogService; import org.neo4j.kernel.impl.proc.Procedures; import org.neo4j.kernel.lifecycle.LifecycleAdapter; +import org.neo4j.logging.Log; +import org.neo4j.scheduler.JobScheduler; class BloomKernelExtension extends LifecycleAdapter { @@ -47,11 +49,13 @@ class BloomKernelExtension extends LifecycleAdapter private final Procedures procedures; private LogService logService; private final AvailabilityGuard availabilityGuard; + private final JobScheduler scheduler; private FulltextProvider provider; BloomKernelExtension( FileSystemAbstraction fileSystemAbstraction, File storeDir, Config config, GraphDatabaseService db, Procedures procedures, - LogService logService, AvailabilityGuard availabilityGuard ) + LogService logService, AvailabilityGuard availabilityGuard, + JobScheduler scheduler ) { this.storeDir = storeDir; this.config = config; @@ -60,6 +64,7 @@ class BloomKernelExtension extends LifecycleAdapter this.procedures = procedures; this.logService = logService; this.availabilityGuard = availabilityGuard; + this.scheduler = scheduler; } @Override @@ -68,7 +73,8 @@ public void init() throws IOException, KernelException List properties = config.get( LoadableBloomFulltextConfig.bloom_indexed_properties ); Analyzer analyzer = getAnalyzer(); - provider = new FulltextProvider( db, logService.getInternalLog( FulltextProvider.class ), availabilityGuard ); + Log log = logService.getInternalLog( FulltextProvider.class ); + provider = new FulltextProvider( db, log, availabilityGuard, scheduler ); FulltextFactory fulltextFactory = new FulltextFactory( fileSystemAbstraction, storeDir, analyzer ); fulltextFactory.createFulltextIndex( BLOOM_NODES, FulltextProvider.FulltextIndexType.NODES, properties, provider ); fulltextFactory.createFulltextIndex( BLOOM_RELATIONSHIPS, FulltextProvider.FulltextIndexType.RELATIONSHIPS, properties, provider ); diff --git a/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/integrations/bloom/BloomKernelExtensionFactory.java b/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/integrations/bloom/BloomKernelExtensionFactory.java index 5a417c3a53292..68897869d36a0 100644 --- a/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/integrations/bloom/BloomKernelExtensionFactory.java +++ b/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/integrations/bloom/BloomKernelExtensionFactory.java @@ -19,6 +19,8 @@ */ package org.neo4j.kernel.api.impl.fulltext.integrations.bloom; +import java.io.File; + import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.kernel.AvailabilityGuard; @@ -28,11 +30,12 @@ import org.neo4j.kernel.impl.proc.Procedures; import org.neo4j.kernel.impl.spi.KernelContext; import org.neo4j.kernel.lifecycle.Lifecycle; +import org.neo4j.scheduler.JobScheduler; /** * A {@link KernelExtensionFactory} for the bloom fulltext addon. * - * @see BloomProcedure + * @see BloomProcedures * @see LoadableBloomFulltextConfig */ public class BloomKernelExtensionFactory extends KernelExtensionFactory @@ -53,6 +56,8 @@ public interface Dependencies LogService logService(); AvailabilityGuard availabilityGuard(); + + JobScheduler scheduler(); } BloomKernelExtensionFactory() @@ -63,7 +68,15 @@ public interface Dependencies @Override public Lifecycle newInstance( KernelContext context, Dependencies dependencies ) throws Throwable { - return new BloomKernelExtension( dependencies.fileSystem(), context.storeDir(), dependencies.getConfig(), dependencies.db(), - dependencies.procedures(), dependencies.logService(), dependencies.availabilityGuard() ); + FileSystemAbstraction fs = dependencies.fileSystem(); + File storeDir = context.storeDir(); + Config config = dependencies.getConfig(); + GraphDatabaseService db = dependencies.db(); + Procedures procedures = dependencies.procedures(); + LogService logService = dependencies.logService(); + AvailabilityGuard availabilityGuard = dependencies.availabilityGuard(); + JobScheduler scheduler = dependencies.scheduler(); + return new BloomKernelExtension( + fs, storeDir, config, db, procedures, logService, availabilityGuard, scheduler ); } } diff --git a/enterprise/fulltext-addon/src/test/java/org/neo4j/kernel/api/impl/fulltext/FulltextAnalyzerTest.java b/enterprise/fulltext-addon/src/test/java/org/neo4j/kernel/api/impl/fulltext/FulltextAnalyzerTest.java index 4cf545bd55e90..b43acd713ddc7 100644 --- a/enterprise/fulltext-addon/src/test/java/org/neo4j/kernel/api/impl/fulltext/FulltextAnalyzerTest.java +++ b/enterprise/fulltext-addon/src/test/java/org/neo4j/kernel/api/impl/fulltext/FulltextAnalyzerTest.java @@ -21,7 +21,6 @@ import org.apache.lucene.analysis.en.EnglishAnalyzer; import org.apache.lucene.analysis.sv.SwedishAnalyzer; -import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; @@ -31,14 +30,13 @@ import org.neo4j.graphdb.Label; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Transaction; +import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.kernel.AvailabilityGuard; import org.neo4j.kernel.internal.GraphDatabaseAPI; import org.neo4j.logging.NullLog; +import org.neo4j.scheduler.JobScheduler; import org.neo4j.test.rule.DatabaseRule; import org.neo4j.test.rule.EmbeddedDatabaseRule; -import org.neo4j.test.rule.TestDirectory; -import org.neo4j.test.rule.fs.DefaultFileSystemRule; -import org.neo4j.test.rule.fs.FileSystemRule; import static java.util.Collections.singletonList; import static org.junit.Assert.assertEquals; @@ -49,10 +47,7 @@ public class FulltextAnalyzerTest { private static final Label LABEL = Label.label( "label" ); private static final NullLog LOG = NullLog.getInstance(); - @ClassRule - public static FileSystemRule fileSystemRule = new DefaultFileSystemRule(); - @ClassRule - public static TestDirectory testDirectory = TestDirectory.testDirectory( fileSystemRule ); + @Rule public DatabaseRule dbRule = new EmbeddedDatabaseRule().startLazily(); @@ -62,10 +57,12 @@ public class FulltextAnalyzerTest public void shouldBeAbleToSpecifyEnglishAnalyzer() throws Exception { GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); - File storeDir = testDirectory.graphDbDir(); - FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, storeDir, new EnglishAnalyzer() ); + JobScheduler scheduler = dbRule.resolveDependency( JobScheduler.class ); + FileSystemAbstraction fs = dbRule.resolveDependency( FileSystemAbstraction.class ); + File storeDir = dbRule.getStoreDir(); + FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, new EnglishAnalyzer() ); - try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ) ) + try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard, scheduler ) ) { fulltextFactory.createFulltextIndex( "bloomNodes", NODES, singletonList( "prop" ), provider ); provider.init(); @@ -101,10 +98,12 @@ public void shouldBeAbleToSpecifyEnglishAnalyzer() throws Exception public void shouldBeAbleToSpecifySwedishAnalyzer() throws Exception { GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); - File storeDir = testDirectory.graphDbDir(); - FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, storeDir, new SwedishAnalyzer() ); + JobScheduler scheduler = dbRule.resolveDependency( JobScheduler.class ); + FileSystemAbstraction fs = dbRule.resolveDependency( FileSystemAbstraction.class ); + File storeDir = dbRule.getStoreDir(); + FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, new SwedishAnalyzer() ); - try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ); ) + try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard, scheduler ); ) { fulltextFactory.createFulltextIndex( "bloomNodes", NODES, singletonList( "prop" ), provider ); provider.init(); diff --git a/enterprise/fulltext-addon/src/test/java/org/neo4j/kernel/api/impl/fulltext/LuceneFulltextUpdaterTest.java b/enterprise/fulltext-addon/src/test/java/org/neo4j/kernel/api/impl/fulltext/LuceneFulltextUpdaterTest.java index e9e535206c6bf..db2b5d97d0f80 100644 --- a/enterprise/fulltext-addon/src/test/java/org/neo4j/kernel/api/impl/fulltext/LuceneFulltextUpdaterTest.java +++ b/enterprise/fulltext-addon/src/test/java/org/neo4j/kernel/api/impl/fulltext/LuceneFulltextUpdaterTest.java @@ -20,10 +20,10 @@ package org.neo4j.kernel.api.impl.fulltext; import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; +import java.io.File; import java.time.Clock; import java.util.Arrays; @@ -33,15 +33,14 @@ import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.RelationshipType; import org.neo4j.graphdb.Transaction; +import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.kernel.AvailabilityGuard; import org.neo4j.kernel.internal.GraphDatabaseAPI; import org.neo4j.logging.Log; import org.neo4j.logging.NullLog; +import org.neo4j.scheduler.JobScheduler; import org.neo4j.test.rule.DatabaseRule; import org.neo4j.test.rule.EmbeddedDatabaseRule; -import org.neo4j.test.rule.TestDirectory; -import org.neo4j.test.rule.fs.DefaultFileSystemRule; -import org.neo4j.test.rule.fs.FileSystemRule; import static java.util.Collections.singletonList; import static org.junit.Assert.assertEquals; @@ -54,10 +53,6 @@ public class LuceneFulltextUpdaterTest public static final StandardAnalyzer ANALYZER = new StandardAnalyzer(); private static final Log LOG = NullLog.getInstance(); - @ClassRule - public static FileSystemRule fileSystemRule = new DefaultFileSystemRule(); - @Rule - public TestDirectory testDirectory = TestDirectory.testDirectory( fileSystemRule ); @Rule public DatabaseRule dbRule = new EmbeddedDatabaseRule().startLazily(); @@ -70,9 +65,12 @@ public class LuceneFulltextUpdaterTest public void shouldFindNodeWithString() throws Exception { GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); - FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, testDirectory.graphDbDir(), ANALYZER ); + JobScheduler scheduler = dbRule.resolveDependency( JobScheduler.class ); + FileSystemAbstraction fs = dbRule.resolveDependency( FileSystemAbstraction.class ); + File storeDir = dbRule.getStoreDir(); + FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, ANALYZER ); - try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ) ) + try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard, scheduler ) ) { fulltextFactory.createFulltextIndex( "nodes", NODES, singletonList( "prop" ), provider ); provider.init(); @@ -107,9 +105,12 @@ public void shouldFindNodeWithString() throws Exception public void shouldFindNodeWithNumber() throws Exception { GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); - FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, testDirectory.graphDbDir(), ANALYZER ); + JobScheduler scheduler = dbRule.resolveDependency( JobScheduler.class ); + FileSystemAbstraction fs = dbRule.resolveDependency( FileSystemAbstraction.class ); + File storeDir = dbRule.getStoreDir(); + FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, ANALYZER ); - try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ) ) + try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard, scheduler ) ) { fulltextFactory.createFulltextIndex( "nodes", NODES, singletonList( "prop" ), provider ); provider.init(); @@ -144,9 +145,12 @@ public void shouldFindNodeWithNumber() throws Exception public void shouldFindNodeWithBoolean() throws Exception { GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); - FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, testDirectory.graphDbDir(), ANALYZER ); + JobScheduler scheduler = dbRule.resolveDependency( JobScheduler.class ); + FileSystemAbstraction fs = dbRule.resolveDependency( FileSystemAbstraction.class ); + File storeDir = dbRule.getStoreDir(); + FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, ANALYZER ); - try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ) ) + try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard, scheduler ) ) { fulltextFactory.createFulltextIndex( "nodes", NODES, singletonList( "prop" ), provider ); provider.init(); @@ -181,9 +185,12 @@ public void shouldFindNodeWithBoolean() throws Exception public void shouldFindNodeWithArrays() throws Exception { GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); - FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, testDirectory.graphDbDir(), ANALYZER ); + JobScheduler scheduler = dbRule.resolveDependency( JobScheduler.class ); + FileSystemAbstraction fs = dbRule.resolveDependency( FileSystemAbstraction.class ); + File storeDir = dbRule.getStoreDir(); + FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, ANALYZER ); - try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ) ) + try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard, scheduler ) ) { fulltextFactory.createFulltextIndex( "nodes", NODES, singletonList( "prop" ), provider ); provider.init(); @@ -226,9 +233,12 @@ public void shouldFindNodeWithArrays() throws Exception public void shouldRepresentPropertyChanges() throws Exception { GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); - FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, testDirectory.graphDbDir(), ANALYZER ); + JobScheduler scheduler = dbRule.resolveDependency( JobScheduler.class ); + FileSystemAbstraction fs = dbRule.resolveDependency( FileSystemAbstraction.class ); + File storeDir = dbRule.getStoreDir(); + FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, ANALYZER ); - try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ) ) + try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard, scheduler ) ) { fulltextFactory.createFulltextIndex( "nodes", NODES, singletonList( "prop" ), provider ); provider.init(); @@ -277,9 +287,12 @@ public void shouldRepresentPropertyChanges() throws Exception public void shouldNotFindRemovedNodes() throws Exception { GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); - FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, testDirectory.graphDbDir(), ANALYZER ); + JobScheduler scheduler = dbRule.resolveDependency( JobScheduler.class ); + FileSystemAbstraction fs = dbRule.resolveDependency( FileSystemAbstraction.class ); + File storeDir = dbRule.getStoreDir(); + FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, ANALYZER ); - try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ) ) + try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard, scheduler ) ) { fulltextFactory.createFulltextIndex( "nodes", NODES, singletonList( "prop" ), provider ); provider.init(); @@ -322,9 +335,12 @@ public void shouldNotFindRemovedNodes() throws Exception public void shouldNotFindRemovedProperties() throws Exception { GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); - FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, testDirectory.graphDbDir(), ANALYZER ); + JobScheduler scheduler = dbRule.resolveDependency( JobScheduler.class ); + FileSystemAbstraction fs = dbRule.resolveDependency( FileSystemAbstraction.class ); + File storeDir = dbRule.getStoreDir(); + FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, ANALYZER ); - try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ) ) + try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard, scheduler ) ) { fulltextFactory.createFulltextIndex( "nodes", NODES, Arrays.asList( "prop", "prop2" ), provider ); provider.init(); @@ -387,9 +403,12 @@ public void shouldNotFindRemovedProperties() throws Exception public void shouldOnlyIndexIndexedProperties() throws Exception { GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); - FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, testDirectory.graphDbDir(), ANALYZER ); + JobScheduler scheduler = dbRule.resolveDependency( JobScheduler.class ); + FileSystemAbstraction fs = dbRule.resolveDependency( FileSystemAbstraction.class ); + File storeDir = dbRule.getStoreDir(); + FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, ANALYZER ); - try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ) ) + try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard, scheduler ) ) { fulltextFactory.createFulltextIndex( "nodes", NODES, singletonList( "prop" ), provider ); provider.init(); @@ -423,9 +442,12 @@ public void shouldOnlyIndexIndexedProperties() throws Exception public void shouldSearchAcrossMultipleProperties() throws Exception { GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); - FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, testDirectory.graphDbDir(), ANALYZER ); + JobScheduler scheduler = dbRule.resolveDependency( JobScheduler.class ); + FileSystemAbstraction fs = dbRule.resolveDependency( FileSystemAbstraction.class ); + File storeDir = dbRule.getStoreDir(); + FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, ANALYZER ); - try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ) ) + try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard, scheduler ) ) { fulltextFactory.createFulltextIndex( "nodes", NODES, Arrays.asList( "prop", "prop2" ), provider ); provider.init(); @@ -465,9 +487,12 @@ public void shouldSearchAcrossMultipleProperties() throws Exception public void shouldOrderResultsBasedOnRelevance() throws Exception { GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); - FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, testDirectory.graphDbDir(), ANALYZER ); + JobScheduler scheduler = dbRule.resolveDependency( JobScheduler.class ); + FileSystemAbstraction fs = dbRule.resolveDependency( FileSystemAbstraction.class ); + File storeDir = dbRule.getStoreDir(); + FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, ANALYZER ); - try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ) ) + try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard, scheduler ) ) { fulltextFactory.createFulltextIndex( "nodes", NODES, Arrays.asList( "first", "last" ), provider ); provider.init(); @@ -514,9 +539,12 @@ public void shouldOrderResultsBasedOnRelevance() throws Exception public void shouldDifferentiateNodesAndRelationships() throws Exception { GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); - FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, testDirectory.graphDbDir(), ANALYZER ); + JobScheduler scheduler = dbRule.resolveDependency( JobScheduler.class ); + FileSystemAbstraction fs = dbRule.resolveDependency( FileSystemAbstraction.class ); + File storeDir = dbRule.getStoreDir(); + FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, ANALYZER ); - try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ) ) + try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard, scheduler ) ) { fulltextFactory.createFulltextIndex( "nodes", NODES, singletonList( "prop" ), provider ); fulltextFactory.createFulltextIndex( "relationships", RELATIONSHIPS, singletonList( "prop" ), provider ); @@ -576,9 +604,12 @@ public void shouldDifferentiateNodesAndRelationships() throws Exception public void fuzzyQueryShouldBeFuzzy() throws Exception { GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); - FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, testDirectory.graphDbDir(), ANALYZER ); + JobScheduler scheduler = dbRule.resolveDependency( JobScheduler.class ); + FileSystemAbstraction fs = dbRule.resolveDependency( FileSystemAbstraction.class ); + File storeDir = dbRule.getStoreDir(); + FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, ANALYZER ); - try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ) ) + try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard, scheduler ) ) { fulltextFactory.createFulltextIndex( "nodes", NODES, singletonList( "prop" ), provider ); provider.init(); @@ -617,9 +648,12 @@ public void fuzzyQueryShouldBeFuzzy() throws Exception public void fuzzyQueryShouldReturnExactMatchesFirst() throws Exception { GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); - FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, testDirectory.graphDbDir(), ANALYZER ); + JobScheduler scheduler = dbRule.resolveDependency( JobScheduler.class ); + FileSystemAbstraction fs = dbRule.resolveDependency( FileSystemAbstraction.class ); + File storeDir = dbRule.getStoreDir(); + FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, ANALYZER ); - try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ) ) + try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard, scheduler ) ) { fulltextFactory.createFulltextIndex( "nodes", NODES, singletonList( "prop" ), provider ); provider.init(); @@ -663,9 +697,12 @@ public void fuzzyQueryShouldReturnExactMatchesFirst() throws Exception public void shouldNotReturnNonMatches() throws Exception { GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); - FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, testDirectory.graphDbDir(), ANALYZER ); + JobScheduler scheduler = dbRule.resolveDependency( JobScheduler.class ); + FileSystemAbstraction fs = dbRule.resolveDependency( FileSystemAbstraction.class ); + File storeDir = dbRule.getStoreDir(); + FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, ANALYZER ); - try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ) ) + try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard, scheduler ) ) { fulltextFactory.createFulltextIndex( "nodes", NODES, singletonList( "prop" ), provider ); fulltextFactory.createFulltextIndex( "relationships", RELATIONSHIPS, singletonList( "prop" ), provider ); @@ -704,7 +741,10 @@ public void shouldNotReturnNonMatches() throws Exception public void shouldPopulateIndexWithExistingNodesAndRelationships() throws Exception { GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); - FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, testDirectory.graphDbDir(), ANALYZER ); + JobScheduler scheduler = dbRule.resolveDependency( JobScheduler.class ); + FileSystemAbstraction fs = dbRule.resolveDependency( FileSystemAbstraction.class ); + File storeDir = dbRule.getStoreDir(); + FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, ANALYZER ); long firstNodeID; long secondNodeID; @@ -730,7 +770,7 @@ public void shouldPopulateIndexWithExistingNodesAndRelationships() throws Except tx.success(); } - try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ) ) + try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard, scheduler ) ) { fulltextFactory.createFulltextIndex( "nodes", NODES, singletonList( "prop" ), provider ); fulltextFactory.createFulltextIndex( "relationships", RELATIONSHIPS, singletonList( "prop" ), provider );