From 83f1e771f77c149a9baa316308bc63b4f04d0248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Finn=C3=A9?= Date: Wed, 19 Sep 2018 13:05:47 +0200 Subject: [PATCH] ConstraintIndexCreationIT asserts lucene-specific things on lucene index By using an index provider which includes Lucene as a sub-provider --- .../api/constraints/ConstraintCreationIT.java | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/community/community-it/index-it/src/test/java/org/neo4j/kernel/impl/api/constraints/ConstraintCreationIT.java b/community/community-it/index-it/src/test/java/org/neo4j/kernel/impl/api/constraints/ConstraintCreationIT.java index 8be248f4575be..9ae6d6be564eb 100644 --- a/community/community-it/index-it/src/test/java/org/neo4j/kernel/impl/api/constraints/ConstraintCreationIT.java +++ b/community/community-it/index-it/src/test/java/org/neo4j/kernel/impl/api/constraints/ConstraintCreationIT.java @@ -32,17 +32,18 @@ import org.neo4j.kernel.api.impl.index.storage.layout.IndexFolderLayout; import org.neo4j.kernel.api.index.IndexProvider; import org.neo4j.kernel.impl.api.index.IndexProviderMap; -import org.neo4j.kernel.internal.GraphDatabaseAPI; import org.neo4j.test.rule.EmbeddedDatabaseRule; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.fail; +import static org.neo4j.graphdb.factory.GraphDatabaseSettings.SchemaIndex.NATIVE20; +import static org.neo4j.graphdb.factory.GraphDatabaseSettings.default_schema_provider; public class ConstraintCreationIT { @Rule - public EmbeddedDatabaseRule dbRule = new EmbeddedDatabaseRule(); + public EmbeddedDatabaseRule db = new EmbeddedDatabaseRule().startLazily(); private static final Label LABEL = Label.label( "label1" ); private static final long indexId = 1; @@ -51,8 +52,33 @@ public class ConstraintCreationIT public void shouldNotLeaveLuceneIndexFilesHangingAroundIfConstraintCreationFails() { // given - GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); + db.withSetting( default_schema_provider, NATIVE20.providerIdentifier() ); // <-- includes Lucene sub-provider + attemptAndFailConstraintCreation(); + // then + IndexProvider indexProvider = + db.getDependencyResolver().resolveDependency( IndexProviderMap.class ).getDefaultProvider(); + File indexDir = indexProvider.directoryStructure().directoryForIndex( indexId ); + + assertFalse( new IndexFolderLayout( indexDir ).getIndexFolder().exists() ); + } + + @Test + public void shouldNotLeaveNativeIndexFilesHangingAroundIfConstraintCreationFails() + { + // given + attemptAndFailConstraintCreation(); + + // then + IndexProvider indexProvider = + db.getDependencyResolver().resolveDependency( IndexProviderMap.class ).getDefaultProvider(); + File indexDir = indexProvider.directoryStructure().directoryForIndex( indexId ); + + assertEquals( 0, indexDir.listFiles().length ); + } + + private void attemptAndFailConstraintCreation() + { try ( Transaction tx = db.beginTx() ) { for ( int i = 0; i < 2; i++ ) @@ -80,11 +106,5 @@ public void shouldNotLeaveLuceneIndexFilesHangingAroundIfConstraintCreationFails { assertEquals( 0, Iterables.count( db.schema().getIndexes() ) ); } - - IndexProvider indexProvider = - db.getDependencyResolver().resolveDependency( IndexProviderMap.class ).getDefaultProvider(); - File indexDir = indexProvider.directoryStructure().directoryForIndex( indexId ); - - assertFalse( new IndexFolderLayout( indexDir ).getIndexFolder().exists() ); } }