From 64919f7550247fa86f04d6853d982b1d4fd8cbcb Mon Sep 17 00:00:00 2001 From: Mikhaylo Demianenko Date: Fri, 15 Jan 2016 11:26:12 +0100 Subject: [PATCH] Switch to default file system and specific test directory to make windows build pass in couple of tests. --- .../kernel/api/impl/index/AbstractLuceneIndex.java | 4 ---- .../kernel/api/impl/index/LuceneLabelScanStore.java | 5 ++++- .../impl/index/PartitionedLuceneLabelScanWriter.java | 4 ++-- ...intVerificationUniqueLuceneIndexPopulatorTest.java | 10 +++++++--- .../api/impl/index/LuceneDocumentStructureTest.java | 2 -- .../impl/index/LuceneSchemaIndexPopulatorTest.java | 11 +++++++---- .../kernel/api/impl/index/LuceneSchemaIndexTest.java | 10 ++++++---- 7 files changed, 26 insertions(+), 20 deletions(-) diff --git a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/index/AbstractLuceneIndex.java b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/index/AbstractLuceneIndex.java index 8b31cde5cbbee..bab8f552c3e00 100644 --- a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/index/AbstractLuceneIndex.java +++ b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/index/AbstractLuceneIndex.java @@ -168,10 +168,6 @@ public void drop() throws IOException public void flush() throws IOException { - if (!open) - { - return; - } commitCloseLock.lock(); try { diff --git a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/index/LuceneLabelScanStore.java b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/index/LuceneLabelScanStore.java index 2ad7e73b5fb0a..d3cd9d698c801 100644 --- a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/index/LuceneLabelScanStore.java +++ b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/index/LuceneLabelScanStore.java @@ -108,7 +108,10 @@ public void force() { try { - luceneIndex.flush(); + if ( luceneIndex.isOpen() ) + { + luceneIndex.flush(); + } } catch ( IOException e ) { diff --git a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/index/PartitionedLuceneLabelScanWriter.java b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/index/PartitionedLuceneLabelScanWriter.java index 092f77ffcf53b..6638b90c52adf 100644 --- a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/index/PartitionedLuceneLabelScanWriter.java +++ b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/index/PartitionedLuceneLabelScanWriter.java @@ -20,6 +20,7 @@ package org.neo4j.kernel.api.impl.index; import org.apache.lucene.document.Document; +import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; import org.apache.lucene.search.IndexSearcher; @@ -45,9 +46,8 @@ public class PartitionedLuceneLabelScanWriter implements LabelScanWriter { - // TODO: Integer.MAX_VALUE usually used as sentinel marker in lucene, test can we use it as max partition size ? private final Integer MAXIMUM_PARTITION_SIZE = - Integer.getInteger( "labelScanStore.maxPartitionSize", Integer.MAX_VALUE ); + Integer.getInteger( "labelScanStore.maxPartitionSize", IndexWriter.MAX_DOCS ); private final BitmapDocumentFormat format; diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/DeferredConstraintVerificationUniqueLuceneIndexPopulatorTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/DeferredConstraintVerificationUniqueLuceneIndexPopulatorTest.java index 28f2fb40019bd..3aad5a82a4524 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/DeferredConstraintVerificationUniqueLuceneIndexPopulatorTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/DeferredConstraintVerificationUniqueLuceneIndexPopulatorTest.java @@ -28,6 +28,7 @@ import java.util.Collections; import org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction; +import org.neo4j.io.fs.DefaultFileSystemAbstraction; import org.neo4j.kernel.api.impl.index.builder.LuceneSchemaIndexBuilder; import org.neo4j.kernel.api.impl.index.populator.DeferredConstraintVerificationUniqueLuceneIndexPopulator; import org.neo4j.kernel.api.impl.index.storage.DirectoryFactory; @@ -40,6 +41,7 @@ import org.neo4j.test.CleanupRule; import org.neo4j.test.OtherThreadExecutor; import org.neo4j.test.OtherThreadExecutor.WorkerCommand; +import org.neo4j.test.TargetDirectory; import static java.util.Arrays.asList; import static java.util.concurrent.TimeUnit.SECONDS; @@ -56,6 +58,8 @@ public class DeferredConstraintVerificationUniqueLuceneIndexPopulatorTest { @Rule public final CleanupRule cleanup = new CleanupRule(); + @Rule + public TargetDirectory.TestDirectory testDir = TargetDirectory.testDirForTest( getClass() ); private static final int LABEL_ID = 1; private static final int PROPERTY_KEY_ID = 2; @@ -456,9 +460,9 @@ public void shouldReleaseSearcherProperlyAfterVerifyingDeferredConstraints() thr private DeferredConstraintVerificationUniqueLuceneIndexPopulator newPopulator() throws IOException { - EphemeralFileSystemAbstraction fileSystem = new EphemeralFileSystemAbstraction(); - indexStorage = new PartitionedIndexStorage( directoryFactory, fileSystem, new File( - "/target/whatever" ), INDEX_IDENTIFIER ); + DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(); + indexStorage = new PartitionedIndexStorage( directoryFactory, fileSystem, + testDir.directory( "folder" ), INDEX_IDENTIFIER ); LuceneSchemaIndex index = LuceneSchemaIndexBuilder.create() .withIndexStorage( indexStorage ) .build(); diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneDocumentStructureTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneDocumentStructureTest.java index 17f8a5063464d..542e2e2d68a0e 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneDocumentStructureTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneDocumentStructureTest.java @@ -22,14 +22,12 @@ import org.apache.commons.lang3.RandomStringUtils; import org.apache.lucene.document.Document; import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.NumericRangeQuery; import org.apache.lucene.search.PrefixQuery; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TermRangeQuery; import org.junit.Test; -import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertNull; import static junit.framework.TestCase.assertEquals; import static org.neo4j.kernel.api.impl.index.LuceneDocumentStructure.NODE_ID_KEY; diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneSchemaIndexPopulatorTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneSchemaIndexPopulatorTest.java index 236e0845b703c..059c666f9e729 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneSchemaIndexPopulatorTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneSchemaIndexPopulatorTest.java @@ -31,7 +31,6 @@ import org.junit.Rule; import org.junit.Test; -import java.io.File; import java.io.IOException; import java.util.HashSet; import java.util.Set; @@ -48,7 +47,8 @@ import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.impl.api.index.IndexStoreView; import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; -import org.neo4j.test.EphemeralFileSystemRule; +import org.neo4j.test.DefaultFileSystemRule; +import org.neo4j.test.TargetDirectory; import static java.lang.Long.parseLong; import static java.util.Arrays.asList; @@ -59,7 +59,10 @@ public class LuceneSchemaIndexPopulatorTest { @Rule - public final EphemeralFileSystemRule fs = new EphemeralFileSystemRule(); + public final DefaultFileSystemRule fs = new DefaultFileSystemRule(); + @Rule + public TargetDirectory.TestDirectory testDir = TargetDirectory.testDirForTest( getClass() ); + private IndexDescriptor indexDescriptor; private IndexStoreView indexStoreView; private LuceneSchemaIndexProvider provider; @@ -76,7 +79,7 @@ public void before() throws Exception directory = new RAMDirectory(); DirectoryFactory directoryFactory = new DirectoryFactory.Single( new DirectoryFactory.UncloseableDirectory( directory ) ); - provider = new LuceneSchemaIndexProvider( fs.get(), directoryFactory, new File( "/target/whatever" ) ); + provider = new LuceneSchemaIndexProvider( fs.get(), directoryFactory, testDir.directory( "folder" ) ); indexDescriptor = new IndexDescriptor( 42, propertyKeyId ); indexStoreView = mock( IndexStoreView.class ); IndexConfiguration indexConfig = IndexConfiguration.NON_UNIQUE; diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneSchemaIndexTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneSchemaIndexTest.java index e57070135b95f..760b42b9e9c07 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneSchemaIndexTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneSchemaIndexTest.java @@ -26,21 +26,23 @@ import org.junit.Rule; import org.junit.Test; -import java.io.File; import java.io.IOException; import java.util.UUID; import org.neo4j.io.IOUtils; import org.neo4j.kernel.api.impl.index.builder.LuceneSchemaIndexBuilder; import org.neo4j.kernel.api.impl.index.storage.DirectoryFactory; -import org.neo4j.test.EphemeralFileSystemRule; +import org.neo4j.test.DefaultFileSystemRule; +import org.neo4j.test.TargetDirectory; import static org.junit.Assert.assertTrue; public class LuceneSchemaIndexTest { @Rule - public final EphemeralFileSystemRule fs = new EphemeralFileSystemRule(); + public final DefaultFileSystemRule fs = new DefaultFileSystemRule(); + @Rule + public TargetDirectory.TestDirectory testDir = TargetDirectory.testDirForTest( getClass() ); private final DirectoryFactory dirFactory = new DirectoryFactory.InMemoryDirectoryFactory(); private LuceneSchemaIndex index; @@ -138,7 +140,7 @@ private LuceneSchemaIndex newSchemaIndex( boolean unique ) builder = builder.uniqueIndex(); } return builder - .withIndexRootFolder( new File( "/graph.db" ) ) + .withIndexRootFolder( testDir.directory( "index" ) ) .withDirectoryFactory( dirFactory ) .withFileSystem( fs.get() ) .withIndexIdentifier( "testIndex" )