diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexIT.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexIT.java index 5a643f7356402..194712f1da9ae 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexIT.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexIT.java @@ -44,7 +44,6 @@ import org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException; import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor; import org.neo4j.kernel.api.KernelTransaction; -import org.neo4j.kernel.api.ReadOperations; import org.neo4j.kernel.api.Statement; import org.neo4j.kernel.api.index.PropertyAccessor; import org.neo4j.kernel.api.schema.SchemaDescriptorFactory; @@ -172,8 +171,8 @@ public void rollBackIndexRuleShouldNotBeCommitted() throws Exception rollback(); // THEN - ReadOperations readOperations = readOperationsInNewTransaction(); - assertEquals( emptySet(), asSet( readOperations.indexesGetForLabel( labelId ) ) ); + KernelTransaction transaction = newTransaction(); + assertEquals( emptySet(), asSet( transaction.schemaRead().indexesGetForLabel( labelId ) ) ); commit(); } @@ -186,8 +185,8 @@ public void shouldBeAbleToRemoveAConstraintIndexWithoutOwner() throws Exception SchemaIndexDescriptor constraintIndex = creator.createConstraintIndex( descriptor ); // then - ReadOperations readOperations = readOperationsInNewTransaction(); - assertEquals( emptySet(), asSet( readOperations.constraintsGetForLabel( labelId ) ) ); + KernelTransaction transaction = newTransaction(); + assertEquals( emptySet(), asSet( transaction.schemaRead().constraintsGetForLabel( labelId ) ) ); commit(); // when @@ -196,8 +195,8 @@ public void shouldBeAbleToRemoveAConstraintIndexWithoutOwner() throws Exception commit(); // then - readOperations = readOperationsInNewTransaction(); - assertEquals( emptySet(), asSet( readOperations.indexesGetForLabel( labelId ) ) ); + transaction = newTransaction(); + assertEquals( emptySet(), asSet( transaction.schemaRead().indexesGetForLabel( labelId ) ) ); commit(); } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/KernelIntegrationTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/KernelIntegrationTest.java index 5d1709cb63712..d422f53385d1e 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/KernelIntegrationTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/KernelIntegrationTest.java @@ -24,9 +24,18 @@ import org.junit.Rule; import org.junit.rules.RuleChain; +import java.util.Iterator; + +import org.neo4j.collection.primitive.Primitive; +import org.neo4j.collection.primitive.PrimitiveIntIterator; +import org.neo4j.collection.primitive.PrimitiveIntSet; +import org.neo4j.graphdb.Direction; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.factory.GraphDatabaseBuilder; +import org.neo4j.internal.kernel.api.NodeCursor; import org.neo4j.internal.kernel.api.Procedures; +import org.neo4j.internal.kernel.api.PropertyCursor; +import org.neo4j.internal.kernel.api.RelationshipScanCursor; import org.neo4j.internal.kernel.api.SchemaWrite; import org.neo4j.internal.kernel.api.TokenWrite; import org.neo4j.internal.kernel.api.Write; @@ -45,8 +54,14 @@ import org.neo4j.test.TestGraphDatabaseFactory; import org.neo4j.test.rule.TestDirectory; import org.neo4j.test.rule.fs.DefaultFileSystemRule; +import org.neo4j.values.storable.Value; +import static java.util.Collections.emptyIterator; +import static org.neo4j.internal.kernel.api.helpers.RelationshipSelections.allIterator; +import static org.neo4j.internal.kernel.api.helpers.RelationshipSelections.incomingIterator; +import static org.neo4j.internal.kernel.api.helpers.RelationshipSelections.outgoingIterator; import static org.neo4j.internal.kernel.api.security.LoginContext.AUTH_DISABLED; +import static org.neo4j.values.storable.Values.NO_VALUE; public abstract class KernelIntegrationTest { @@ -209,4 +224,137 @@ protected void restartDb() throws TransactionFailureException stopDb(); startDb(); } + + boolean nodeHasLabel( KernelTransaction transaction, long node, int label ) + { + try( NodeCursor cursor = transaction.cursors().allocateNodeCursor() ) + { + transaction.dataRead().singleNode( node, cursor ); + return cursor.next() && cursor.labels().contains( label ); + } + } + + boolean nodeHasProperty( KernelTransaction transaction, long node, int property ) + { + try ( NodeCursor cursor = transaction.cursors().allocateNodeCursor(); + PropertyCursor properties = transaction.cursors().allocatePropertyCursor() ) + { + transaction.dataRead().singleNode( node, cursor ); + if ( !cursor.next() ) + { + return false; + } + else + { + cursor.properties( properties ); + while ( properties.next() ) + { + if ( properties.propertyKey() == property ) + { + return true; + } + } + return false; + } + } + } + + Value nodeGetProperty( KernelTransaction transaction, long node, int property ) + { + try ( NodeCursor cursor = transaction.cursors().allocateNodeCursor(); + PropertyCursor properties = transaction.cursors().allocatePropertyCursor() ) + { + transaction.dataRead().singleNode( node, cursor ); + if ( !cursor.next() ) + { + return NO_VALUE; + } + else + { + cursor.properties( properties ); + while ( properties.next() ) + { + if ( properties.propertyKey() == property ) + { + return properties.propertyValue(); + } + } + return NO_VALUE; + } + } + } + + PrimitiveIntIterator nodeGetPropertyKeys( KernelTransaction transaction, long node ) + { + try ( NodeCursor cursor = transaction.cursors().allocateNodeCursor(); + PropertyCursor properties = transaction.cursors().allocatePropertyCursor() ) + { + PrimitiveIntSet props = Primitive.intSet(); + transaction.dataRead().singleNode( node, cursor ); + if ( cursor.next() ) + { + cursor.properties( properties ); + while ( properties.next() ) + { + props.add( properties.propertyKey() ); + } + } + return props.iterator(); + } + } + + Value relationshipGetProperty( KernelTransaction transaction, long relationship, int property ) + { + try ( RelationshipScanCursor cursor = transaction.cursors().allocateRelationshipScanCursor(); + PropertyCursor properties = transaction.cursors().allocatePropertyCursor() ) + { + transaction.dataRead().singleRelationship( relationship, cursor ); + if ( !cursor.next() ) + { + return NO_VALUE; + } + else + { + cursor.properties( properties ); + while ( properties.next() ) + { + if ( properties.propertyKey() == property ) + { + return properties.propertyValue(); + } + } + return NO_VALUE; + } + } + } + + Iterator nodeGetRelationships( KernelTransaction transaction, long node, Direction direction ) + { + return nodeGetRelationships( transaction, node, direction, null ); + } + + Iterator nodeGetRelationships( KernelTransaction transaction, long node, Direction direction, int[] types ) + { + NodeCursor cursor = transaction.cursors().allocateNodeCursor(); + transaction.dataRead().singleNode( node, cursor ); + if ( !cursor.next() ) + { + return emptyIterator(); + } + + switch ( direction ) + { + case OUTGOING: + return outgoingIterator( transaction.cursors(), cursor, types, + ( id, startNodeId, typeId, endNodeId ) -> id ); + case INCOMING: + return incomingIterator( transaction.cursors(), cursor, types, + ( id, startNodeId, typeId, endNodeId ) -> id ); + case BOTH: + return allIterator( transaction.cursors(), cursor, types, + ( id, startNodeId, typeId, endNodeId ) -> id ); + default: + throw new IllegalStateException( direction + " is not a valid direction" ); + } + } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/LabelIT.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/LabelIT.java index e587d153be4e8..619d1f1ff2ab3 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/LabelIT.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/LabelIT.java @@ -23,8 +23,9 @@ import java.util.Iterator; +import org.neo4j.internal.kernel.api.NamedToken; import org.neo4j.internal.kernel.api.Write; -import org.neo4j.kernel.api.ReadOperations; +import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.Statement; import org.neo4j.kernel.api.security.AnonymousContext; import org.neo4j.storageengine.api.Token; @@ -54,12 +55,12 @@ public void shouldListAllLabels() throws Exception // when commit(); - ReadOperations readOperations = readOperationsInNewTransaction(); - Iterator labelIdsAfterCommit = readOperations.labelsGetAllTokens(); + KernelTransaction transaction = newTransaction(); + Iterator labelIdsAfterCommit = transaction.tokenRead().labelsGetAllTokens(); // then assertThat( asCollection( labelIdsAfterCommit ), - hasItems( new Token( "label1", label1Id ), new Token( "label2", label2Id ) ) ); + hasItems( new NamedToken( "label1", label1Id ), new NamedToken( "label2", label2Id ) ) ); commit(); } @@ -82,7 +83,8 @@ public void addingAndRemovingLabelInSameTxShouldHaveNoEffect() throws Exception commit(); // And then the node should have the label - assertTrue( readOperationsInNewTransaction().nodeHasLabel( node, label ) ); + + assertTrue( nodeHasLabel( newTransaction(), node, label ) ); commit(); } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/ProceduresKernelIT.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/ProceduresKernelIT.java index 0774321fd1de3..18f2eaf243fc7 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/ProceduresKernelIT.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/ProceduresKernelIT.java @@ -95,7 +95,7 @@ public void shouldGetAllProcedures() throws Throwable // When List signatures = - Iterables.asList( readOperationsInNewTransaction().proceduresGetAll() ); + Iterables.asList( newTransaction().procedures().proceduresGetAll() ); // Then assertThat( signatures, hasItems( diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/PropertyIT.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/PropertyIT.java index 3b562e1e91c7d..ddc154b1b10a7 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/PropertyIT.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/PropertyIT.java @@ -24,9 +24,10 @@ import java.util.Collections; import java.util.Iterator; +import org.neo4j.internal.kernel.api.NamedToken; import org.neo4j.internal.kernel.api.Write; import org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException; -import org.neo4j.kernel.api.ReadOperations; +import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.Statement; import org.neo4j.kernel.api.security.AnonymousContext; import org.neo4j.storageengine.api.Token; @@ -60,10 +61,10 @@ public void shouldBeAbleToSetAndReadLargeByteArray() throws Exception // WHEN commit(); - ReadOperations readOperations = readOperationsInNewTransaction(); + KernelTransaction transaction = newTransaction(); // THEN - readOperations.nodeGetProperty( nodeId, propertyKeyId ); + nodeGetProperty( transaction, nodeId, propertyKeyId ); commit(); } @@ -73,23 +74,23 @@ public void shouldSetNodePropertyValue() throws Exception { // GIVEN Value value = Values.of( "bozo" ); - Statement statement = statementInNewTransaction( AnonymousContext.writeToken() ); + KernelTransaction transaction = newTransaction( AnonymousContext.writeToken() ); - long nodeId = statement.dataWriteOperations().nodeCreate(); + long nodeId = transaction.dataWrite().nodeCreate(); // WHEN - int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName( "clown" ); - statement.dataWriteOperations().nodeSetProperty( nodeId, propertyKeyId, value ); + int propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( "clown" ); + transaction.dataWrite().nodeSetProperty( nodeId, propertyKeyId, value ); // THEN - assertEquals( value, statement.readOperations().nodeGetProperty( nodeId, propertyKeyId ) ); + assertEquals( value, nodeGetProperty( transaction, nodeId, propertyKeyId ) ); // WHEN commit(); - ReadOperations readOperations = readOperationsInNewTransaction(); + transaction = newTransaction(); // THEN - assertEquals( value, readOperations.nodeGetProperty( nodeId, propertyKeyId ) ); + assertEquals( value, nodeGetProperty( transaction, nodeId, propertyKeyId ) ); commit(); } @@ -113,8 +114,8 @@ public void shouldRemoveSetNodeProperty() throws Exception commit(); // THEN - ReadOperations readOperations = readOperationsInNewTransaction(); - assertThat( readOperations.nodeGetProperty( nodeId, propertyKeyId ), equalTo( Values.NO_VALUE ) ); + KernelTransaction transaction = newTransaction(); + assertThat( nodeGetProperty( transaction, nodeId, propertyKeyId ), equalTo( Values.NO_VALUE ) ); commit(); } @@ -146,8 +147,8 @@ public void shouldRemoveSetNodePropertyAcrossTransactions() throws Exception } // THEN - ReadOperations readOperations = readOperationsInNewTransaction(); - assertThat( readOperations.nodeGetProperty( nodeId, propertyKeyId ), equalTo( Values.NO_VALUE ) ); + KernelTransaction transaction = newTransaction(); + assertThat( nodeGetProperty( transaction, nodeId, propertyKeyId ), equalTo( Values.NO_VALUE ) ); commit(); } @@ -185,9 +186,9 @@ public void shouldRemoveSetExistingProperty() throws Exception // THEN { - ReadOperations readOperations = readOperationsInNewTransaction(); - assertThat( readOperations.nodeGetProperty( nodeId, propertyKeyId ), equalTo( newValue ) ); - assertThat( toList( readOperations.nodeGetPropertyKeys( nodeId ) ), + KernelTransaction transaction = newTransaction(); + assertThat( nodeGetProperty( transaction, nodeId, propertyKeyId ), equalTo( newValue ) ); + assertThat( toList( nodeGetPropertyKeys( transaction, nodeId ) ), equalTo( Collections.singletonList( propertyKeyId ) ) ); commit(); } @@ -235,11 +236,11 @@ public void nodeHasPropertyIfSet() throws Exception // WHEN commit(); - ReadOperations readOperations = readOperationsInNewTransaction(); + KernelTransaction transaction = newTransaction(); // THEN - assertThat( readOperations.nodeHasProperty( nodeId, propertyKeyId ), is( true ) ); - assertThat( readOperations.nodeGetProperty( nodeId, propertyKeyId ), not( equalTo( Values.NO_VALUE ) ) ); + assertThat( nodeHasProperty( transaction, nodeId, propertyKeyId ), is( true ) ); + assertThat( nodeGetProperty( transaction, nodeId, propertyKeyId ), not( equalTo( Values.NO_VALUE ) ) ); commit(); } @@ -260,11 +261,11 @@ public void nodeHasNotPropertyIfUnset() throws Exception // WHEN commit(); - ReadOperations readOperations = readOperationsInNewTransaction(); + KernelTransaction transaction = newTransaction(); // THEN - assertThat( readOperations.nodeHasProperty( nodeId, propertyKeyId ), is( false ) ); - assertThat( readOperations.nodeGetProperty( nodeId, propertyKeyId ), equalTo( Values.NO_VALUE ) ); + assertThat( nodeHasProperty( transaction, nodeId, propertyKeyId ), is( false ) ); + assertThat( nodeGetProperty( transaction, nodeId, propertyKeyId ), equalTo( Values.NO_VALUE ) ); commit(); } @@ -283,9 +284,9 @@ public void shouldRollbackSetNodePropertyValue() throws Exception rollback(); // THEN - ReadOperations readOperations = readOperationsInNewTransaction(); - assertThat( readOperations.nodeHasProperty( nodeId, propertyKeyId ), is( false ) ); - assertThat( readOperations.nodeGetProperty( nodeId, propertyKeyId ), equalTo( Values.NO_VALUE ) ); + KernelTransaction transaction = newTransaction(); + assertThat( nodeHasProperty( transaction, nodeId, propertyKeyId ), is( false ) ); + assertThat( nodeGetProperty( transaction, nodeId, propertyKeyId ), equalTo( Values.NO_VALUE ) ); commit(); } @@ -305,8 +306,8 @@ public void shouldUpdateNodePropertyValue() throws Exception commit(); // THEN - ReadOperations readOperations = readOperationsInNewTransaction(); - assertEquals( 42, readOperations.nodeGetProperty( nodeId, propertyId ).asObject() ); + KernelTransaction transaction = newTransaction(); + assertEquals( 42, nodeGetProperty( transaction, nodeId, propertyId ).asObject() ); commit(); } @@ -329,12 +330,12 @@ public void shouldListAllPropertyKeys() throws Exception // when commit(); - ReadOperations readOperations = readOperationsInNewTransaction(); - Iterator propIdsAfterCommit = readOperations.propertyKeyGetAllTokens(); + KernelTransaction transaction = newTransaction(); + Iterator propIdsAfterCommit = transaction.tokenRead().propertyKeyGetAllTokens(); // then assertThat( asCollection( propIdsAfterCommit ), - hasItems( new Token( "prop1", prop1 ), new Token( "prop2", prop2 ) ) ); + hasItems( new NamedToken( "prop1", prop1 ), new NamedToken( "prop2", prop2 ) ) ); commit(); } @@ -411,8 +412,8 @@ public void shouldBeAbleToRemoveResetAndTwiceRemovePropertyOnNode() throws Excep commit(); // then - ReadOperations readOperations = readOperationsInNewTransaction(); - assertThat( readOperations.nodeGetProperty( node, prop ), equalTo( Values.NO_VALUE ) ); + KernelTransaction transaction = newTransaction(); + assertThat( nodeGetProperty( transaction, node, prop ), equalTo( Values.NO_VALUE ) ); commit(); } @@ -441,8 +442,8 @@ public void shouldBeAbleToRemoveResetAndTwiceRemovePropertyOnRelationship() thro commit(); // then - ReadOperations readOperations = readOperationsInNewTransaction(); - assertThat( readOperations.relationshipGetProperty( rel, prop ), equalTo( Values.NO_VALUE ) ); + KernelTransaction transaction = newTransaction(); + assertThat( relationshipGetProperty(transaction, rel, prop ), equalTo( Values.NO_VALUE ) ); commit(); } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/RelationshipIT.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/RelationshipIT.java index 03b628592e757..af3355a97ff2b 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/RelationshipIT.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/RelationshipIT.java @@ -24,16 +24,16 @@ import org.junit.Test; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import org.neo4j.collection.primitive.PrimitiveLongCollections; -import org.neo4j.collection.primitive.PrimitiveLongIterator; import org.neo4j.graphdb.Direction; import org.neo4j.graphdb.Transaction; -import org.neo4j.kernel.api.ReadOperations; +import org.neo4j.helpers.collection.Iterators; +import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.Statement; import org.neo4j.kernel.api.security.AnonymousContext; import org.neo4j.test.rule.concurrent.OtherThreadRule; @@ -55,58 +55,58 @@ public class RelationshipIT extends KernelIntegrationTest public void shouldListRelationshipsInCurrentAndSubsequentTx() throws Exception { // given - Statement statement = statementInNewTransaction( AnonymousContext.writeToken() ); - int relType1 = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName( "Type1" ); - int relType2 = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName( "Type2" ); - - long refNode = statement.dataWriteOperations().nodeCreate(); - long otherNode = statement.dataWriteOperations().nodeCreate(); - long fromRefToOther1 = statement.dataWriteOperations().relationshipCreate( relType1, refNode, otherNode ); - long fromRefToOther2 = statement.dataWriteOperations().relationshipCreate( relType2, refNode, otherNode ); - long fromOtherToRef = statement.dataWriteOperations().relationshipCreate( relType1, otherNode, refNode ); - long fromRefToRef = statement.dataWriteOperations().relationshipCreate( relType2, refNode, refNode ); - long endNode = statement.dataWriteOperations().nodeCreate(); - long fromRefToThird = statement.dataWriteOperations().relationshipCreate( relType2, refNode, endNode ); + KernelTransaction transaction = newTransaction( AnonymousContext.writeToken() ); + int relType1 = transaction.tokenWrite().relationshipTypeGetOrCreateForName( "Type1" ); + int relType2 = transaction.tokenWrite().relationshipTypeGetOrCreateForName( "Type2" ); + + long refNode = transaction.dataWrite().nodeCreate(); + long otherNode = transaction.dataWrite().nodeCreate(); + long fromRefToOther1 = transaction.dataWrite().relationshipCreate( refNode, relType1, otherNode ); + long fromRefToOther2 = transaction.dataWrite().relationshipCreate( refNode, relType2, otherNode ); + long fromOtherToRef = transaction.dataWrite().relationshipCreate( otherNode, relType1, refNode ); + long fromRefToRef = transaction.dataWrite().relationshipCreate( refNode, relType2, refNode ); + long endNode = transaction.dataWrite().nodeCreate(); + long fromRefToThird = transaction.dataWrite().relationshipCreate( refNode, relType2, endNode ); // when & then - assertRels( statement.readOperations().nodeGetRelationships( refNode, BOTH ), fromRefToOther1, fromRefToOther2, + assertRels( nodeGetRelationships( transaction, refNode, BOTH ), fromRefToOther1, fromRefToOther2, fromRefToRef, fromRefToThird, fromOtherToRef ); - assertRels( statement.readOperations().nodeGetRelationships( refNode, BOTH, new int[]{relType1} ), + assertRels( nodeGetRelationships( transaction, refNode, BOTH, new int[]{relType1} ), fromRefToOther1, fromOtherToRef ); - assertRels( statement.readOperations().nodeGetRelationships( refNode, BOTH, new int[]{relType1, relType2} ), + assertRels( nodeGetRelationships( transaction, refNode, BOTH, new int[]{relType1, relType2} ), fromRefToOther1, fromRefToOther2, fromRefToRef, fromRefToThird, fromOtherToRef ); - assertRels( statement.readOperations().nodeGetRelationships( refNode, INCOMING ), fromOtherToRef ); + assertRels( nodeGetRelationships( transaction, refNode, INCOMING ), fromOtherToRef ); - assertRels( statement.readOperations().nodeGetRelationships( refNode, INCOMING, new int[]{relType1} + assertRels( nodeGetRelationships( transaction, refNode, INCOMING, new int[]{relType1} /* none */ ) ); - assertRels( statement.readOperations().nodeGetRelationships( refNode, OUTGOING, new int[]{relType1, relType2} ), + assertRels( nodeGetRelationships( transaction, refNode, OUTGOING, new int[]{relType1, relType2} ), fromRefToOther1, fromRefToOther2, fromRefToThird, fromRefToRef ); // when commit(); - ReadOperations readOperations = readOperationsInNewTransaction(); + transaction = newTransaction(); // when & then - assertRels( readOperations.nodeGetRelationships( refNode, BOTH ), fromRefToOther1, fromRefToOther2, + assertRels( nodeGetRelationships( transaction, refNode, BOTH ), fromRefToOther1, fromRefToOther2, fromRefToRef, fromRefToThird, fromOtherToRef ); - assertRels( readOperations.nodeGetRelationships( refNode, BOTH, new int[]{relType1} ), fromRefToOther1, + assertRels( nodeGetRelationships( transaction, refNode, BOTH, new int[]{relType1} ), fromRefToOther1, fromOtherToRef ); - assertRels( readOperations.nodeGetRelationships( refNode, BOTH, new int[]{relType1, relType2} ), + assertRels( nodeGetRelationships( transaction, refNode, BOTH, new int[]{relType1, relType2} ), fromRefToOther1, fromRefToOther2, fromRefToRef, fromRefToThird, fromOtherToRef ); - assertRels( readOperations.nodeGetRelationships( refNode, INCOMING ), fromOtherToRef ); + assertRels( nodeGetRelationships( transaction, refNode, INCOMING ), fromOtherToRef ); - assertRels( readOperations.nodeGetRelationships( refNode, INCOMING, new int[]{relType1} ) + assertRels( nodeGetRelationships( transaction, refNode, INCOMING, new int[]{relType1} ) /* none */ ); - assertRels( readOperations.nodeGetRelationships( refNode, OUTGOING, new int[]{relType1, relType2} ), + assertRels( nodeGetRelationships( transaction, refNode, OUTGOING, new int[]{relType1, relType2} ), fromRefToOther1, fromRefToOther2, fromRefToThird, fromRefToRef ); commit(); } @@ -121,27 +121,27 @@ public void shouldInterleaveModifiedRelationshipsWithExistingOnes() throws Excep int relType1; int relType2; { - Statement statement = statementInNewTransaction( AnonymousContext.writeToken() ); + KernelTransaction transaction = newTransaction( AnonymousContext.writeToken() ); - relType1 = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName( "Type1" ); - relType2 = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName( "Type2" ); + relType1 = transaction.tokenWrite().relationshipTypeGetOrCreateForName( "Type1" ); + relType2 = transaction.tokenWrite().relationshipTypeGetOrCreateForName( "Type2" ); - refNode = statement.dataWriteOperations().nodeCreate(); - long otherNode = statement.dataWriteOperations().nodeCreate(); - fromRefToOther1 = statement.dataWriteOperations().relationshipCreate( relType1, refNode, otherNode ); - fromRefToOther2 = statement.dataWriteOperations().relationshipCreate( relType2, refNode, otherNode ); + refNode = transaction.dataWrite().nodeCreate(); + long otherNode = transaction.dataWrite().nodeCreate(); + fromRefToOther1 = transaction.dataWrite().relationshipCreate( refNode, relType1, otherNode ); + fromRefToOther2 = transaction.dataWrite().relationshipCreate( refNode, relType2, otherNode ); commit(); } { - Statement statement = statementInNewTransaction( AnonymousContext.writeToken() ); + KernelTransaction transaction = newTransaction( AnonymousContext.writeToken() ); // When - statement.dataWriteOperations().relationshipDelete( fromRefToOther1 ); - long endNode = statement.dataWriteOperations().nodeCreate(); - long localTxRel = statement.dataWriteOperations().relationshipCreate( relType1, refNode, endNode ); + transaction.dataWrite().relationshipDelete( fromRefToOther1 ); + long endNode = transaction.dataWrite().nodeCreate(); + long localTxRel = transaction.dataWrite().relationshipCreate( refNode, relType1, endNode ); // Then - assertRels( statement.readOperations().nodeGetRelationships( refNode, BOTH ), fromRefToOther2, localTxRel); + assertRels( nodeGetRelationships( transaction, refNode, BOTH ), fromRefToOther2, localTxRel); assertRelsInSeparateTx( refNode, BOTH, fromRefToOther1, fromRefToOther2); commit(); } @@ -150,17 +150,16 @@ public void shouldInterleaveModifiedRelationshipsWithExistingOnes() throws Excep @Test public void shouldReturnRelsWhenAskingForRelsWhereOnlySomeTypesExistInCurrentRel() throws Exception { - Statement statement = statementInNewTransaction( AnonymousContext.writeToken() ); + KernelTransaction transaction = newTransaction( AnonymousContext.writeToken() ); - int relType1 = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName( "Type1" ); - int relType2 = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName( "Type2" ); + int relType1 = transaction.tokenWrite().relationshipTypeGetOrCreateForName( "Type1" ); + int relType2 = transaction.tokenWrite().relationshipTypeGetOrCreateForName( "Type2" ); - long refNode = statement.dataWriteOperations().nodeCreate(); - long otherNode = statement.dataWriteOperations().nodeCreate(); - long theRel = statement.dataWriteOperations().relationshipCreate( relType1, refNode, otherNode ); + long refNode = transaction.dataWrite().nodeCreate(); + long otherNode = transaction.dataWrite().nodeCreate(); + long theRel = transaction.dataWrite().relationshipCreate( refNode, relType1, otherNode ); - assertRels( statement.readOperations().nodeGetRelationships( refNode, OUTGOING, new int[]{relType2,relType1} ), - theRel ); + assertRels( nodeGetRelationships( transaction, refNode, OUTGOING, new int[]{relType2,relType1} ), theRel ); commit(); } @@ -188,13 +187,13 @@ public void askingForNonExistantReltypeOnDenseNodeShouldNotCorruptState() throws } commit(); } - ReadOperations stmt = readOperationsInNewTransaction(); + KernelTransaction transaction = newTransaction(); // When I've asked for rels that the node does not have - assertRels( stmt.nodeGetRelationships( refNode, Direction.INCOMING, new int[]{relTypeTheNodeDoesNotUse} ) ); + assertRels( nodeGetRelationships( transaction, refNode, Direction.INCOMING, new int[]{relTypeTheNodeDoesNotUse} ) ); // Then the node should still load the real rels - assertRels( stmt.nodeGetRelationships( refNode, Direction.BOTH, new int[]{relTypeTheNodeDoesUse} ), rels ); + assertRels( nodeGetRelationships( transaction, refNode, Direction.BOTH, new int[]{relTypeTheNodeDoesUse} ), rels ); commit(); } @@ -203,17 +202,16 @@ private void assertRelsInSeparateTx( final long refNode, final Direction both, f { assertTrue( otherThread.execute( state -> { - try ( Transaction tx = db.beginTx(); - Statement statement = statementContextSupplier.get() ) + try ( Transaction ignore = db.beginTx(); + KernelTransaction ktx = statementContextSupplier.getKernelTransactionBoundToThisThread( true ) ) { - ReadOperations stmt = statement.readOperations(); - assertRels( stmt.nodeGetRelationships( refNode, both ), longs ); + assertRels( nodeGetRelationships( ktx, refNode, both ), longs ); } return true; } ).get( 10, TimeUnit.SECONDS ) ); } - private void assertRels( PrimitiveLongIterator it, long ... rels ) + private void assertRels( Iterator it, long ... rels ) { List>> all = new ArrayList<>( rels.length ); for ( long element : rels ) @@ -221,7 +219,7 @@ private void assertRels( PrimitiveLongIterator it, long ... rels ) all.add(hasItem(element)); } - List list = PrimitiveLongCollections.asList( it ); + List list = Iterators.asList( it ); assertThat( list, allOf(all)); } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/newapi/MockStore.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/newapi/MockStore.java index 531cde08ac804..d6dcb556893aa 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/newapi/MockStore.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/newapi/MockStore.java @@ -24,6 +24,8 @@ import org.junit.runners.model.Statement; import java.util.Iterator; +import java.util.Set; +import java.util.function.Function; import org.neo4j.collection.RawIterator; import org.neo4j.collection.primitive.Primitive; @@ -33,6 +35,7 @@ import org.neo4j.internal.kernel.api.exceptions.ProcedureException; import org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException; import org.neo4j.internal.kernel.api.procs.ProcedureHandle; +import org.neo4j.internal.kernel.api.procs.ProcedureSignature; import org.neo4j.internal.kernel.api.procs.QualifiedName; import org.neo4j.internal.kernel.api.procs.UserAggregator; import org.neo4j.internal.kernel.api.procs.UserFunctionHandle; @@ -257,6 +260,13 @@ public ProcedureHandle procedureGet( QualifiedName name ) throws ProcedureExcept } + @Override + public Set proceduresGetAll( ) throws ProcedureException + { + throw new UnsupportedOperationException( "not implemented" ); + + } + @Override public RawIterator procedureCallRead( int id, Object[] arguments ) throws ProcedureException @@ -637,4 +647,22 @@ public Long indexGetOwningUniquenessConstraintId( CapableIndexReference index ) { return null; } + + @Override + public V schemaStateGetOrCreate( K key, Function creator ) + { + throw new UnsupportedOperationException( "not implemented" ); + } + + @Override + public V schemaStateGet( K key ) + { + throw new UnsupportedOperationException( "not implemented" ); + } + + @Override + public void schemaStateFlush() + { + throw new UnsupportedOperationException( "not implemented" ); + } } diff --git a/enterprise/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/AbstractConstraintCreationIT.java b/enterprise/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/AbstractConstraintCreationIT.java index c8e5c10fce7f5..b243568e8ec0d 100644 --- a/enterprise/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/AbstractConstraintCreationIT.java +++ b/enterprise/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/AbstractConstraintCreationIT.java @@ -44,7 +44,6 @@ import org.neo4j.internal.kernel.api.schema.SchemaDescriptor; import org.neo4j.internal.kernel.api.schema.constraints.ConstraintDescriptor; import org.neo4j.kernel.api.KernelTransaction; -import org.neo4j.kernel.api.ReadOperations; import org.neo4j.kernel.api.exceptions.Status; import org.neo4j.kernel.api.exceptions.TransactionFailureException; import org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException; @@ -122,10 +121,10 @@ public void shouldBeAbleToStoreAndRetrieveConstraint() throws Exception // given commit(); - ReadOperations readOperations = readOperationsInNewTransaction(); + transaction = newTransaction(); // when - Iterator constraints = readOperations.constraintsGetAll(); + Iterator constraints = transaction.schemaRead().constraintsGetAll(); // then assertEquals( constraint, single( constraints ) ); @@ -148,10 +147,10 @@ public void shouldBeAbleToStoreAndRetrieveConstraintAfterRestart() throws Except // given commit(); restartDb(); - ReadOperations readOperations = readOperationsInNewTransaction(); + transaction = newTransaction(); // when - Iterator constraints = readOperations.constraintsGetAll(); + Iterator constraints = transaction.schemaRead().constraintsGetAll(); // then assertEquals( constraint, single( constraints ) ); @@ -170,10 +169,10 @@ public void shouldNotPersistConstraintCreatedInAbortedTransaction() throws Excep // when rollback(); - ReadOperations readOperations = readOperationsInNewTransaction(); + KernelTransaction transaction = newTransaction(); // then - Iterator constraints = readOperations.constraintsGetAll(); + Iterator constraints = transaction.schemaRead().constraintsGetAll(); assertFalse( "should not have any constraints", constraints.hasNext() ); commit(); } @@ -224,10 +223,10 @@ public void shouldDropConstraint() throws Exception // then { - ReadOperations statement = readOperationsInNewTransaction(); + KernelTransaction transaction = newTransaction(); // then - assertFalse( "should not have any constraints", statement.constraintsGetAll().hasNext() ); + assertFalse( "should not have any constraints", transaction.schemaRead().constraintsGetAll().hasNext() ); commit(); } } @@ -284,11 +283,11 @@ public void shouldNotRemoveConstraintThatGetsReAdded() throws Exception commit(); } { - ReadOperations statement = readOperationsInNewTransaction(); + KernelTransaction transaction = newTransaction(); // then - assertEquals( singletonList( constraint ), asCollection( statement.constraintsGetAll() ) ); - schemaState.assertNotCleared( statement ); + assertEquals( singletonList( constraint ), asCollection( transaction.schemaRead().constraintsGetAll() ) ); + schemaState.assertNotCleared( transaction ); commit(); } } @@ -306,7 +305,7 @@ public void shouldClearSchemaStateWhenConstraintIsCreated() throws Exception commit(); // then - schemaState.assertCleared( readOperationsInNewTransaction() ); + schemaState.assertCleared( newTransaction() ); rollback(); } @@ -333,7 +332,7 @@ public void shouldClearSchemaStateWhenConstraintIsDropped() throws Exception } // then - schemaState.assertCleared( readOperationsInNewTransaction() ); + schemaState.assertCleared( newTransaction() ); rollback(); } @@ -361,8 +360,8 @@ public void shouldNotDropConstraintThatDoesNotExist() throws Exception // then { - ReadOperations statement = readOperationsInNewTransaction(); - assertEquals( emptySet(), asSet( statement.indexesGetAll() ) ); + KernelTransaction transaction = newTransaction(); + assertEquals( emptySet(), asSet( transaction.schemaRead().indexesGetAll() ) ); commit(); } } @@ -493,29 +492,29 @@ public Integer apply( String s ) public SchemaStateCheck setUp() throws TransactionFailureException { - ReadOperations readOperations = readOperationsInNewTransaction(); - checkState( readOperations ); + KernelTransaction transaction = newTransaction(); + checkState( transaction ); commit(); return this; } - void assertCleared( ReadOperations readOperations ) + void assertCleared( KernelTransaction transaction ) { int count = invocationCount; - checkState( readOperations ); + checkState( transaction ); assertEquals( "schema state should have been cleared.", count + 1, invocationCount ); } - void assertNotCleared( ReadOperations readOperations ) + void assertNotCleared( KernelTransaction transaction ) { int count = invocationCount; - checkState( readOperations ); + checkState( transaction ); assertEquals( "schema state should not have been cleared.", count, invocationCount ); } - private SchemaStateCheck checkState( ReadOperations readOperations ) + private SchemaStateCheck checkState( KernelTransaction transaction ) { - assertEquals( Integer.valueOf( 7 ), readOperations.schemaStateGetOrCreate( "7", this ) ); + assertEquals( Integer.valueOf( 7 ), transaction.schemaRead().schemaStateGetOrCreate( "7", this ) ); return this; } } diff --git a/enterprise/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/NodePropertyExistenceConstraintCreationIT.java b/enterprise/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/NodePropertyExistenceConstraintCreationIT.java index a6b710bfabe7c..dc8a65692b6a7 100644 --- a/enterprise/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/NodePropertyExistenceConstraintCreationIT.java +++ b/enterprise/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/NodePropertyExistenceConstraintCreationIT.java @@ -32,7 +32,7 @@ import org.neo4j.internal.kernel.api.exceptions.KernelException; import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor; import org.neo4j.internal.kernel.api.schema.constraints.ConstraintDescriptor; -import org.neo4j.kernel.api.ReadOperations; +import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.exceptions.schema.DropConstraintFailureException; import org.neo4j.kernel.api.exceptions.schema.NoSuchConstraintException; import org.neo4j.kernel.api.schema.SchemaDescriptorFactory; @@ -137,9 +137,9 @@ public void shouldNotDropPropertyExistenceConstraintThatDoesNotExistWhenThereIsA // then { - ReadOperations statement = readOperationsInNewTransaction(); + KernelTransaction transaction = newTransaction(); - Iterator constraints = statement.constraintsGetForSchema( descriptor ); + Iterator constraints = transaction.schemaRead().constraintsGetForSchema( descriptor ); assertEquals( constraint, single( constraints ) ); commit(); diff --git a/enterprise/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/PropertyConstraintValidationIT.java b/enterprise/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/PropertyConstraintValidationIT.java index 91e690df85775..6823f75a0a1df 100644 --- a/enterprise/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/PropertyConstraintValidationIT.java +++ b/enterprise/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/PropertyConstraintValidationIT.java @@ -27,17 +27,17 @@ import java.util.UUID; import org.neo4j.SchemaHelper; -import org.neo4j.collection.primitive.PrimitiveLongCollections; import org.neo4j.graphdb.ConstraintViolationException; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Label; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Transaction; +import org.neo4j.internal.kernel.api.NodeCursor; import org.neo4j.internal.kernel.api.SchemaWrite; import org.neo4j.internal.kernel.api.TokenWrite; import org.neo4j.internal.kernel.api.exceptions.KernelException; import org.neo4j.kernel.api.DataWriteOperations; -import org.neo4j.kernel.api.ReadOperations; +import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.Statement; import org.neo4j.kernel.api.exceptions.ConstraintViolationTransactionFailureException; import org.neo4j.kernel.api.exceptions.Status; @@ -207,8 +207,8 @@ void removeProperty( DataWriteOperations writeOps, long entityId, int propertyKe @Override int entityCount() throws TransactionFailureException { - ReadOperations readOps = readOperationsInNewTransaction(); - int result = PrimitiveLongCollections.count( readOps.nodesGetAll() ); + KernelTransaction transaction = newTransaction(); + int result = countNodes( transaction ); rollback(); return result; } @@ -294,8 +294,8 @@ void removeProperty( DataWriteOperations writeOps, long entityId, int propertyKe @Override int entityCount() throws TransactionFailureException { - ReadOperations readOps = readOperationsInNewTransaction(); - int result = PrimitiveLongCollections.count( readOps.relationshipsGetAll() ); + KernelTransaction transaction = newTransaction(); + int result = countNodes( transaction ); rollback(); return result; } @@ -425,5 +425,19 @@ public void shouldAllowCreationOfNonConflictingData() throws Exception // then assertEquals( 5, entityCount() ); } + + protected int countNodes( KernelTransaction transaction ) + { + int result = 0; + try ( NodeCursor cursor = transaction.cursors().allocateNodeCursor() ) + { + transaction.dataRead().allNodesScan( cursor ); + while ( cursor.next() ) + { + result++; + } + } + return result; + } } } diff --git a/enterprise/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/UniquenessConstraintCreationIT.java b/enterprise/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/UniquenessConstraintCreationIT.java index 8d0b5c45be439..53605783659ab 100644 --- a/enterprise/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/UniquenessConstraintCreationIT.java +++ b/enterprise/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/UniquenessConstraintCreationIT.java @@ -36,7 +36,6 @@ import org.neo4j.internal.kernel.api.schema.constraints.ConstraintDescriptor; import org.neo4j.internal.kernel.api.security.LoginContext; import org.neo4j.kernel.api.KernelTransaction; -import org.neo4j.kernel.api.ReadOperations; import org.neo4j.kernel.api.SilentTokenNameLookup; import org.neo4j.kernel.api.Statement; import org.neo4j.kernel.api.exceptions.TransactionFailureException; @@ -181,8 +180,8 @@ public void shouldCreateAnIndexToGoAlongWithAUniquePropertyConstraint() throws E commit(); // then - ReadOperations readOperations = readOperationsInNewTransaction(); - assertEquals( asSet( uniqueIndex ), asSet( readOperations.indexesGetAll() ) ); + KernelTransaction transaction = newTransaction(); + assertEquals( asSet( uniqueIndex ), asSet( transaction.schemaRead().indexesGetAll() ) ); commit(); } @@ -198,8 +197,8 @@ public void shouldDropCreatedConstraintIndexWhenRollingBackConstraintCreation() rollback(); // then - ReadOperations readOperations = readOperationsInNewTransaction(); - assertEquals( emptySet(), asSet( readOperations.indexesGetAll() ) ); + KernelTransaction transaction = newTransaction(); + assertEquals( emptySet(), asSet( transaction.schemaRead().indexesGetAll() ) ); commit(); } @@ -232,9 +231,9 @@ public void shouldNotDropUniquePropertyConstraintThatDoesNotExistWhenThereIsAPro // then { - ReadOperations statement = readOperationsInNewTransaction(); + KernelTransaction transaction = newTransaction(); - Iterator constraints = statement.constraintsGetForSchema( descriptor ); + Iterator constraints = transaction.schemaRead().constraintsGetForSchema( descriptor ); assertEquals( ConstraintDescriptorFactory.existsForSchema( descriptor ), single( constraints ) ); commit(); @@ -280,8 +279,8 @@ public void shouldDropConstraintIndexWhenDroppingConstraint() throws Exception commit(); // then - ReadOperations readOperations = readOperationsInNewTransaction(); - assertEquals( emptySet(), asSet( readOperations.indexesGetAll() ) ); + KernelTransaction transaction = newTransaction(); + assertEquals( emptySet(), asSet( transaction.schemaRead().indexesGetAll() ) ); commit(); }