diff --git a/community/kernel/src/test/java/examples/CreateAndLoadDenseNodeIT.java b/community/kernel/src/test/java/examples/CreateAndLoadDenseNodeIT.java index 9471b88f288c4..663528a53e0f6 100644 --- a/community/kernel/src/test/java/examples/CreateAndLoadDenseNodeIT.java +++ b/community/kernel/src/test/java/examples/CreateAndLoadDenseNodeIT.java @@ -104,7 +104,7 @@ private void createDbIfNecessary() } finally { - dbRule.stopAndKeepFiles(); + dbRule.shutdownAndKeepStore(); } } } diff --git a/community/kernel/src/test/java/org/neo4j/test/DatabaseRule.java b/community/kernel/src/test/java/org/neo4j/test/DatabaseRule.java index b14281e8971b7..d22021baebcfc 100644 --- a/community/kernel/src/test/java/org/neo4j/test/DatabaseRule.java +++ b/community/kernel/src/test/java/org/neo4j/test/DatabaseRule.java @@ -333,14 +333,9 @@ private void shutdown( boolean deleteResources ) } } - public void stopAndKeepFiles() + public void shutdownAndKeepStore() { - if ( database != null ) - { - database.shutdown(); - database = null; - statementSupplier = null; - } + shutdown( false ); } public T resolveDependency( Class type ) diff --git a/community/lucene-index/src/test/java/org/neo4j/graphdb/LuceneLabelScanStoreChaosIT.java b/community/lucene-index/src/test/java/org/neo4j/graphdb/LuceneLabelScanStoreChaosIT.java index 4a47a41d8594a..d6011e6da4e13 100644 --- a/community/lucene-index/src/test/java/org/neo4j/graphdb/LuceneLabelScanStoreChaosIT.java +++ b/community/lucene-index/src/test/java/org/neo4j/graphdb/LuceneLabelScanStoreChaosIT.java @@ -52,6 +52,11 @@ */ public class LuceneLabelScanStoreChaosIT { + + @Rule + public final DatabaseRule dbRule = new EmbeddedDatabaseRule( getClass() ); + private final Random random = new Random(); + @Test public void shouldRebuildDeletedLabelScanStoreOnStartup() throws Exception { @@ -97,55 +102,44 @@ public void shouldPreventCorruptedLabelScanStoreToStartup() throws Exception private RestartAction corruptTheLabelScanStoreIndex() { - return new RestartAction() - { - @Override - public void run( FileSystemAbstraction fs, File storeDirectory ) + return ( fs, storeDirectory ) -> { + try { - try + int filesCorrupted = 0; + for ( File file : labelScanStoreIndexDirectory( storeDirectory ).listFiles() ) { - int filesCorrupted = 0; - for ( File file : labelScanStoreIndexDirectory( storeDirectory ).listFiles() ) - { - scrambleFile( file ); - filesCorrupted++; - } - assertTrue( "No files found to corrupt", filesCorrupted > 0 ); - } - catch ( IOException e ) - { - throw new RuntimeException( e ); + scrambleFile( file ); + filesCorrupted++; } + assertTrue( "No files found to corrupt", filesCorrupted > 0 ); + } + catch ( IOException e ) + { + throw new RuntimeException( e ); } }; } private RestartAction deleteTheLabelScanStoreIndex() { - return new RestartAction() - { - @Override - public void run( FileSystemAbstraction fs, File storeDirectory ) + return ( fs, storeDirectory ) -> { + try { - try - { - File directory = labelScanStoreIndexDirectory( storeDirectory ); - assertTrue( "We seem to want to delete the wrong directory here", directory.exists() ); - assertTrue( "No index files to delete", directory.listFiles().length > 0 ); - deleteRecursively( directory ); - } - catch ( IOException e ) - { - throw new RuntimeException( e ); - } + File directory = labelScanStoreIndexDirectory( storeDirectory ); + assertTrue( "We seem to want to delete the wrong directory here", directory.exists() ); + assertTrue( "No index files to delete", directory.listFiles().length > 0 ); + deleteRecursively( directory ); + } + catch ( IOException e ) + { + throw new RuntimeException( e ); } }; } private File labelScanStoreIndexDirectory( File storeDirectory ) { - File directory = new File( new File( new File( storeDirectory, "schema" ), "label" ), "lucene" ); - return directory; + return new File( new File( new File( storeDirectory, "schema" ), "label" ), "lucene" ); } private Node createLabeledNode( Label... labels ) @@ -197,13 +191,10 @@ private void putRandomBytes( byte[] bytes ) } } - private static enum Labels implements Label + private enum Labels implements Label { First, Second, Third; } - - public final @Rule DatabaseRule dbRule = new EmbeddedDatabaseRule( getClass() ); - private final Random random = new Random(); } diff --git a/community/lucene-index/src/test/java/org/neo4j/index/Neo4jTestCase.java b/community/lucene-index/src/test/java/org/neo4j/index/Neo4jTestCase.java index 99e7f29bc418c..255db2da0e479 100644 --- a/community/lucene-index/src/test/java/org/neo4j/index/Neo4jTestCase.java +++ b/community/lucene-index/src/test/java/org/neo4j/index/Neo4jTestCase.java @@ -48,6 +48,12 @@ public static void setUpDb() throws Exception { graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase(); } + + @AfterClass + public static void tearDownDb() throws Exception + { + graphDb.shutdown(); + } @Before public void setUpTest() @@ -93,12 +99,6 @@ protected Transaction beginTx() return tx; } - @AfterClass - public static void tearDownDb() throws Exception - { - graphDb.shutdown(); - } - public static void deleteFileOrDirectory( File file ) { if ( !file.exists() ) diff --git a/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/AbstractLuceneIndexTest.java b/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/AbstractLuceneIndexTest.java index 4fe3ad9381706..64915d0f4fe3d 100644 --- a/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/AbstractLuceneIndexTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/AbstractLuceneIndexTest.java @@ -41,9 +41,10 @@ public abstract class AbstractLuceneIndexTest { + @Rule + public final TestName testname = new TestName(); protected static GraphDatabaseService graphDb; protected Transaction tx; - public final @Rule TestName testname = new TestName(); @BeforeClass public static void setUpStuff() diff --git a/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/AutoIndexerTest.java b/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/AutoIndexerTest.java index 457472574cbc4..4a35e87b0c738 100644 --- a/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/AutoIndexerTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/AutoIndexerTest.java @@ -42,7 +42,8 @@ public class AutoIndexerTest { - public final @Rule DatabaseRule db = new EmbeddedDatabaseRule() + @Rule + public final DatabaseRule db = new EmbeddedDatabaseRule() { @Override protected void configure( GraphDatabaseBuilder builder ) diff --git a/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/IsEmpty.java b/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/IsEmpty.java deleted file mode 100644 index cbba8df8f0cfd..0000000000000 --- a/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/IsEmpty.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2002-2015 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * 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. - * - * 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. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.index.impl.lucene; - -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; - -public class IsEmpty extends TypeSafeMatcher> -{ - private Iterable iterable; - - @Override - public boolean matchesSafely( Iterable iterable ) - { - this.iterable = iterable; - return !iterable.iterator().hasNext(); - } - - public void describeTo( Description description ) - { - description.appendValueList("[", ",", "]", iterable); - } - - public static Matcher> isEmpty() { - return new IsEmpty(); - } -} diff --git a/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/LuceneCommandApplierTest.java b/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/LuceneCommandApplierTest.java index 7714c139a6ef3..94797b60fc9ad 100644 --- a/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/LuceneCommandApplierTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/LuceneCommandApplierTest.java @@ -45,8 +45,10 @@ public class LuceneCommandApplierTest { - public final @Rule EphemeralFileSystemRule fs = new EphemeralFileSystemRule(); - public final @Rule LifeRule life = new LifeRule( true ); + @Rule + public final EphemeralFileSystemRule fs = new EphemeralFileSystemRule(); + @Rule + public final LifeRule life = new LifeRule( true ); private final File dir = new File( "dir" ); @Test diff --git a/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/LuceneDataSourceTest.java b/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/LuceneDataSourceTest.java index 35708c595bd27..4de9080031297 100644 --- a/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/LuceneDataSourceTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/LuceneDataSourceTest.java @@ -46,8 +46,10 @@ public class LuceneDataSourceTest { - public final @Rule LifeRule life = new LifeRule( true ); - public final @Rule TestDirectory directory = TargetDirectory.testDirForTest( getClass() ); + @Rule + public final LifeRule life = new LifeRule( true ); + @Rule + public final TestDirectory directory = TargetDirectory.testDirForTest( getClass() ); private IndexConfigStore indexStore; private LuceneDataSource dataSource; diff --git a/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/LuceneRecoveryIT.java b/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/LuceneRecoveryIT.java index 49cd5738d3bd6..921a782c7d059 100644 --- a/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/LuceneRecoveryIT.java +++ b/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/LuceneRecoveryIT.java @@ -37,16 +37,20 @@ public class LuceneRecoveryIT { + @Test public void testHardCoreRecovery() throws Exception { String path = "target/hcdb"; FileUtils.deleteRecursively( new File( path ) ); + + Process process = Runtime.getRuntime().exec( new String[]{ ProcessUtil.getJavaExecutable().toString(), "-cp", ProcessUtil.getClassPath(), Inserter.class.getName(), path } ); + // Let it run for a while and then kill it, and wait for it to die awaitFile( new File( path, "started" ) ); Thread.sleep( 5000 ); diff --git a/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/PerformanceAndSanityIT.java b/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/PerformanceAndSanityIT.java index 5332b12aa642c..e320eb4403b0a 100644 --- a/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/PerformanceAndSanityIT.java +++ b/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/PerformanceAndSanityIT.java @@ -54,6 +54,9 @@ public class PerformanceAndSanityIT extends AbstractLuceneIndexTest { + @Rule + public final TargetDirectory.TestDirectory testDirectory = TargetDirectory.testDirForTest( getClass() ); + @Ignore @Test public void testNodeInsertionSpeed() @@ -288,7 +291,4 @@ public void run() System.out.println( t1 + ", " + (double)t1/(double)count ); } - - @Rule - public final TargetDirectory.TestDirectory testDirectory = TargetDirectory.testDirForTest( getClass() ); } diff --git a/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/RecoveryTest.java b/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/RecoveryTest.java index 63358337f53ae..3c65929c716fc 100644 --- a/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/RecoveryTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/RecoveryTest.java @@ -25,27 +25,22 @@ import java.io.File; import java.io.IOException; -import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; +import org.neo4j.graphdb.RelationshipType; import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.factory.GraphDatabaseSettings; import org.neo4j.graphdb.index.Index; import org.neo4j.helpers.collection.MapUtil; import org.neo4j.io.fs.FileSystemAbstraction; -import org.neo4j.io.proc.ProcessUtil; import org.neo4j.kernel.DefaultFileSystemAbstraction; import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.impl.index.IndexConfigStore; import org.neo4j.test.DatabaseRule; import org.neo4j.test.EmbeddedDatabaseRule; -import org.neo4j.test.ProcessStreamHandler; -import org.neo4j.test.TestGraphDatabaseFactory; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; - import static org.neo4j.graphdb.RelationshipType.withName; /** @@ -56,21 +51,6 @@ public class RecoveryTest @Rule public DatabaseRule db = new EmbeddedDatabaseRule(); - private void shutdownDB() - { - db.stopAndKeepFiles(); - } - - private void startDB() - { - db.getGraphDatabaseService(); // will ensure started - } - - private void forceRecover() throws IOException - { - db.restartDatabase(); - } - @Test public void testRecovery() throws Exception { @@ -109,25 +89,29 @@ public void testIndexDeleteIssue() throws Exception db.index().forNodes( "index" ); tx.success(); } - - String storeDir = db.getStoreDir(); shutdownDB(); - // NB: AddDeleteQuit will start and shutdown the db - final Process process = Runtime.getRuntime().exec( new String[]{ - ProcessUtil.getJavaExecutable().toString(), - "-cp", - ProcessUtil.getClassPath(), - AddDeleteQuit.class.getName(), - storeDir - } ); - - int result = new ProcessStreamHandler( process, true ).waitForResult(); - - assertEquals( 0, result ); + db.ensureStarted(); + Index index; + Index index2; + try ( Transaction tx = db.beginTx() ) + { + index = db.index().forNodes( "index" ); + index2 = db.index().forNodes( "index2" ); + Node node = db.createNode(); + index.add( node, "key", "value" ); + tx.success(); + } - startDB(); + try ( Transaction tx = db.beginTx() ) + { + index.delete(); + index2.add( db.createNode(), "key", "value" ); + tx.success(); + } + db.shutdown(); + db.ensureStarted(); forceRecover(); } @@ -135,20 +119,26 @@ public void testIndexDeleteIssue() throws Exception public void recoveryForRelationshipCommandsOnly() throws Throwable { // shutdown db here - String storeDir = db.getStoreDir(); - File path = new File( storeDir ); + File storeDir = db.getStoreDirFile(); shutdownDB(); - // NB: AddRelToIndex will start and shutdown the db - Process process = Runtime.getRuntime().exec( new String[]{ - ProcessUtil.getJavaExecutable().toString(), "-cp", ProcessUtil.getClassPath(), - AddRelToIndex.class.getName(), storeDir - } ); - assertEquals( 0, new ProcessStreamHandler( process, false ).waitForResult() ); + try ( Transaction tx = db.beginTx() ) + { + Index index = db.index().forRelationships( "myIndex" ); + Node node = db.createNode(); + Relationship relationship = db.createNode().createRelationshipTo( node, + RelationshipType.withName( "KNOWS" ) ); + + index.add( relationship, "key", "value" ); + tx.success(); + } + + db.shutdown(); FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(); Config config = new Config( MapUtil.stringMap(), GraphDatabaseSettings.class ); - LuceneDataSource ds = new LuceneDataSource( path, config, new IndexConfigStore( path, fileSystem ), fileSystem ); + LuceneDataSource ds = new LuceneDataSource( storeDir, config, new IndexConfigStore( storeDir, fileSystem ), + fileSystem ); ds.start(); ds.stop(); } @@ -163,96 +153,44 @@ public void recoveryOnDeletedIndex() throws Exception } // shutdown db here - String storeDir = db.getStoreDir(); shutdownDB(); - // NB: AddThenDeleteInAnotherTxAndQuit will start and shutdown the db - Process process = Runtime.getRuntime().exec( new String[]{ - ProcessUtil.getJavaExecutable().toString(), - "-cp", - ProcessUtil.getClassPath(), - AddThenDeleteInAnotherTxAndQuit.class.getName(), - storeDir - } ); - assertEquals( 0, new ProcessStreamHandler( process, false ).waitForResult() ); - - // restart db - startDB(); - + Index index; + Index index2; try ( Transaction tx = db.beginTx() ) { - assertFalse( db.index().existsForNodes( "index" ) ); - assertNotNull( db.index().forNodes( "index2" ).get( "key", "value" ).getSingle() ); + index = db.index().forNodes( "index" ); + index2 = db.index().forNodes( "index2" ); + Node node = db.createNode(); + index.add( node, "key", "value" ); + tx.success(); } - // db shutdown handled in tearDown... - } - - public static class AddDeleteQuit - { - public static void main( String[] args ) + try ( Transaction tx = db.beginTx() ) { - GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase( args[0] ); - try ( Transaction tx = db.beginTx() ) - { - Index index = db.index().forNodes( "index" ); - index.add( db.createNode(), "key", "value" ); - index.delete(); - tx.success(); - } - - db.shutdown(); - System.exit( 0 ); + index.delete(); + index2.add( db.createNode(), "key", "value" ); + tx.success(); } - } - public static class AddRelToIndex - { - public static void main( String[] args ) - { - GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase( args[0] ); - try ( Transaction tx = db.beginTx() ) - { - Index index = db.index().forRelationships( "myIndex" ); - Node node = db.createNode(); - Relationship relationship = db.createNode().createRelationshipTo( node, - withName( "KNOWS" ) ); + db.shutdownAndKeepStore(); - index.add( relationship, "key", "value" ); - tx.success(); - } + db.ensureStarted(); - db.shutdown(); - System.exit( 0 ); + try ( Transaction tx = db.beginTx() ) + { + assertFalse( db.index().existsForNodes( "index" ) ); + assertNotNull( db.index().forNodes( "index2" ).get( "key", "value" ).getSingle() ); } } - public static class AddThenDeleteInAnotherTxAndQuit + private void shutdownDB() { - public static void main( String[] args ) - { - GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase( args[0] ); - - Index index; - Index index2; - try ( Transaction tx = db.beginTx() ) - { - index = db.index().forNodes( "index" ); - index2 = db.index().forNodes( "index2" ); - Node node = db.createNode(); - index.add( node, "key", "value" ); - tx.success(); - } - - try ( Transaction tx = db.beginTx() ) - { - index.delete(); - index2.add( db.createNode(), "key", "value" ); - tx.success(); - } + db.shutdownAndKeepStore(); + } - db.shutdown(); - System.exit( 0 ); - } + private void forceRecover() throws IOException + { + db.restartDatabase(); } } diff --git a/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/TestLuceneIndex.java b/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/TestLuceneIndex.java index d4cd958eb3606..6bedf8d0c5e92 100644 --- a/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/TestLuceneIndex.java +++ b/community/lucene-index/src/test/java/org/neo4j/index/impl/lucene/TestLuceneIndex.java @@ -20,15 +20,14 @@ package org.neo4j.index.impl.lucene; import org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper; -import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.index.Term; import org.apache.lucene.queryparser.classic.QueryParser.Operator; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.similarities.DefaultSimilarity; import org.apache.lucene.search.NumericRangeQuery; import org.apache.lucene.search.Sort; import org.apache.lucene.search.TermQuery; +import org.apache.lucene.search.similarities.DefaultSimilarity; import org.hamcrest.CoreMatchers; import org.junit.Ignore; import org.junit.Test; @@ -60,6 +59,7 @@ import org.neo4j.kernel.impl.index.IndexConfigStore; import static org.apache.lucene.search.NumericRangeQuery.newIntRange; +import static org.hamcrest.Matchers.emptyIterable; import static org.hamcrest.Matchers.isOneOf; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsNull.nullValue; @@ -70,7 +70,6 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; - import static org.neo4j.graphdb.RelationshipType.withName; import static org.neo4j.helpers.collection.IteratorUtil.asSet; import static org.neo4j.helpers.collection.IteratorUtil.count; @@ -78,7 +77,6 @@ import static org.neo4j.index.Neo4jTestCase.assertContains; import static org.neo4j.index.Neo4jTestCase.assertContainsInOrder; import static org.neo4j.index.impl.lucene.Contains.contains; -import static org.neo4j.index.impl.lucene.IsEmpty.isEmpty; import static org.neo4j.index.impl.lucene.LuceneIndexImplementation.EXACT_CONFIG; import static org.neo4j.index.lucene.QueryContext.numericRange; import static org.neo4j.index.lucene.ValueContext.numeric; @@ -92,9 +90,9 @@ private void makeSureAdditionsCanBeRead( String key = "name"; String value = "Mattias"; assertThat( index.get( key, value ).getSingle(), is( nullValue() ) ); - assertThat( index.get( key, value ), isEmpty() ); + assertThat( index.get( key, value ), emptyIterable() ); - assertThat( index.query( key, "*" ), isEmpty() ); + assertThat( index.query( key, "*" ), emptyIterable() ); T entity1 = entityCreator.create(); T entity2 = entityCreator.create(); @@ -339,7 +337,7 @@ private void makeSureThereCanBeMoreThanOneValueForAKeyAndEntity( String value1 = "Lucene"; String value2 = "Index"; String value3 = "Rules"; - assertThat( index.query( key, "*" ), isEmpty() ); + assertThat( index.query( key, "*" ), emptyIterable() ); Node node = graphDb.createNode(); index.add( node, key, value1 ); index.add( node, key, value2 ); @@ -353,7 +351,7 @@ private void makeSureThereCanBeMoreThanOneValueForAKeyAndEntity( assertThat( index.get( key, value1 ), contains( node ) ); assertThat( index.get( key, value2 ), contains( node ) ); assertThat( index.get( key, value3 ), contains( node ) ); - assertThat( index.get( key, "whatever" ), isEmpty() ); + assertThat( index.get( key, "whatever" ), emptyIterable() ); restartTx(); } index.delete(); @@ -376,7 +374,7 @@ public void shouldNotGetLatestTxModificationsWhenChoosingSpeedQueries() Node node = graphDb.createNode(); index.add( node, "key", "value" ); QueryContext queryContext = new QueryContext( "value" ).tradeCorrectnessForSpeed(); - assertThat( index.query( "key", queryContext ), isEmpty() ); + assertThat( index.query( "key", queryContext ), emptyIterable() ); assertThat( index.query( "key", "value" ), contains( node ) ); } @@ -388,7 +386,7 @@ public void makeSureArrayValuesAreSupported() String value1 = "Lucene"; String value2 = "Index"; String value3 = "Rules"; - assertThat( index.query( key, "*" ), isEmpty() ); + assertThat( index.query( key, "*" ), emptyIterable() ); Node node = graphDb.createNode(); index.add( node, key, new String[]{value1, value2, value3} ); for ( int i = 0; i < 2; i++ ) @@ -396,7 +394,7 @@ public void makeSureArrayValuesAreSupported() assertThat( index.get( key, value1 ), contains( node ) ); assertThat( index.get( key, value2 ), contains( node ) ); assertThat( index.get( key, value3 ), contains( node ) ); - assertThat( index.get( key, "whatever" ), isEmpty() ); + assertThat( index.get( key, "whatever" ), emptyIterable() ); restartTx(); } @@ -405,8 +403,8 @@ public void makeSureArrayValuesAreSupported() for ( int i = 0; i < 2; i++ ) { assertThat( index.get( key, value1 ), contains( node ) ); - assertThat( index.get( key, value2 ), isEmpty() ); - assertThat( index.get( key, value3 ), isEmpty() ); + assertThat( index.get( key, value2 ), emptyIterable() ); + assertThat( index.get( key, value3 ), emptyIterable() ); restartTx(); } index.delete(); @@ -471,7 +469,7 @@ private void doSomeRandomUseCaseTestingWithExactIn String title = "title"; String hacker = "Hacker"; - assertThat( index.get( name, mattias ), isEmpty() ); + assertThat( index.get( name, mattias ), emptyIterable() ); T entity1 = creator.create(); T entity2 = creator.create(); @@ -762,7 +760,7 @@ public void testNumericValueArrays() assertThat( indexResult3.size(), is( 1 ) ); IndexHits indexResult4 = index.query( "number", newIntRange( "number", 47, 98, false, false ) ); - assertThat( indexResult4, isEmpty() ); + assertThat( indexResult4, emptyIterable() ); IndexHits indexResult5 = index.query( "number", numericRange( "number", null, 98, true, true ) ); assertContains( indexResult5, node1, node2 ); @@ -786,10 +784,10 @@ public void testRemoveNumericValues() index.remove( node2, key, new ValueContext( 5 ).indexNumeric() ); - assertThat( index.query( NumericRangeQuery.newIntRange( key, 0, 20, false, false ) ), isEmpty() ); + assertThat( index.query( NumericRangeQuery.newIntRange( key, 0, 20, false, false ) ), emptyIterable() ); restartTx(); - assertThat( index.query( NumericRangeQuery.newIntRange( key, 0, 20, false, false ) ), isEmpty() ); + assertThat( index.query( NumericRangeQuery.newIntRange( key, 0, 20, false, false ) ), emptyIterable() ); index.add( node1, key, new ValueContext( 15 ).indexNumeric() ); index.add( node2, key, new ValueContext( 5 ).indexNumeric() ); @@ -884,11 +882,11 @@ public void makeSureFulltextIndexCanBeCaseSensitive() for ( int i = 0; i < 2; i++ ) { assertThat( index.query( "name", "[A TO Z]" ), contains( node ) ); - assertThat( index.query( "name", "[a TO z]" ), isEmpty() ); + assertThat( index.query( "name", "[a TO z]" ), emptyIterable() ); assertThat( index.query( "name", "Matt*" ), contains( node ) ); - assertThat( index.query( "name", "matt*" ), isEmpty() ); + assertThat( index.query( "name", "matt*" ), emptyIterable() ); assertThat( index.query( "name", "Persson" ), contains( node ) ); - assertThat( index.query( "name", "persson" ), isEmpty() ); + assertThat( index.query( "name", "persson" ), emptyIterable() ); restartTx(); } } @@ -1021,7 +1019,7 @@ public void makeSureYouCanRemoveFromRelationshipIndex() index.add( r, key, "otherValue" ); for ( int i = 0; i < 2; i++ ) { - assertThat( index.get( key, "value" ), isEmpty() ); + assertThat( index.get( key, "value" ), emptyIterable() ); assertThat( index.get( key, "otherValue" ), contains( r ) ); restartTx(); } diff --git a/community/lucene-index/src/test/java/org/neo4j/index/lucene/ConstraintIndexFailureIT.java b/community/lucene-index/src/test/java/org/neo4j/index/lucene/ConstraintIndexFailureIT.java index ea8b219f0984e..a540350a0a85e 100644 --- a/community/lucene-index/src/test/java/org/neo4j/index/lucene/ConstraintIndexFailureIT.java +++ b/community/lucene-index/src/test/java/org/neo4j/index/lucene/ConstraintIndexFailureIT.java @@ -42,13 +42,13 @@ import static org.hamcrest.core.IsEqual.equalTo; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; - import static org.neo4j.graphdb.Label.label; import static org.neo4j.test.TargetDirectory.testDirForTest; public class ConstraintIndexFailureIT { - public final @Rule TargetDirectory.TestDirectory storeDir = testDirForTest( ConstraintIndexFailureIT.class ); + @Rule + public final TargetDirectory.TestDirectory storeDir = testDirForTest( ConstraintIndexFailureIT.class ); @Test public void shouldFailToValidateConstraintsIfUnderlyingIndexIsFailed() throws Exception diff --git a/community/lucene-index/src/test/java/org/neo4j/index/recovery/UniqueIndexRecoveryTests.java b/community/lucene-index/src/test/java/org/neo4j/index/recovery/UniqueIndexRecoveryTests.java index 98f2eb416acfc..e1323b35c8981 100644 --- a/community/lucene-index/src/test/java/org/neo4j/index/recovery/UniqueIndexRecoveryTests.java +++ b/community/lucene-index/src/test/java/org/neo4j/index/recovery/UniqueIndexRecoveryTests.java @@ -63,6 +63,44 @@ @RunWith(Parameterized.class) public class UniqueIndexRecoveryTests { + @Rule + public final TargetDirectory.TestDirectory storeDir = + TargetDirectory.testDirForTest( UniqueIndexRecoveryTests.class ); + + private static final String PROPERTY_KEY = "key"; + private static final String PROPERTY_VALUE = "value"; + private static final Label LABEL = label( "label" ); + + private final TestGraphDatabaseFactory factory = new TestGraphDatabaseFactory(); + private GraphDatabaseAPI db; + + @Parameterized.Parameters(name = "{0}") + public static Collection parameters() + { + return asList( + new Object[]{new LuceneSchemaIndexProviderFactory()}, + new Object[]{new InMemoryIndexProviderFactory()} ); + } + + @Parameterized.Parameter(0) + public KernelExtensionFactory kernelExtensionFactory; + + @Before + public void before() + { + List> extensionFactories = new ArrayList<>(); + extensionFactories.add( kernelExtensionFactory ); + extensionFactories.add(new LuceneLabelScanStoreExtension()); + factory.setKernelExtensions( extensionFactories ); + db = (GraphDatabaseAPI) factory.newEmbeddedDatabase( storeDir.absolutePath() ); + } + + @After + public void after() + { + db.shutdown(); + } + @Test public void shouldRecoverCreationOfUniquenessConstraintFollowedByDeletionOfThatSameConstraint() throws Exception { @@ -206,44 +244,6 @@ private void dropConstraints() } } - @Parameterized.Parameters(name = "{0}") - public static Collection parameters() - { - return asList( - new Object[]{new LuceneSchemaIndexProviderFactory()}, - new Object[]{new InMemoryIndexProviderFactory()} ); - } - - @Parameterized.Parameter(0) - public KernelExtensionFactory kernelExtensionFactory; - - @Rule - public final TargetDirectory.TestDirectory storeDir = - TargetDirectory.testDirForTest( UniqueIndexRecoveryTests.class ); - - private static final String PROPERTY_KEY = "key"; - private static final String PROPERTY_VALUE = "value"; - private static final Label LABEL = label( "label" ); - - private final TestGraphDatabaseFactory factory = new TestGraphDatabaseFactory(); - private GraphDatabaseAPI db; - - @Before - public void before() - { - List> extensionFactories = new ArrayList<>(); - extensionFactories.add( kernelExtensionFactory ); - extensionFactories.add(new LuceneLabelScanStoreExtension()); - factory.setKernelExtensions( extensionFactories ); - db = (GraphDatabaseAPI) factory.newEmbeddedDatabase( storeDir.absolutePath() ); - } - - @After - public void after() - { - db.shutdown(); - } - private void rotateLogAndCheckPoint() throws IOException { db.getDependencyResolver().resolveDependency( LogRotation.class ).rotateLogFile(); 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 2d0a78b963c47..6408f4cc3f9aa 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 @@ -53,6 +53,21 @@ public class DeferredConstraintVerificationUniqueLuceneIndexPopulatorTest { + + @Rule + public final CleanupRule cleanup = new CleanupRule(); + + private static final int LABEL_ID = 1; + private static final int PROPERTY_KEY_ID = 2; + private static final int INDEX_ID = 42; + + private final FailureStorage failureStorage = mock( FailureStorage.class ); + private final DirectoryFactory.InMemoryDirectoryFactory directoryFactory = new DirectoryFactory.InMemoryDirectoryFactory(); + private final IndexDescriptor descriptor = new IndexDescriptor( LABEL_ID, PROPERTY_KEY_ID ); + + private final File indexDirectory = new File( "target/whatever" ); + private final PropertyAccessor propertyAccessor = mock( PropertyAccessor.class ); + @Test public void shouldVerifyThatThereAreNoDuplicates() throws Exception { @@ -487,17 +502,6 @@ public void shouldCloseSearcherWhenPopulatorIsClosed() throws Exception verify( searcherManager ).afterClose(); } - private static final int LABEL_ID = 1; - private static final int PROPERTY_KEY_ID = 2; - private static final int INDEX_ID = 42; - - private final FailureStorage failureStorage = mock( FailureStorage.class ); - private final DirectoryFactory.InMemoryDirectoryFactory directoryFactory = new DirectoryFactory.InMemoryDirectoryFactory(); - private final IndexDescriptor descriptor = new IndexDescriptor( LABEL_ID, PROPERTY_KEY_ID ); - - private final File indexDirectory = new File( "target/whatever" ); - private final PropertyAccessor propertyAccessor = mock( PropertyAccessor.class ); - public final @Rule CleanupRule cleanup = new CleanupRule(); private DeferredConstraintVerificationUniqueLuceneIndexPopulator newPopulator() throws IOException { diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneIndexAccessorReservationsTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneIndexAccessorReservationsTest.java index 855c39e3d0531..80174f929298f 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneIndexAccessorReservationsTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneIndexAccessorReservationsTest.java @@ -61,6 +61,23 @@ public class LuceneIndexAccessorReservationsTest @Parameter( 1 ) public AccessorFactory accessorFactory; + @Parameters( name = "{0}" ) + public static List accessorFactories() + { + return Arrays.asList( + new Object[]{ + UniqueLuceneIndexAccessor.class.getSimpleName(), + (AccessorFactory) writer -> new UniqueLuceneIndexAccessor( new LuceneDocumentStructure(), + factoryOfOne( writer ), new InMemoryDirectoryFactory(), new File( "unique" ) )}, + new Object[]{ + NonUniqueLuceneIndexAccessor.class.getSimpleName(), + (AccessorFactory) writer -> new NonUniqueLuceneIndexAccessor( new LuceneDocumentStructure(), + factoryOfOne( writer ), new InMemoryDirectoryFactory(), + new File( "non-unique" ), 100_000 )} + ); + } + + @Test public void reservationShouldAllowReleaseOnlyOnce() throws Exception { @@ -186,36 +203,6 @@ private IndexUpdater newIndexUpdater( ReservingLuceneIndexWriter writer ) throws return accessorFactory.create( writer ).newUpdater( IndexUpdateMode.ONLINE ); } - @Parameters( name = "{0}" ) - public static List accessorFactories() - { - return Arrays.asList( - new Object[]{ - UniqueLuceneIndexAccessor.class.getSimpleName(), - new AccessorFactory() - { - @Override - public IndexAccessor create( ReservingLuceneIndexWriter writer ) throws IOException - { - return new UniqueLuceneIndexAccessor( new LuceneDocumentStructure(), - factoryOfOne( writer ), new InMemoryDirectoryFactory(), new File( "unique" ) ); - } - }}, - new Object[]{ - NonUniqueLuceneIndexAccessor.class.getSimpleName(), - new AccessorFactory() - { - @Override - public IndexAccessor create( ReservingLuceneIndexWriter writer ) throws IOException - { - return new NonUniqueLuceneIndexAccessor( new LuceneDocumentStructure(), - factoryOfOne( writer ), new InMemoryDirectoryFactory(), - new File( "non-unique" ), 100_000 ); - } - }} - ); - } - @SuppressWarnings( "unchecked" ) private static IndexWriterFactory factoryOfOne( ReservingLuceneIndexWriter writer ) throws IOException diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneIndexIT.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneIndexIT.java index 80d206541a6f8..c87a51cea2d92 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneIndexIT.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneIndexIT.java @@ -48,6 +48,32 @@ public class LuceneIndexIT { + + private final long nodeId = 1, nodeId2 = 2; + private final Object value = "value"; + private final LuceneDocumentStructure documentLogic = new LuceneDocumentStructure(); + private LuceneIndexAccessor accessor; + private DirectoryFactory dirFactory; + + @Rule + public TargetDirectory.TestDirectory testDir = TargetDirectory.testDirForTest( getClass() ); + + @Before + public void before() throws Exception + { + dirFactory = DirectoryFactory.PERSISTENT; + accessor = new NonUniqueLuceneIndexAccessor( + documentLogic, reserving(), dirFactory, testDir.directory(), 100_000 + ); + } + + @After + public void after() throws IOException + { + accessor.close(); + dirFactory.close(); + } + @Test public void shouldProvideStoreSnapshot() throws Exception { @@ -85,31 +111,6 @@ private Set asUniqueSetOfNames( ResourceIterator files ) return asUniqueSet( out ); } - private final long nodeId = 1, nodeId2 = 2; - private final Object value = "value"; - private final LuceneDocumentStructure documentLogic = new LuceneDocumentStructure(); - private LuceneIndexAccessor accessor; - private DirectoryFactory dirFactory; - - @Rule - public TargetDirectory.TestDirectory testDir = TargetDirectory.testDirForTest( getClass() ); - - @Before - public void before() throws Exception - { - dirFactory = DirectoryFactory.PERSISTENT; - accessor = new NonUniqueLuceneIndexAccessor( - documentLogic, reserving(), dirFactory, testDir.directory(), 100_000 - ); - } - - @After - public void after() throws IOException - { - accessor.close(); - dirFactory.close(); - } - private NodePropertyUpdate add( long nodeId, Object value ) { return NodePropertyUpdate.add( nodeId, 0, value, new long[0] ); diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneIndexRecoveryIT.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneIndexRecoveryIT.java index 78112c08db91d..4a7113240722a 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneIndexRecoveryIT.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneIndexRecoveryIT.java @@ -57,7 +57,49 @@ public class LuceneIndexRecoveryIT { + @Rule + public EphemeralFileSystemRule fs = new EphemeralFileSystemRule(); + + private final String NUM_BANANAS_KEY = "number_of_bananas_owned"; private final static Label myLabel = label( "MyLabel" ); + private GraphDatabaseAPI db; + private DirectoryFactory directoryFactory; + + private final DirectoryFactory ignoreCloseDirectoryFactory = new DirectoryFactory() + { + @Override + public Directory open( File dir ) throws IOException + { + return directoryFactory.open( dir ); + } + + @Override + public void close() + { + } + + @Override + public void dumpToZip( ZipOutputStream zip, byte[] scratchPad ) throws IOException + { + directoryFactory.dumpToZip( zip, scratchPad ); + } + }; + + @Before + public void before() + { + directoryFactory = new DirectoryFactory.InMemoryDirectoryFactory(); + } + + @After + public void after() + { + if ( db != null ) + { + db.shutdown(); + } + directoryFactory.close(); + } @Test public void addShouldBeIdempotentWhenDoingRecovery() throws Exception @@ -190,49 +232,6 @@ public void shouldNotUpdateTwiceDuringRecovery() throws Exception assertEquals( 1, doIndexLookup( myLabel, 14 ).size() ); } - @Before - public void before() - { - directoryFactory = new DirectoryFactory.InMemoryDirectoryFactory(); - } - - @After - public void after() - { - if ( db != null ) - { - db.shutdown(); - } - directoryFactory.close(); - } - - private GraphDatabaseAPI db; - private DirectoryFactory directoryFactory; - private final DirectoryFactory ignoreCloseDirectoryFactory = new DirectoryFactory() - { - @Override - public Directory open( File dir ) throws IOException - { - return directoryFactory.open( dir ); - } - - @Override - public void close() - { - } - - @Override - public void dumpToZip( ZipOutputStream zip, byte[] scratchPad ) throws IOException - { - directoryFactory.dumpToZip( zip, scratchPad ); - } - }; - - @Rule - public EphemeralFileSystemRule fs = new EphemeralFileSystemRule(); - - private final String NUM_BANANAS_KEY = "number_of_bananas_owned"; - private void startDb( KernelExtensionFactory indexProviderFactory ) { if ( db != null ) diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneIndexWriterTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneIndexWriterTest.java index 7c067158bd4cb..75c89380ff36a 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneIndexWriterTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneIndexWriterTest.java @@ -38,6 +38,22 @@ public class LuceneIndexWriterTest { + private Directory directory; + private DirectoryFactory.InMemoryDirectoryFactory dirFactory; + + @Before + public void before() throws Exception + { + dirFactory = new DirectoryFactory.InMemoryDirectoryFactory(); + directory = dirFactory.open( new File( "dir" ) ); + } + + @After + public void after() + { + dirFactory.close(); + } + @Test public void forceShouldSetOnlineStatus() throws Exception { @@ -86,22 +102,6 @@ public void otherWriterSessionShouldKeepOnlineStatusEvenIfNotForcingBeforeClosin assertTrue( "Should have had online status set", LuceneIndexWriter.isOnline( directory ) ); } - private Directory directory; - private DirectoryFactory.InMemoryDirectoryFactory dirFactory; - - @Before - public void before() throws Exception - { - dirFactory = new DirectoryFactory.InMemoryDirectoryFactory(); - directory = dirFactory.open( new File( "dir" ) ); - } - - @After - public void after() - { - dirFactory.close(); - } - private LuceneIndexWriter newWriter() throws IOException { return new LuceneIndexWriter( directory, new IndexWriterConfig( KEYWORD_ANALYZER ) ); diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneLabelScanStoreTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneLabelScanStoreTest.java index 6ff6d3a407747..ee318db700282 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneLabelScanStoreTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneLabelScanStoreTest.java @@ -82,6 +82,46 @@ public class LuceneLabelScanStoreTest { private static final long[] NO_LABELS = new long[0]; + private final LabelScanStorageStrategy strategy; + + @Parameterized.Parameters(name = "{0}") + public static List parameterizedWithStrategies() + { + return asList( + new Object[]{ + new NodeRangeDocumentLabelScanStorageStrategy( + BitmapDocumentFormat._32 )}, + new Object[]{ + new NodeRangeDocumentLabelScanStorageStrategy( + BitmapDocumentFormat._64 )} + ); + } + + @Rule + public final TargetDirectory.TestDirectory testDirectory = TargetDirectory.testDirForTest( getClass() ); + + private final Random random = new Random(); + private DirectoryFactory directoryFactory = new DirectoryFactory.InMemoryDirectoryFactory(); + private LifeSupport life; + private TrackingMonitor monitor; + private LuceneLabelScanStore store; + private File dir; + + @Before + public void clearDir() throws IOException + { + dir = testDirectory.directory( "lucene" ); + if ( dir.exists() ) + { + deleteRecursively( dir ); + } + } + + @After + public void shutdown() throws IOException + { + life.shutdown(); + } @Test public void shouldUpdateIndexOnLabelChange() throws Exception @@ -252,6 +292,7 @@ public void shouldUpdateAFullRange() throws Exception assertThat( labels, hasItem( label0Id ) ); } } + private void write( Iterator iterator ) throws IOException, IndexCapacityExceededException { try ( LabelScanWriter writer = store.newWriter() ) @@ -380,25 +421,12 @@ private Set gaps( Set ids, int expectedCount ) return gaps; } - private final LabelScanStorageStrategy strategy; - public LuceneLabelScanStoreTest( LabelScanStorageStrategy strategy ) { this.strategy = strategy; } - @Parameterized.Parameters(name = "{0}") - public static List parameterizedWithStrategies() - { - return asList( - new Object[]{ - new NodeRangeDocumentLabelScanStorageStrategy( - BitmapDocumentFormat._32 )}, - new Object[]{ - new NodeRangeDocumentLabelScanStorageStrategy( - BitmapDocumentFormat._64 )} - ); - } + private void assertNodesForLabel( int labelId, long... expectedNodeIds ) { @@ -417,16 +445,6 @@ private void assertNodesForLabel( int labelId, long... expectedNodeIds ) assertTrue( "Unexpected nodes in scan store " + nodeSet, nodeSet.isEmpty() ); } - @Rule - public final TargetDirectory.TestDirectory testDirectory = TargetDirectory.testDirForTest( getClass() ); - - private final Random random = new Random(); - private DirectoryFactory directoryFactory = new DirectoryFactory.InMemoryDirectoryFactory(); - private LifeSupport life; - private TrackingMonitor monitor; - private LuceneLabelScanStore store; - private File dir; - private List noData() { return emptyList(); @@ -508,22 +526,6 @@ private void putRandomBytes( byte[] bytes ) } } - @Before - public void clearDir() throws IOException - { - dir = testDirectory.directory( "lucene" ); - if ( dir.exists() ) - { - deleteRecursively( dir ); - } - } - - @After - public void shutdown() throws IOException - { - life.shutdown(); - } - private static class TrackingMonitor implements LuceneLabelScanStore.Monitor { boolean initCalled, rebuildingCalled, rebuiltCalled, noIndexCalled; diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/SchemaIndexAcceptanceTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/SchemaIndexAcceptanceTest.java index 382707c4268d0..3a449cd574c5e 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/SchemaIndexAcceptanceTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/SchemaIndexAcceptanceTest.java @@ -51,6 +51,23 @@ public class SchemaIndexAcceptanceTest { + private EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction(); + private GraphDatabaseService db; + private final Label label = label( "PERSON" ); + private final String propertyKey = "key"; + + @Before + public void before() throws Exception + { + db = newDb(); + } + + @After + public void after() throws Exception + { + db.shutdown(); + } + @Test public void creatingIndexOnExistingDataBuildsIndexWhichWillBeOnlineNextStartup() throws Exception { @@ -153,17 +170,6 @@ public void recoveryAfterCreateAndDropIndex() throws Exception assertThat( getIndexes( db, label ), isEmpty() ); } - private EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction(); - private GraphDatabaseService db; - private final Label label = label( "PERSON" ); - private final String propertyKey = "key"; - - @Before - public void before() throws Exception - { - db = newDb(); - } - private GraphDatabaseService newDb() { return new TestGraphDatabaseFactory().setFileSystem( fs ).newImpermanentDatabase(); @@ -184,12 +190,6 @@ private void restart() db = newDb(); } - @After - public void after() throws Exception - { - db.shutdown(); - } - private Node createNode( Label label, Object... properties ) { Node node = db.createNode( label ); diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/UniqueIndexApplicationIT.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/UniqueIndexApplicationIT.java index 756a4780ebe40..5cb26b90ae471 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/UniqueIndexApplicationIT.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/UniqueIndexApplicationIT.java @@ -56,16 +56,26 @@ @RunWith(Parameterized.class) public class UniqueIndexApplicationIT { - public final @Rule DatabaseRule db = new ImpermanentDatabaseRule(); + @Rule + public final DatabaseRule db = new ImpermanentDatabaseRule(); + + private final Function createIndex; @Parameterized.Parameters(name = "{0}") public static List indexTypes() { return asList( createIndex( index( label( "Label1" ), "key1" ) ), - createIndex( uniquenessConstraint( label( "Label1" ), "key1" ) ) ); + createIndex( uniquenessConstraint( label( "Label1" ), "key1" ) ) ); + } + + @After + public void then() throws Exception + { + assertThat( "Matching nodes from index lookup", + db.when( db.tx( listNodeIdsFromIndexLookup( label( "Label1" ), "key1", "value1" ) ) ), + hasSize( 1 ) ); } - private final Function createIndex; @Before public void given() throws Exception @@ -136,14 +146,6 @@ public void tx_createNode_tx_setProperty_tx_addLabel() throws Exception ) ) ) ); } - @After - public void then() throws Exception - { - assertThat( "Matching nodes from index lookup", - db.when( db.tx( listNodeIdsFromIndexLookup( label( "Label1" ), "key1", "value1" ) ) ), - hasSize( 1 ) ); - } - private static Matcher> hasSize( final int size ) { return new TypeSafeMatcher>() diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/UniqueLuceneIndexPopulatorTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/UniqueLuceneIndexPopulatorTest.java index c41c1b6613116..5ebec7dfe9205 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/UniqueLuceneIndexPopulatorTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/UniqueLuceneIndexPopulatorTest.java @@ -41,6 +41,9 @@ public class UniqueLuceneIndexPopulatorTest { + private final FailureStorage failureStorage = mock( FailureStorage.class ); + private final long indexId = 1; + @Test public void shouldAddUniqueUniqueLuceneIndexPopulatorTestEntries() throws Exception { @@ -193,7 +196,4 @@ public void shouldRejectUpdateWithAlreadyIndexedValue() throws Exception assertEquals( 2, conflict.getAddedNodeId() ); } } - - private final FailureStorage failureStorage = mock( FailureStorage.class ); - private final long indexId = 1; } diff --git a/community/lucene-index/src/test/java/org/neo4j/unsafe/batchinsert/TestLuceneBatchInsert.java b/community/lucene-index/src/test/java/org/neo4j/unsafe/batchinsert/TestLuceneBatchInsert.java index c2fce9f48defe..1d46664f65978 100644 --- a/community/lucene-index/src/test/java/org/neo4j/unsafe/batchinsert/TestLuceneBatchInsert.java +++ b/community/lucene-index/src/test/java/org/neo4j/unsafe/batchinsert/TestLuceneBatchInsert.java @@ -19,6 +19,7 @@ */ package org.neo4j.unsafe.batchinsert; +import org.hamcrest.Matchers; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -68,12 +69,39 @@ import static org.neo4j.helpers.collection.MapUtil.stringMap; import static org.neo4j.index.Neo4jTestCase.assertContains; import static org.neo4j.index.impl.lucene.Contains.contains; -import static org.neo4j.index.impl.lucene.IsEmpty.isEmpty; import static org.neo4j.index.impl.lucene.LuceneIndexImplementation.EXACT_CONFIG; import static org.neo4j.index.lucene.ValueContext.numeric; public class TestLuceneBatchInsert { + @Rule + public final TargetDirectory.TestDirectory testDirectory = TargetDirectory.testDirForTest( getClass() ); + + private File storeDir; + private BatchInserter inserter; + private GraphDatabaseService db; + + @SuppressWarnings( { "rawtypes", "unchecked" } ) + @Before + public void startInserter() throws Exception + { + storeDir = testDirectory.graphDbDir(); + Iterable filteredKernelExtensions = filter( onlyRealLuceneExtensions(), + Service.load( KernelExtensionFactory.class ) ); + inserter = BatchInserters.inserter( storeDir, stringMap(), filteredKernelExtensions ); + } + + @After + public void shutdown() + { + shutdownInserter(); + if ( db != null ) + { + db.shutdown(); + db = null; + } + } + @Test public void testSome() throws Exception { @@ -250,7 +278,7 @@ public void testNumericValueArrays() assertThat( batchIndexResult3.size(), is( 1 ) ); IndexHits batchIndexResult4 = batchIndex.query( "number", newIntRange( "number", 47, 98, false, false ) ); - assertThat( batchIndexResult4, isEmpty() ); + assertThat( batchIndexResult4, Matchers.emptyIterable() ); provider.shutdown(); @@ -274,7 +302,7 @@ public void testNumericValueArrays() assertThat( indexResult3.size(), is( 1 ) ); IndexHits indexResult4 = index.query( "number", newIntRange( "number", 47, 98, false, false ) ); - assertThat( indexResult4, isEmpty() ); + assertThat( indexResult4, Matchers.emptyIterable() ); transaction.success(); } } @@ -511,22 +539,7 @@ private Map>> getIndexCache( BatchInse } } - @Rule - public final TargetDirectory.TestDirectory testDirectory = TargetDirectory.testDirForTest( getClass() ); - private File storeDir; - private BatchInserter inserter; - private GraphDatabaseService db; - - @SuppressWarnings( { "rawtypes", "unchecked" } ) - @Before - public void startInserter() throws Exception - { - storeDir = testDirectory.graphDbDir(); - Iterable filteredKernelExtensions = filter( onlyRealLuceneExtensions(), - Service.load( KernelExtensionFactory.class ) ); - inserter = BatchInserters.inserter( storeDir, stringMap(), filteredKernelExtensions ); - } @SuppressWarnings( "rawtypes" ) private Predicate onlyRealLuceneExtensions() @@ -582,15 +595,4 @@ private void shutdownInserter() inserter = null; } } - - @After - public void shutdown() - { - shutdownInserter(); - if ( db != null ) - { - db.shutdown(); - db = null; - } - } } diff --git a/community/lucene-index/src/test/java/org/neo4j/unsafe/batchinsert/TestLuceneSchemaBatchInsertIT.java b/community/lucene-index/src/test/java/org/neo4j/unsafe/batchinsert/TestLuceneSchemaBatchInsertIT.java index 944a84f91b02b..51ce4285fb4ad 100644 --- a/community/lucene-index/src/test/java/org/neo4j/unsafe/batchinsert/TestLuceneSchemaBatchInsertIT.java +++ b/community/lucene-index/src/test/java/org/neo4j/unsafe/batchinsert/TestLuceneSchemaBatchInsertIT.java @@ -45,6 +45,11 @@ public class TestLuceneSchemaBatchInsertIT { + @Rule + public final TargetDirectory.TestDirectory testDirectory = TargetDirectory.testDirForTest( getClass() ); + + private static final Label LABEL = label( "Person" ); + @Test public void shouldLoadAndUseLuceneProvider() throws Exception { @@ -76,9 +81,4 @@ public void shouldLoadAndUseLuceneProvider() throws Exception // CLEANUP db.shutdown(); } - - @Rule - public final TargetDirectory.TestDirectory testDirectory = TargetDirectory.testDirForTest( getClass() ); - - private static final Label LABEL = label( "Person" ); } diff --git a/enterprise/backup/src/test/java/org/neo4j/backup/BackupServiceIT.java b/enterprise/backup/src/test/java/org/neo4j/backup/BackupServiceIT.java index 0ca5572597e57..fe6479244c573 100644 --- a/enterprise/backup/src/test/java/org/neo4j/backup/BackupServiceIT.java +++ b/enterprise/backup/src/test/java/org/neo4j/backup/BackupServiceIT.java @@ -325,14 +325,7 @@ public void shouldBeAbleToBackupEvenIfTransactionLogsAreIncomplete() throws Thro long lastCommittedTxBefore = db.getDependencyResolver().resolveDependency( NeoStores.class ).getMetaDataStore() .getLastCommittedTransactionId(); - db = dbRule.restartDatabase( new DatabaseRule.RestartAction() - { - @Override - public void run( FileSystemAbstraction fs, File storeDirectory ) throws IOException - { - FileUtils.deleteFile( oldLog ); - } - } ); + db = dbRule.restartDatabase( ( fs, storeDirectory ) -> FileUtils.deleteFile( oldLog ) ); long lastCommittedTxAfter = db.getDependencyResolver().resolveDependency( NeoStores.class ).getMetaDataStore() .getLastCommittedTransactionId(); @@ -558,23 +551,11 @@ public void shouldHandleBackupWhenLogFilesHaveBeenDeleted() throws Exception private GraphDatabaseAPI deleteLogFilesAndRestart() throws IOException { - final FileFilter logFileFilter = new FileFilter() - { - @Override - public boolean accept( File pathname ) - { - return pathname.getName().contains( "logical" ); - } - }; - return dbRule.restartDatabase( new DatabaseRule.RestartAction() - { - @Override - public void run( FileSystemAbstraction fs, File storeDirectory ) throws IOException + final FileFilter logFileFilter = pathname -> pathname.getName().contains( "logical" ); + return dbRule.restartDatabase( ( fs, storeDirectory ) -> { + for ( File logFile : storeDir.listFiles( logFileFilter ) ) { - for ( File logFile : storeDir.listFiles( logFileFilter ) ) - { - logFile.delete(); - } + logFile.delete(); } } ); } @@ -677,16 +658,11 @@ public void incrementalBackupShouldFailWhenTargetDirContainsDifferentStore() thr defaultConfig, BackupClient.BIG_READ_TIMEOUT, false ); // When - GraphDatabaseAPI db2 = dbRule.restartDatabase( new DatabaseRule.RestartAction() - { - @Override - public void run( FileSystemAbstraction fs, File storeDirectory ) throws IOException - { - deleteAllBackedUpTransactionLogs(); + GraphDatabaseAPI db2 = dbRule.restartDatabase( ( fs, storeDirectory ) -> { + deleteAllBackedUpTransactionLogs(); - fileSystem.deleteRecursively( storeDir ); - fileSystem.mkdir( storeDir ); - } + fileSystem.deleteRecursively( storeDir ); + fileSystem.mkdir( storeDir ); } ); createAndIndexNode( db2, 2 );