diff --git a/community/community-it/index-it/src/test/java/org/neo4j/index/impl/lucene/explicit/TestAutoIndexing.java b/community/community-it/index-it/src/test/java/org/neo4j/index/impl/lucene/explicit/TestAutoIndexing.java index e8bd0380f326b..100e171abe530 100644 --- a/community/community-it/index-it/src/test/java/org/neo4j/index/impl/lucene/explicit/TestAutoIndexing.java +++ b/community/community-it/index-it/src/test/java/org/neo4j/index/impl/lucene/explicit/TestAutoIndexing.java @@ -99,13 +99,13 @@ public void stopDb() @Test public void testNodeAutoIndexFromAPISanity() { + newTransaction(); AutoIndexer autoIndexer = graphDb.index().getNodeAutoIndexer(); autoIndexer.startAutoIndexingProperty( "test_uuid" ); autoIndexer.setEnabled( true ); assertEquals( 1, autoIndexer.getAutoIndexedProperties().size() ); assertTrue( autoIndexer.getAutoIndexedProperties().contains( "test_uuid" ) ); - newTransaction(); Node node1 = graphDb.createNode(); node1.setProperty( "test_uuid", "node1" ); @@ -125,6 +125,7 @@ public void testNodeAutoIndexFromAPISanity() @Test public void testAutoIndexesReportReadOnly() { + newTransaction(); AutoIndexer autoIndexer = graphDb.index().getNodeAutoIndexer(); try ( Transaction tx = graphDb.beginTx() ) { @@ -143,12 +144,12 @@ public void testAutoIndexesReportReadOnly() @Test public void testChangesAreVisibleInTransaction() { + newTransaction(); + AutoIndexer autoIndexer = graphDb.index().getNodeAutoIndexer(); autoIndexer.startAutoIndexingProperty( "nodeProp" ); autoIndexer.setEnabled( true ); - newTransaction(); - Node node1 = graphDb.createNode(); node1.setProperty( "nodeProp", "nodePropValue" ); node1.setProperty( "nodePropNonIndexable", "valueWhatever" ); @@ -180,11 +181,11 @@ public void testChangesAreVisibleInTransaction() @Test public void testRelationshipAutoIndexFromAPISanity() { + newTransaction(); final String propNameToIndex = "test"; AutoIndexer autoIndexer = graphDb.index().getRelationshipAutoIndexer(); autoIndexer.startAutoIndexingProperty( propNameToIndex ); autoIndexer.setEnabled( true ); - newTransaction(); Node node1 = graphDb.createNode(); Node node2 = graphDb.createNode(); @@ -221,6 +222,7 @@ public void testConfigAndAPICompatibility() config.put( GraphDatabaseSettings.relationship_auto_indexing.name(), "true" ); startDb(); + newTransaction(); assertTrue( graphDb.index().getNodeAutoIndexer().isEnabled() ); assertTrue( graphDb.index().getRelationshipAutoIndexer().isEnabled() ); @@ -248,11 +250,10 @@ public void testSmallGraphWithNonIndexableProps() config.put( GraphDatabaseSettings.relationship_auto_indexing.name(), "true" ); startDb(); + newTransaction(); assertTrue( graphDb.index().getNodeAutoIndexer().isEnabled() ); assertTrue( graphDb.index().getRelationshipAutoIndexer().isEnabled() ); - newTransaction(); - // Build the graph, a 3-cycle Node node1 = graphDb.createNode(); Node node2 = graphDb.createNode(); @@ -356,8 +357,8 @@ public void testDefaultIsOff() @Test public void testDefaultIfOffIsForEverything() { - graphDb.index().getNodeAutoIndexer().setEnabled( true ); newTransaction(); + graphDb.index().getNodeAutoIndexer().setEnabled( true ); Node node1 = graphDb.createNode(); node1.setProperty( "testProp", "node1" ); node1.setProperty( "testProp1", "node1" ); @@ -384,9 +385,9 @@ public void testDefaultIsOffIfExplicit() config.put( GraphDatabaseSettings.relationship_auto_indexing.name(), "false" ); startDb(); + newTransaction(); AutoIndexer autoIndexer = graphDb.index().getNodeAutoIndexer(); autoIndexer.startAutoIndexingProperty( "testProp" ); - newTransaction(); Node node1 = graphDb.createNode(); node1.setProperty( "nodeProp1", "node1" ); @@ -441,12 +442,12 @@ public void testStartStopAutoIndexing() // Now only node properties named propName should be indexed. startDb(); + newTransaction(); AutoIndexer autoIndexer = graphDb.index().getNodeAutoIndexer(); assertTrue( autoIndexer.isEnabled() ); autoIndexer.setEnabled( false ); assertFalse( autoIndexer.isEnabled() ); - newTransaction(); Node node1 = graphDb.createNode(); Node node2 = graphDb.createNode(); @@ -466,10 +467,10 @@ public void testStartStopAutoIndexing() @Test public void testStopMonitoringProperty() { + newTransaction(); AutoIndexer autoIndexer = graphDb.index().getNodeAutoIndexer(); autoIndexer.setEnabled( true ); autoIndexer.startAutoIndexingProperty( "propName" ); - newTransaction(); Node node1 = graphDb.createNode(); Node node2 = graphDb.createNode(); node1.setProperty( "propName", "node" ); @@ -503,6 +504,7 @@ public void testStopMonitoringProperty() public void testGettingAutoIndexByNameReturnsSomethingReadOnly() { // Create the node and relationship auto-indexes + newTransaction(); graphDb.index().getNodeAutoIndexer().setEnabled( true ); graphDb.index().getNodeAutoIndexer().startAutoIndexingProperty( "nodeProp" ); @@ -510,8 +512,6 @@ public void testGettingAutoIndexByNameReturnsSomethingReadOnly() graphDb.index().getRelationshipAutoIndexer().startAutoIndexingProperty( "relProp" ); - newTransaction(); - Node node1 = graphDb.createNode(); Node node2 = graphDb.createNode(); Relationship rel = node1.createRelationshipTo( node2, @@ -561,11 +561,9 @@ public void testRemoveUnloadedHeavyProperty() * Checks a bug where removing non-cached heavy properties * would cause NPE in auto indexer. */ - graphDb.index().getNodeAutoIndexer().setEnabled( true ); - graphDb.index().getNodeAutoIndexer().startAutoIndexingProperty( - "nodeProp" ); - newTransaction(); + graphDb.index().getNodeAutoIndexer().setEnabled( true ); + graphDb.index().getNodeAutoIndexer().startAutoIndexingProperty( "nodeProp" ); Node node1 = graphDb.createNode(); // Large array, needed for making sure this is a heavy property @@ -586,12 +584,11 @@ public void testRemoveUnloadedHeavyProperty() @Test public void testRemoveRelationshipRemovesDocument() { + newTransaction(); AutoIndexer autoIndexer = graphDb.index().getRelationshipAutoIndexer(); autoIndexer.startAutoIndexingProperty( "foo" ); autoIndexer.setEnabled( true ); - newTransaction(); - Node node1 = graphDb.createNode(); Node node2 = graphDb.createNode(); Relationship rel = node1.createRelationshipTo( node2, RelationshipType.withName( "foo" ) ); @@ -621,12 +618,11 @@ public void testRemoveRelationshipRemovesDocument() @Test public void testDeletingNodeRemovesItFromAutoIndex() { + newTransaction(); AutoIndexer nodeAutoIndexer = graphDb.index().getNodeAutoIndexer(); nodeAutoIndexer.startAutoIndexingProperty( "foo" ); nodeAutoIndexer.setEnabled( true ); - newTransaction(); - Node node1 = graphDb.createNode(); node1.setProperty( "foo", "bar" ); @@ -655,11 +651,11 @@ public void shouldOnlyDeleteAffectedKeyWhenRemovingPropertyFromNode() String key2 = "bar"; String value1 = "bip"; String value2 = "bop"; + newTransaction(); AutoIndexer nodeAutoIndexer = graphDb.index().getNodeAutoIndexer(); nodeAutoIndexer.startAutoIndexingProperty( key1 ); nodeAutoIndexer.startAutoIndexingProperty( key2 ); nodeAutoIndexer.setEnabled( true ); - newTransaction(); Node node = graphDb.createNode(); node.setProperty( key1, value1 ); node.setProperty( key2, value2 ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/core/PathProxyTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/core/PathProxyTest.java index 0c5e3751248a4..462024f855bf7 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/core/PathProxyTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/core/PathProxyTest.java @@ -21,6 +21,7 @@ import java.util.Iterator; +import org.junit.Before; import org.junit.Test; import org.neo4j.graphdb.Entity; @@ -34,14 +35,23 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; public class PathProxyTest { + private EmbeddedProxySPI proxySPI; + + @Before + public void setUp() throws Exception + { + proxySPI = mock( EmbeddedProxySPI.class ); + } + @Test public void shouldIterateThroughNodes() { // given - Path path = new PathProxy( null, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} ); + Path path = new PathProxy( proxySPI, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} ); Iterator iterator = path.nodes().iterator(); Node node; @@ -63,7 +73,7 @@ public void shouldIterateThroughNodes() public void shouldIterateThroughNodesInReverse() { // given - Path path = new PathProxy( null, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} ); + Path path = new PathProxy( proxySPI, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} ); Iterator iterator = path.reverseNodes().iterator(); Node node; @@ -85,7 +95,7 @@ public void shouldIterateThroughNodesInReverse() public void shouldIterateThroughRelationships() { // given - Path path = new PathProxy( null, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} ); + Path path = new PathProxy( proxySPI, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} ); Iterator iterator = path.relationships().iterator(); Relationship relationship; @@ -108,7 +118,7 @@ public void shouldIterateThroughRelationships() public void shouldIterateThroughRelationshipsInReverse() { // given - Path path = new PathProxy( null, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} ); + Path path = new PathProxy( proxySPI, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} ); Iterator iterator = path.reverseRelationships().iterator(); Relationship relationship; @@ -131,7 +141,7 @@ public void shouldIterateThroughRelationshipsInReverse() public void shouldIterateAlternatingNodesAndRelationships() { // given - Path path = new PathProxy( null, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} ); + Path path = new PathProxy( proxySPI, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} ); Iterator iterator = path.iterator(); PropertyContainer entity; diff --git a/community/server/src/test/java/org/neo4j/server/rest/AutoIndexIT.java b/community/server/src/test/java/org/neo4j/server/rest/AutoIndexIT.java index 24559dc2ca150..c37b84a508ee1 100644 --- a/community/server/src/test/java/org/neo4j/server/rest/AutoIndexIT.java +++ b/community/server/src/test/java/org/neo4j/server/rest/AutoIndexIT.java @@ -27,6 +27,7 @@ import org.neo4j.graphdb.ResourceIterable; import org.neo4j.graphdb.ResourceIterator; import org.neo4j.graphdb.Transaction; +import org.neo4j.kernel.impl.factory.GraphDatabaseFacade; import org.neo4j.server.rest.domain.JsonHelper; import org.neo4j.server.rest.domain.JsonParseException; import org.neo4j.server.rest.web.RestfulGraphDatabase; @@ -305,7 +306,12 @@ public void listAutoIndexingPropertiesForNodes() throws JsonParseException int initialPropertiesSize = getAutoIndexedPropertiesForType( "node" ).size(); String propName = "some-property" + System.currentTimeMillis(); - server().getDatabase().getGraph().index().getNodeAutoIndexer().startAutoIndexingProperty( propName ); + GraphDatabaseFacade db = server().getDatabase().getGraph(); + try ( Transaction tx = db.beginTx() ) + { + db.index().getNodeAutoIndexer().startAutoIndexingProperty( propName ); + tx.success(); + } List properties = getAutoIndexedPropertiesForType( "node" );