Refine search
@Test public void getAllRelationshipsIteratorShouldPickUpHigherIdsThanHighIdWhenStarted() throws Exception { // GIVEN Transaction tx = db.beginTx(); createRelationshipAssumingTxWith( "key", 1 ); createRelationshipAssumingTxWith( "key", 2 ); tx.success(); tx.close(); // WHEN tx = db.beginTx(); Iterator<Relationship> allRelationships = db.getAllRelationships().iterator(); Thread thread = new Thread( () -> { Transaction newTx = db.beginTx(); assertThat( newTx, not( instanceOf( PlaceboTransaction.class ) ) ); createRelationshipAssumingTxWith( "key", 3 ); newTx.success(); newTx.close(); } ); thread.start(); thread.join(); // THEN assertThat( addToCollection( allRelationships, new ArrayList<>() ).size(), is(3) ); tx.success(); tx.close(); }
@Test public void getAllNodesIteratorShouldPickUpHigherIdsThanHighIdWhenStarted() throws Exception { // GIVEN { Transaction tx = db.beginTx(); db.createNode(); db.createNode(); tx.success(); tx.close(); } // WHEN iterator is started Transaction transaction = db.beginTx(); Iterator<Node> allNodes = db.getAllNodes().iterator(); allNodes.next(); // and WHEN another node is then added Thread thread = new Thread( () -> { Transaction newTx = db.beginTx(); assertThat( newTx, not( instanceOf( PlaceboTransaction.class ) ) ); db.createNode(); newTx.success(); newTx.close(); } ); thread.start(); thread.join(); // THEN the new node is picked up by the iterator assertThat( addToCollection( allNodes, new ArrayList<>() ).size(), is( 2 ) ); transaction.close(); }
@Test public void deletedNodeShouldShowUpWithinTransaction() { // GIVEN GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); Neo4jMatchers.createIndex( beansAPI, LABEL1, "name" ); Node firstNode = createNode( beansAPI, map( "name", "Mattias" ), LABEL1 ); // WHEN Transaction tx = beansAPI.beginTx(); long sizeBeforeDelete = count( beansAPI.findNodes( LABEL1, "name", "Mattias" ) ); firstNode.delete(); long sizeAfterDelete = count( beansAPI.findNodes( LABEL1, "name", "Mattias" ) ); tx.close(); // THEN assertThat( sizeBeforeDelete, equalTo(1L) ); assertThat( sizeAfterDelete, equalTo(0L) ); }
@Test public void getNonExistentGraphPropertyWithDefaultValue() { GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase(); PropertyContainer graphProperties = properties( db ); Transaction tx = db.beginTx(); assertEquals( "default", graphProperties.getProperty( "test", "default" ) ); tx.success(); tx.close(); db.shutdown(); }
@Test public void createdNodeShouldShowUpWithinTransaction() { // GIVEN GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); Neo4jMatchers.createIndex( beansAPI, LABEL1, "name" ); // WHEN Transaction tx = beansAPI.beginTx(); Node firstNode = createNode( beansAPI, map( "name", "Mattias" ), LABEL1 ); long sizeBeforeDelete = count( beansAPI.findNodes( LABEL1, "name", "Mattias" ) ); firstNode.delete(); long sizeAfterDelete = count( beansAPI.findNodes( LABEL1, "name", "Mattias" ) ); tx.close(); // THEN assertThat( sizeBeforeDelete, equalTo(1L) ); assertThat( sizeAfterDelete, equalTo(0L) ); }
@Test public void createdNodeShouldShowUpInIndexQuery() { // GIVEN GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); Neo4jMatchers.createIndex( beansAPI, LABEL1, "name" ); createNode( beansAPI, map( "name", "Mattias" ), LABEL1 ); // WHEN Transaction tx = beansAPI.beginTx(); long sizeBeforeDelete = count( beansAPI.findNodes( LABEL1, "name", "Mattias" ) ); createNode( beansAPI, map( "name", "Mattias" ), LABEL1 ); long sizeAfterDelete = count( beansAPI.findNodes( LABEL1, "name", "Mattias" ) ); tx.close(); // THEN assertThat( sizeBeforeDelete, equalTo(1L) ); assertThat( sizeAfterDelete, equalTo(2L) ); }
@Test public void testRemovePropertyDeletedNode() { Node node = getGraphDb().createNode(); node.setProperty( key, 1 ); node.delete(); try { node.removeProperty( key ); Transaction tx = getTransaction(); tx.success(); tx.close(); fail( "Change property on deleted node should not validate" ); } catch ( Exception e ) { // ok } }
@Test public void onlineConstraintShouldRejectChangingEntryToAlreadyIndexedValueThatOtherTransactionsAreRemoving() { // Given givenOnlineConstraint(); transaction( setProperty( b, "b" ), success ); Transaction otherTx = db.beginTx(); a.removeLabel( label ); suspend( otherTx ); // When try { transaction( setProperty( b, "a" ), success, fail( "Changing a property to an already indexed value should have thrown" ) ); } catch ( ConstraintViolationException ignore ) { // we're happy } finally { resume( otherTx ); otherTx.failure(); otherTx.close(); } }