private Node createNode( GraphDatabaseService db, String key, Object value, Label label ) { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode( label ); node.setProperty( key, value ); tx.success(); return node; } } }
private static void executeDummyTxs( GraphDatabaseService db, int count ) { for ( int i = 0; i < count; i++ ) { try ( Transaction tx = db.beginTx() ) { db.createNode(); tx.success(); } } }
void setProperty( String nodeName, String propertyName, Object propertyValue ) { Node i = this.getNode( nodeName ); GraphDatabaseService db = i.getGraphDatabase(); try ( Transaction tx = db.beginTx() ) { i.setProperty( propertyName, propertyValue ); tx.success(); } }
@Test @Graph( { "a TO b", "b TO c", "c TO a" } ) public void canCreateGraphFromMultipleStrings() { Map<String,Node> graph = data.get(); Set<Node> unique = new HashSet<>(); Node n = graph.get( "a" ); while ( unique.add( n ) ) { try ( Transaction ignored = graphdb.beginTx() ) { n = n.getSingleRelationship( RelationshipType.withName( "TO" ), Direction.OUTGOING ).getEndNode(); } } assertEquals( graph.size(), unique.size() ); }
private void makeSureFirstAndLastAreReturnedCorrectly( EntityCreator<PropertyContainer> creator, TimelineIndex<PropertyContainer> timeline ) { LinkedList<Pair<PropertyContainer, Long>> timestamps = createTimestamps( creator, timeline, 223456, 12345, 432234 ); try ( Transaction tx = db.beginTx() ) { assertEquals( timestamps.get( 1 ).first(), timeline.getFirst() ); assertEquals( timestamps.getLast().first(), timeline.getLast() ); tx.success(); } }
private void assertPropertyEqual( PropertyContainer primitive, String key, String value ) { try ( Transaction tx = getGraphDb().beginTx() ) { assertEquals( value, primitive.getProperty( key ) ); } }
private void createSomeData( Label label, String propertyKey ) { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode( label ); node.setProperty( propertyKey, "yeah" ); tx.success(); } } }
@Test public void awaitingIndexComingOnlineWorks() { // GIVEN // WHEN IndexDefinition index = createIndex( db, label, propertyKey ); // PASS try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexOnline( index, 1L, TimeUnit.MINUTES ); // THEN assertEquals( Schema.IndexState.ONLINE, db.schema().getIndexState( index ) ); } }
private void makeSureRangesAreReturnedInCorrectOrder( EntityCreator<PropertyContainer> creator, TimelineIndex<PropertyContainer> timeline ) { LinkedList<Pair<PropertyContainer, Long>> timestamps = createTimestamps( creator, timeline, 300000, 200000, 400000, 100000, 500000, 600000, 900000, 800000 ); try ( Transaction tx = db.beginTx() ) { assertEquals( sortedEntities( timestamps, false ), asCollection( timeline.getBetween( null, null ).iterator() ) ); tx.success(); } }
@Test @Graph( { "a:Person EATS b:Banana" } ) public void ensurePeopleCanEatBananas() { Map<String,Node> graph = data.get(); Node a = graph.get( "a" ); Node b = graph.get( "b" ); try ( Transaction ignored = graphdb.beginTx() ) { assertTrue( a.hasLabel( label( "Person" ) ) ); assertTrue( b.hasLabel( label( "Banana" ) ) ); } }
private void assertRelationshipCount( Node node, int count ) { try ( Transaction tx = getGraphDb().beginTx() ) { int actualCount = 0; for ( Relationship rel : node.getRelationships() ) { actualCount++; } assertEquals( count, actualCount ); } } }
private static void createNode( GraphDatabaseService database ) { try ( Transaction transaction = database.beginTx() ) { database.createNode(); transaction.success(); } }
private static Node createNodeWithProperty( GraphDatabaseService db, String key, Object value ) { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode(); node.setProperty( key, value ); tx.success(); return node; } }
@Test public void shouldCreateNode() throws Exception { long node; try ( Transaction tx = beginTransaction() ) { node = tx.dataWrite().nodeCreate(); tx.success(); } try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() ) { assertEquals( node, graphDb.getNodeById( node ).getId() ); } }
private void makeSureWeCanQueryLowerDefaultThan1970( EntityCreator<PropertyContainer> creator, TimelineIndex<PropertyContainer> timeline ) { LinkedList<Pair<PropertyContainer,Long>> timestamps = createTimestamps( creator, timeline, -10000, 0, 10000 ); try ( Transaction tx = db.beginTx() ) { assertEquals( sortedEntities( timestamps, true ), asCollection( timeline.getBetween( null, 10000L, true ).iterator() ) ); tx.success(); } }
@Test @Graph( value = {"I know you"}, autoIndexNodes = true ) public void canAutoIndexNodes() { data.get(); try ( Transaction ignored = graphdb.beginTx() ) { try ( IndexHits<Node> indexHits = graphdb().index().getNodeAutoIndexer().getAutoIndex().get( "name", "I" ) ) { assertTrue( "can't look up node.", indexHits.hasNext() ); } } }
private Runnable createNodeWithLabel( Label label ) { return () -> { try ( Transaction transaction = database.beginTx() ) { database.createNode( label ); transaction.success(); } }; }
private void createAliens() { try ( Transaction tx = db.beginTx() ) { for ( int i = 0; i < 32; i++ ) { Node alien = db.createNode( ALIEN ); alien.setProperty( SPECIMEN, i / 2 ); } tx.success(); } }
@Test public void awaitingAllIndexesComingOnlineWorks() { // GIVEN // WHEN IndexDefinition index = createIndex( db, label, propertyKey ); createIndex( db, label, "other_property" ); // PASS waitForIndex( db, index ); try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexesOnline( 1L, TimeUnit.MINUTES ); // THEN assertEquals( Schema.IndexState.ONLINE, db.schema().getIndexState( index ) ); } }