From 296aad894507042da2ad8e764b9f67a0208207b0 Mon Sep 17 00:00:00 2001 From: Ragnar Mellbin Date: Mon, 18 Sep 2017 16:07:34 +0200 Subject: [PATCH] Update fulltext addon test after rebase --- .../fulltext/FulltextIndexConfiguration.java | 15 +++-- .../api/impl/fulltext/WritableFulltext.java | 14 ++++- .../bloom/BloomKernelExtension.java | 23 +++---- .../bloom/BloomKernelExtensionFactory.java | 4 +- .../integrations/bloom/BloomProcedures.java | 4 +- .../impl/fulltext/FulltextAnalyzerTest.java | 60 +++++++++---------- 6 files changed, 65 insertions(+), 55 deletions(-) diff --git a/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/FulltextIndexConfiguration.java b/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/FulltextIndexConfiguration.java index 0d4c276b913c..770a29bff54b 100644 --- a/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/FulltextIndexConfiguration.java +++ b/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/FulltextIndexConfiguration.java @@ -5,17 +5,17 @@ * 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. + * it under the terms of the GNU Affero 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. + * GNU Affero 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ package org.neo4j.kernel.api.impl.fulltext; @@ -30,7 +30,6 @@ import java.util.Set; import static org.apache.lucene.document.Field.Store.NO; -import static org.apache.lucene.document.Field.Store.YES; import static org.neo4j.kernel.api.impl.fulltext.FulltextProvider.FIELD_CONFIG_ANALYZER; import static org.neo4j.kernel.api.impl.fulltext.FulltextProvider.FIELD_CONFIG_PROPERTIES; import static org.neo4j.kernel.api.impl.fulltext.FulltextProvider.FIELD_METADATA_DOC; @@ -44,7 +43,7 @@ class FulltextIndexConfiguration FulltextIndexConfiguration( Document doc ) { - properties = new HashSet( Arrays.asList( doc.getValues( FIELD_CONFIG_PROPERTIES ) ) ); + properties = new HashSet<>( Arrays.asList( doc.getValues( FIELD_CONFIG_PROPERTIES ) ) ); analyzerClassName = doc.get( FIELD_CONFIG_ANALYZER ); } diff --git a/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/WritableFulltext.java b/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/WritableFulltext.java index 25f5fbec923f..90f3396d4bca 100644 --- a/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/WritableFulltext.java +++ b/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/WritableFulltext.java @@ -27,15 +27,27 @@ class WritableFulltext extends WritableAbstractDatabaseIndex { - private PartitionedIndexWriter indexWriter; WritableFulltext( LuceneFulltext luceneFulltext ) throws IOException { super( luceneFulltext ); + } + + @Override + public void open() throws IOException + { + super.open(); indexWriter = luceneIndex.getIndexWriter( this ); } + @Override + public void drop() throws IOException + { + super.drop(); + indexWriter = null; + } + PartitionedIndexWriter getIndexWriter() { return indexWriter; 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 5ac4bf7e7779..55221a7c1a4d 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 @@ -36,13 +36,16 @@ import org.neo4j.logging.Log; import org.neo4j.scheduler.JobScheduler; +import static org.neo4j.kernel.api.impl.fulltext.FulltextProvider.FulltextIndexType.NODES; +import static org.neo4j.kernel.api.impl.fulltext.FulltextProvider.FulltextIndexType.RELATIONSHIPS; +import static org.neo4j.kernel.api.impl.fulltext.integrations.bloom.BloomKernelExtensionFactory.BLOOM_NODES; +import static org.neo4j.kernel.api.impl.fulltext.integrations.bloom.BloomKernelExtensionFactory.BLOOM_RELATIONSHIPS; + class BloomKernelExtension extends LifecycleAdapter { - public static final String BLOOM_RELATIONSHIPS = "bloomRelationships"; - public static final String BLOOM_NODES = "bloomNodes"; private final File storeDir; private final Config config; - private final FileSystemAbstraction fileSystemAbstraction; + private final FileSystemAbstraction fileSystem; private final GraphDatabaseService db; private final Procedures procedures; private LogService logService; @@ -50,14 +53,14 @@ class BloomKernelExtension extends LifecycleAdapter private final JobScheduler scheduler; private FulltextProvider provider; - BloomKernelExtension( FileSystemAbstraction fileSystemAbstraction, File storeDir, Config config, + BloomKernelExtension( FileSystemAbstraction fileSystem, File storeDir, Config config, GraphDatabaseService db, Procedures procedures, LogService logService, AvailabilityGuard availabilityGuard, JobScheduler scheduler ) { this.storeDir = storeDir; this.config = config; - this.fileSystemAbstraction = fileSystemAbstraction; + this.fileSystem = fileSystem; this.db = db; this.procedures = procedures; this.logService = logService; @@ -70,14 +73,14 @@ public void init() throws IOException, KernelException { if ( config.get( LoadableBloomFulltextConfig.bloom_enabled ) ) { - List properties = getProperties( ); - String analyzer = config.get( LoadableBloomFulltextConfig.bloom_analyzer); + List properties = getProperties(); + String analyzer = config.get( LoadableBloomFulltextConfig.bloom_analyzer ); Log log = logService.getInternalLog( FulltextProvider.class ); provider = new FulltextProvider( db, log, availabilityGuard, scheduler ); - FulltextFactory fulltextFactory = new FulltextFactory( fileSystemAbstraction, storeDir, analyzer, provider ); - fulltextFactory.createFulltextIndex( BLOOM_NODES, FulltextProvider.FulltextIndexType.NODES, properties ); - fulltextFactory.createFulltextIndex( BLOOM_RELATIONSHIPS, FulltextProvider.FulltextIndexType.RELATIONSHIPS, properties ); + FulltextFactory fulltextFactory = new FulltextFactory( fileSystem, storeDir, analyzer, provider ); + fulltextFactory.createFulltextIndex( BLOOM_NODES, NODES, properties ); + fulltextFactory.createFulltextIndex( BLOOM_RELATIONSHIPS, RELATIONSHIPS, properties ); provider.init(); procedures.registerComponent( FulltextProvider.class, context -> provider, true ); 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 7a53f838af8f..2ca681b7b24b 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 @@ -43,7 +43,9 @@ public class BloomKernelExtensionFactory extends KernelExtensionFactory { - private static final String SERVICE_NAME = "bloom"; + public static final String SERVICE_NAME = "bloom"; + public static final String BLOOM_RELATIONSHIPS = "bloomRelationships"; + public static final String BLOOM_NODES = "bloomNodes"; public interface Dependencies { diff --git a/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/integrations/bloom/BloomProcedures.java b/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/integrations/bloom/BloomProcedures.java index 0884c588b41c..22a2d4de8b32 100644 --- a/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/integrations/bloom/BloomProcedures.java +++ b/enterprise/fulltext-addon/src/main/java/org/neo4j/kernel/api/impl/fulltext/integrations/bloom/BloomProcedures.java @@ -36,8 +36,8 @@ import org.neo4j.procedure.Name; import org.neo4j.procedure.Procedure; -import static org.neo4j.kernel.api.impl.fulltext.integrations.bloom.BloomKernelExtension.BLOOM_NODES; -import static org.neo4j.kernel.api.impl.fulltext.integrations.bloom.BloomKernelExtension.BLOOM_RELATIONSHIPS; +import static org.neo4j.kernel.api.impl.fulltext.integrations.bloom.BloomKernelExtensionFactory.BLOOM_NODES; +import static org.neo4j.kernel.api.impl.fulltext.integrations.bloom.BloomKernelExtensionFactory.BLOOM_RELATIONSHIPS; import static org.neo4j.procedure.Mode.READ; /** 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 1b16b0d149d5..4964defeb869 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 @@ -27,6 +27,7 @@ import static java.util.Collections.singletonList; import static org.neo4j.kernel.api.impl.fulltext.FulltextProvider.FulltextIndexType.NODES; +import static org.neo4j.kernel.api.impl.fulltext.integrations.bloom.BloomKernelExtensionFactory.BLOOM_NODES; public class FulltextAnalyzerTest extends LuceneFulltextTestSupport { @@ -39,7 +40,7 @@ public void shouldBeAbleToSpecifyEnglishAnalyzer() throws Exception try ( FulltextProvider provider = createProvider() ) { FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, ENGLISH, provider ); - fulltextFactory.createFulltextIndex( "bloomNodes", NODES, singletonList( "prop" ) ); + fulltextFactory.createFulltextIndex( BLOOM_NODES, NODES, singletonList( "prop" ) ); provider.init(); long id; @@ -51,7 +52,7 @@ public void shouldBeAbleToSpecifyEnglishAnalyzer() throws Exception tx.success(); } - try ( ReadOnlyFulltext reader = provider.getReader( "bloomNodes", NODES ) ) + try ( ReadOnlyFulltext reader = provider.getReader( BLOOM_NODES, NODES ) ) { assertExactQueryFindsNothing( reader, "and" ); assertExactQueryFindsNothing( reader, "in" ); @@ -69,7 +70,7 @@ public void shouldBeAbleToSpecifySwedishAnalyzer() throws Exception try ( FulltextProvider provider = createProvider(); ) { FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, SWEDISH, provider ); - fulltextFactory.createFulltextIndex( "bloomNodes", NODES, singletonList( "prop" ) ); + fulltextFactory.createFulltextIndex( BLOOM_NODES, NODES, singletonList( "prop" ) ); provider.init(); long id; @@ -81,7 +82,7 @@ public void shouldBeAbleToSpecifySwedishAnalyzer() throws Exception tx.success(); } - try ( ReadOnlyFulltext reader = provider.getReader( "bloomNodes", NODES ) ) + try ( ReadOnlyFulltext reader = provider.getReader( BLOOM_NODES, NODES ) ) { assertExactQueryFindsIds( reader, "and", id ); assertExactQueryFindsIds( reader, "in", id ); @@ -96,56 +97,49 @@ public void shouldBeAbleToSpecifySwedishAnalyzer() throws Exception @Test public void shouldReindexNodesWhenAnalyzerIsChanged() throws Exception { - GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); - File storeDir = testDirectory.graphDbDir(); - long firstID; long secondID; - try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ) ) + try ( FulltextProvider provider = createProvider() ) { - FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, storeDir, ENGLISH, provider ); - fulltextFactory.createFulltextIndex( "bloomNodes", NODES, singletonList( "prop" ) ); + FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, ENGLISH, provider ); + fulltextFactory.createFulltextIndex( BLOOM_NODES, NODES, singletonList( "prop" ) ); provider.init(); try ( Transaction tx = db.beginTx() ) { - Node node = db.createNode( LABEL ); - Node node2 = db.createNode( LABEL ); - firstID = node.getId(); - secondID = node2.getId(); - node.setProperty( "prop", "Hello and hello again, in the end." ); - node2.setProperty( "prop", "En apa och en tomte bodde i ett hus." ); + firstID = createNodeIndexableByPropertyValue( "Hello and hello again, in the end." ); + secondID = createNodeIndexableByPropertyValue( "En apa och en tomte bodde i ett hus." ); tx.success(); } - try ( ReadOnlyFulltext reader = provider.getReader( "bloomNodes", NODES ) ) + try ( ReadOnlyFulltext reader = provider.getReader( BLOOM_NODES, NODES ) ) { - assertFalse( reader.query( "and" ).hasNext() ); - assertFalse( reader.query( "in" ).hasNext() ); - assertFalse( reader.query( "the" ).hasNext() ); - assertEquals( secondID, reader.query( "en" ).next() ); - assertEquals( secondID, reader.query( "och" ).next() ); - assertEquals( secondID, reader.query( "ett" ).next() ); + assertExactQueryFindsNothing( reader, "and" ); + assertExactQueryFindsNothing( reader, "in" ); + assertExactQueryFindsNothing( reader, "the" ); + assertExactQueryFindsIds( reader, "en", secondID ); + assertExactQueryFindsIds( reader, "och", secondID ); + assertExactQueryFindsIds( reader, "ett", secondID ); } } - try ( FulltextProvider provider = new FulltextProvider( db, LOG, availabilityGuard ); ) + try ( FulltextProvider provider = createProvider() ) { - FulltextFactory fulltextFactory = new FulltextFactory( fileSystemRule, storeDir, SWEDISH, provider ); - fulltextFactory.createFulltextIndex( "bloomNodes", NODES, singletonList( "prop" ) ); + FulltextFactory fulltextFactory = new FulltextFactory( fs, storeDir, SWEDISH, provider ); + fulltextFactory.createFulltextIndex( BLOOM_NODES, NODES, singletonList( "prop" ) ); provider.init(); provider.awaitPopulation(); - try ( ReadOnlyFulltext reader = provider.getReader( "bloomNodes", NODES ) ) + try ( ReadOnlyFulltext reader = provider.getReader( BLOOM_NODES, NODES ) ) { - assertEquals( firstID, reader.query( "and" ).next() ); - assertEquals( firstID, reader.query( "in" ).next() ); - assertEquals( firstID, reader.query( "the" ).next() ); - assertFalse( reader.query( "en" ).hasNext() ); - assertFalse( reader.query( "och" ).hasNext() ); - assertFalse( reader.query( "ett" ).hasNext() ); + assertExactQueryFindsIds( reader, "and", firstID ); + assertExactQueryFindsIds( reader, "in", firstID ); + assertExactQueryFindsIds( reader, "the", firstID ); + assertExactQueryFindsNothing( reader, "en" ); + assertExactQueryFindsNothing( reader, "och" ); + assertExactQueryFindsNothing( reader, "ett" ); } } }