private void relateNTimes( int nRelationshipsInStore, int type, long n1, long n2, Transaction tx ) throws KernelException { for ( int i = 0; i < nRelationshipsInStore; i++ ) { tx.dataWrite().relationshipCreate( n1, type, n2 ); } }
protected Write dataWriteInNewTransaction() throws KernelException { transaction = kernel.beginTransaction( implicit, AnonymousContext.write() ); return transaction.dataWrite(); }
private long createNode( Transaction transaction, String key, Object value ) throws KernelException { long node = transaction.dataWrite().nodeCreate(); int propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( key ); transaction.dataWrite().nodeSetProperty( node, propertyKeyId, Values.of( value ) ); return node; }
private long createLabeledNode( Transaction transaction, String label, String key, Object value ) throws KernelException { long node = createLabeledNode( transaction, label ); int propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( key ); transaction.dataWrite().nodeSetProperty( node, propertyKeyId, Values.of( value ) ); return node; }
@Test public void shouldNotAddLabelToNonExistingNode() throws Exception { long node = 1337L; try ( Transaction tx = beginTransaction() ) { int labelId = tx.token().labelGetOrCreateForName( labelName ); exception.expect( KernelException.class ); tx.dataWrite().nodeAddLabel( node, labelId ); } }
@Test public void shouldAllowNoopLabelUpdate() throws KernelException { // given long node = constrainedNode( "Label1", "key1", "value1" ); Transaction transaction = newTransaction( AnonymousContext.writeToken() ); // when int label = transaction.tokenWrite().labelGetOrCreateForName( "Label1" ); transaction.dataWrite().nodeAddLabel( node, label ); // then should not throw exception commit(); }
@Test public void shouldAddLabelNodeOnce() throws Exception { long node = createNodeWithLabel( labelName ); try ( Transaction tx = beginTransaction() ) { int labelId = tx.token().labelGetOrCreateForName( labelName ); assertFalse( tx.dataWrite().nodeAddLabel( node, labelId ) ); tx.success(); } assertLabels( node, labelName ); }
@Test public void shouldAllowRemoveAndAddConflictingDataInOneTransaction_RemoveProperty() throws Exception { // given long node = constrainedNode( "Label1", "key1", "value1" ); Transaction transaction = newTransaction( AnonymousContext.writeToken() ); // when int key = transaction.tokenRead().propertyKey( "key1" ); transaction.dataWrite().nodeRemoveProperty( node, key ); createLabeledNode( transaction, "Label1", "key1", "value1" ); commit(); }
private Pair<Long,Value> nodeWithProp( Transaction tx, Object value ) throws Exception { Write write = tx.dataWrite(); long node = write.nodeCreate(); write.nodeAddLabel( node, tx.tokenWrite().labelGetOrCreateForName( "Node" ) ); Value val = Values.of( value ); write.nodeSetProperty( node, tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ), val ); return Pair.of( node, val ); }
@Test public void shouldAllowRemoveAndAddConflictingDataInOneTransaction_RemoveLabel() throws Exception { // given long node = constrainedNode( "Label1", "key1", "value1" ); Transaction transaction = newTransaction( AnonymousContext.writeToken() ); // when int label = transaction.tokenWrite().labelGetOrCreateForName( "Label1" ); transaction.dataWrite().nodeRemoveLabel( node, label ); createLabeledNode( transaction, "Label1", "key1", "value1" ); commit(); }
private Pair<Long,Value> nodeWithProp( Transaction tx, Object value ) throws Exception { Write write = tx.dataWrite(); long node = write.nodeCreate(); write.nodeAddLabel( node, tx.tokenWrite().labelGetOrCreateForName( "Node" ) ); Value val = Values.of( value ); write.nodeSetProperty( node, tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ), val ); return Pair.of( node, val ); } }
@Test public void txReturnsCorrectIdWhenRolledBack() throws Exception { executeDummyTxs( db, 42 ); org.neo4j.internal.kernel.api.Transaction tx = newTransaction( AUTH_DISABLED ); tx.dataWrite().nodeCreate(); tx.failure(); assertEquals( KernelTransaction.ROLLBACK, tx.closeTransaction() ); assertFalse( tx.isOpen() ); }
@Test public void txReturnsCorrectIdWhenMarkedForTermination() throws Exception { executeDummyTxs( db, 42 ); org.neo4j.internal.kernel.api.Transaction tx = newTransaction( AUTH_DISABLED ); tx.dataWrite().nodeCreate(); tx.markForTermination( Status.Transaction.Terminated ); assertEquals( KernelTransaction.ROLLBACK, tx.closeTransaction() ); assertFalse( tx.isOpen() ); }
@Test public void shouldAllowNoopPropertyUpdate() throws KernelException { // given long node = constrainedNode( "Label1", "key1", "value1" ); Transaction transaction = newTransaction( AnonymousContext.writeToken() ); // when int key = transaction.tokenWrite().propertyKeyGetOrCreateForName( "key1" ); transaction.dataWrite().nodeSetProperty( node, key, Values.of( "value1" ) ); // then should not throw exception commit(); }
@Test public void txReturnsCorrectIdWhenFailedAndMarkedForTermination() throws Exception { executeDummyTxs( db, 42 ); org.neo4j.internal.kernel.api.Transaction tx = newTransaction( AUTH_DISABLED ); tx.dataWrite().nodeCreate(); tx.failure(); tx.markForTermination( Status.Transaction.Terminated ); assertEquals( KernelTransaction.ROLLBACK, tx.closeTransaction() ); assertFalse( tx.isOpen() ); }
@Test public void shouldAllowRemoveAndAddConflictingDataInOneTransaction_ChangeProperty() throws Exception { // given long node = constrainedNode( "Label1", "key1", "value1" ); Transaction transaction = newTransaction( AnonymousContext.writeToken() ); // when int propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( "key1" ); transaction.dataWrite().nodeSetProperty( node, propertyKeyId, Values.of( "value2" ) ); createLabeledNode( transaction, "Label1", "key1", "value1" ); commit(); }
@Test public void txReturnsCorrectIdWhenCommitted() throws Exception { executeDummyTxs( db, 42 ); org.neo4j.internal.kernel.api.Transaction tx = newTransaction( AUTH_DISABLED ); tx.dataWrite().nodeCreate(); tx.success(); long previousCommittedTxId = lastCommittedTxId( db ); assertEquals( previousCommittedTxId + 1, tx.closeTransaction() ); assertFalse( tx.isOpen() ); }