SchemaCalculator( Transaction ktx ) { this.dataRead = ktx.dataRead(); this.tokenRead = ktx.tokenRead(); this.cursors = ktx.cursors(); // the only one that is common for both nodes and rels so thats why we can do it here propertyIdToPropertyNameMapping = new HashMap<>( tokenRead.propertyKeyCount() ); addNamesToCollection( tokenRead.propertyKeyGetAllTokens(), propertyIdToPropertyNameMapping ); }
private boolean hasProperties( RelationshipScanCursor cursor, Transaction tx ) { try ( PropertyCursor propertyCursor = tx.cursors().allocatePropertyCursor() ) { cursor.properties( propertyCursor ); return propertyCursor.next(); } }
protected int countNodes( Transaction transaction ) { int result = 0; try ( NodeCursor cursor = transaction.cursors().allocateNodeCursor() ) { transaction.dataRead().allNodesScan( cursor ); while ( cursor.next() ) { result++; } } return result; }
static int countRelationships( Transaction transaction ) { int result = 0; try ( RelationshipScanCursor cursor = transaction.cursors().allocateRelationshipScanCursor() ) { transaction.dataRead().allRelationshipsScan( cursor ); while ( cursor.next() ) { result++; } } return result; }
@Test public void shouldSeeNewGraphPropertyInTransaction() throws Exception { try ( Transaction tx = beginTransaction(); PropertyCursor cursor = tx.cursors().allocatePropertyCursor() ) { int prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ); assertThat( tx.dataWrite().graphSetProperty( prop, stringValue( "hello" ) ), equalTo( NO_VALUE ) ); tx.dataRead().graphProperties( cursor ); assertTrue( cursor.next() ); assertThat( cursor.propertyKey(), equalTo( prop ) ); assertThat( cursor.propertyValue(), equalTo( stringValue( "hello" ) ) ); } }
private void assertNoNode( long nodeId ) throws TransactionFailureException { try ( Transaction tx = beginTransaction(); NodeCursor cursor = tx.cursors().allocateNodeCursor() ) { tx.dataRead().singleNode( nodeId, cursor ); assertFalse( cursor.next() ); } } }
@Ignore public void shouldNotFindDeletedNodeInConjunctionLabelScan() throws Exception { // Given Node node = createNode( "label1", "label2" ); try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction(); NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor() ) { // when tx.dataWrite().nodeDelete( node.node ); tx.dataRead().nodeLabelIntersectionScan( cursor, node.labels ); // then assertFalse( cursor.next() ); } }
@Ignore public void shouldNotFindDeletedNodeInDisjunctionLabelScan() throws Exception { // Given Node node = createNode( "label1", "label2" ); try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction(); NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor() ) { // when tx.dataWrite().nodeDelete( node.node ); tx.dataRead().nodeLabelUnionScan( cursor, node.labels ); // then assertFalse( cursor.next() ); } }
@Test public void shouldNotFindDeletedNodeInLabelScan() throws Exception { // Given Node node = createNode( "label" ); try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction(); NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor() ) { // when tx.dataWrite().nodeDelete( node.node ); tx.dataRead().nodeLabelScan( node.labels[0], cursor ); // then assertFalse( cursor.next() ); } }
@Test public void shouldNotFindNodeWithRemovedLabelInLabelScan() throws Exception { // Given Node node = createNode( "label" ); try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction(); NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor() ) { // when tx.dataWrite().nodeRemoveLabel( node.node, node.labels[0] ); tx.dataRead().nodeLabelScan( node.labels[0], cursor ); // then assertFalse( cursor.next() ); } }
@Ignore public void shouldNotFindNodeWithRemovedLabelInConjunctionLabelScan() throws Exception { // Given Node node = createNode( "label1", "label2" ); try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction(); NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor() ) { // when tx.dataWrite().nodeRemoveLabel( node.node, node.labels[1] ); tx.dataRead().nodeLabelIntersectionScan( cursor, node.labels ); // then assertFalse( cursor.next() ); } }
@Test public void hasPropertiesShouldSeeNewlyCreatedPropertiesOnNewlyCreatedNode() throws Exception { try ( Transaction tx = beginTransaction() ) { long node = tx.dataWrite().nodeCreate(); try ( NodeCursor cursor = tx.cursors().allocateNodeCursor(); PropertyCursor props = tx.cursors().allocatePropertyCursor() ) { tx.dataRead().singleNode( node, cursor ); assertTrue( cursor.next() ); assertFalse( hasProperties( cursor, props ) ); tx.dataWrite().nodeSetProperty( node, tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ), stringValue( "foo" ) ); assertTrue( hasProperties( cursor, props ) ); } } }
@Test public void txReturnsCorrectIdWhenReadOnly() throws Exception { executeDummyTxs( db, 42 ); org.neo4j.internal.kernel.api.Transaction tx = newTransaction(); try ( NodeCursor node = tx.cursors().allocateNodeCursor() ) { tx.dataRead().singleNode( 1, node ); node.next(); } tx.success(); assertEquals( KernelTransaction.READ_ONLY, tx.closeTransaction() ); assertFalse( tx.isOpen() ); }
@Ignore public void shouldFindNodeWithOneRemovedLabelInDisjunctionLabelScan() throws Exception { // Given Node node = createNode( "label1", "label2" ); try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction(); NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor() ) { // when tx.dataWrite().nodeRemoveLabel( node.node, node.labels[1] ); tx.dataRead().nodeLabelUnionScan( cursor, node.labels ); // then assertTrue( cursor.next() ); assertEquals( node.node, cursor.nodeReference() ); } }
@Ignore public void shouldNotFindNodeWithAllRemovedLabelsInDisjunctionLabelScan() throws Exception { // Given Node node = createNode( "label1", "label2" ); try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction(); NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor() ) { // when tx.dataWrite().nodeRemoveLabel( node.node, node.labels[0] ); tx.dataWrite().nodeRemoveLabel( node.node, node.labels[1] ); tx.dataRead().nodeLabelUnionScan( cursor, node.labels ); // then assertFalse( cursor.next() ); } }
@Before public void setupGraph() throws IOException, KernelException { if ( testSupport == null ) { folder.create(); testSupport = newTestSupport(); testSupport.setup( folder.getRoot(), this::createTestGraph ); } Kernel kernel = testSupport.kernelToTest(); tx = kernel.beginTransaction( Transaction.Type.implicit, LoginContext.AUTH_DISABLED ); token = tx.token(); read = tx.dataRead(); indexRead = tx.indexRead(); schemaRead = tx.schemaRead(); cursors = new ManagedTestCursors( tx.cursors() ); }
@Ignore public void shouldNotFindNodeWithOneRemovedLabelsInDisjunctionLabelScan() throws Exception { // Given Node node = createNode( "label1"); try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction(); NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor() ) { // when int label1 = tx.tokenWrite().labelGetOrCreateForName( "label1" ); int label2 = tx.tokenWrite().labelGetOrCreateForName( "label2" ); tx.dataWrite().nodeRemoveLabel( node.node, label1 ); tx.dataRead().nodeLabelUnionScan( cursor, label1, label2 ); // then assertFalse( cursor.next() ); } }
@Test public void shouldFindUpdatedNodeInInLabelScan() throws Exception { // Given Node node = createNode( ); try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction(); NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor() ) { // when int label = tx.tokenWrite().labelGetOrCreateForName( "label" ); tx.dataWrite().nodeAddLabel( node.node, label ); tx.dataRead().nodeLabelScan( label, cursor ); // then assertTrue( cursor.next() ); assertEquals( node.node, cursor.nodeReference() ); } }
@Ignore public void shouldFindUpdatedNodeInInDisjunctionLabelScan() throws Exception { // Given Node node = createNode( "label1" ); try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction(); NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor() ) { // when int label2 = tx.tokenWrite().labelGetOrCreateForName( "label2" ); tx.dataWrite().nodeAddLabel( node.node, label2 ); tx.dataRead().nodeLabelUnionScan( cursor, node.labels[0], label2 ); // then assertTrue( cursor.next() ); assertEquals( node.node, cursor.nodeReference() ); } }
@Ignore public void shouldNotFindNodeWithJustOneUpdatedLabelInInConjunctionLabelScan() throws Exception { // Given Node node = createNode(); try ( org.neo4j.internal.kernel.api.Transaction tx = beginTransaction(); NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor() ) { // when int label1 = tx.tokenWrite().labelGetOrCreateForName( "labe1" ); int label2 = tx.tokenWrite().labelGetOrCreateForName( "label2" ); tx.dataWrite().nodeAddLabel( node.node, label2 ); tx.dataRead().nodeLabelIntersectionScan( cursor, label1, label2 ); // then assertFalse( cursor.next() ); } }