@Override protected boolean matchesSafely( GraphDatabaseService db, Description mismatchDescription ) { Set<Node> found = asSet( db.findNodes( withLabel ) ); if ( !found.isEmpty() ) { mismatchDescription.appendText( "found " + found.toString() ); return false; } return true; }
private static Node findNode( GraphDatabaseService db, Label label, String property, String value ) { try ( ResourceIterator<Node> nodes = db.findNodes( label, property, value ) ) { return Iterators.single( nodes ); } }
@Override protected Iterable<Node> manifest() { return loop( db.findNodes( label, propertyName, propertyValue ) ); } };
private Node getNodeByLabel( Label label ) { try ( ResourceIterator<Node> iterator = graphDb.findNodes( label ) ) { return iterator.next(); } }
private static Node findNodeByLabel( GraphDatabaseService database, Label testLabel ) { try ( ResourceIterator<Node> nodes = database.findNodes( testLabel ) ) { return nodes.next(); } }
@Override protected boolean matchesSafely( GraphDatabaseService db, Description mismatchDescription ) { Set<Node> expected = asSet( expectedNodes ); Set<Node> found = asSet( db.findNodes( withLabel ) ); if ( !expected.equals( found ) ) { mismatchDescription.appendText( "found " + found.toString() ); return false; } return true; }
private Function<GraphDatabaseService, List<Long>> listNodeIdsFromIndexLookup( final Label label, final String propertyKey, final Object value ) { return graphDb -> { ArrayList<Long> ids = new ArrayList<>(); for ( Node node : loop( graphDb.findNodes( label, propertyKey, value ) ) ) { ids.add( node.getId() ); } return ids; }; }
private static void addToResults( GraphDatabaseService db, HashMap<TestValue, Set<Object>> results, TestValue value ) { ResourceIterator<Node> foundNodes = db.findNodes( label( LABEL ), PROPERTY_KEY, value.value ); Set<Object> propertyValues = asSet( Iterators.map( PROPERTY_EXTRACTOR, foundNodes ) ); results.put( value, propertyValues ); }
private static void addToResults( GraphDatabaseService db, HashMap<TestValue, Set<Object>> results, TestValue value ) { ResourceIterator<Node> foundNodes = db.findNodes( label( LABEL ), PROPERTY_KEY, value.value ); Set<Object> propertyValues = asSet( Iterators.map( PROPERTY_EXTRACTOR, foundNodes ) ); results.put( value, propertyValues ); }
private void lockNodeWithLabel( Label sharedLockLabel, CountDownLatch nodeLockLatch, CountDownLatch nodeReleaseLatch ) { GraphDatabaseService db = graphdb(); try ( Transaction ignored = db.beginTx() ) { Node node = db.findNodes( sharedLockLabel ).next(); node.setProperty( "a", "b" ); nodeLockLatch.countDown(); nodeReleaseLatch.await(); } catch ( InterruptedException e ) { throw new RuntimeException( e ); } }
private static void doStuff( GraphDatabaseService db, Label label, String propertyKey ) { try ( Transaction tx = db.beginTx() ) { for ( Node node : loop( db.findNodes( label, propertyKey, 3323 ) ) ) { count( node.getLabels() ); } } }
@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) ); }
private void deleteHumans() { try ( Transaction tx = db.beginTx() ) { try ( ResourceIterator<Node> humans = db.findNodes( HUMAN ) ) { while ( humans.hasNext() ) { humans.next().delete(); } } tx.success(); } }
@Test public void shouldSupportIndexSeek() { // GIVEN createNodes( db, LABEL, nonMatching ); LongSet expected = createNodes( db, LABEL, matching ); // WHEN MutableLongSet found = new LongHashSet(); try ( Transaction tx = db.beginTx() ) { collectNodes( found, db.findNodes( LABEL, KEY, template, searchMode ) ); } // THEN assertThat( found, equalTo( expected ) ); }
private void assertSingleCorrectHit( GraphDatabaseService db, PointValue point ) { ResourceIterator<Node> nodes = db.findNodes( TestLabels.LABEL_ONE, "prop", point ); assertTrue( nodes.hasNext() ); Node node = nodes.next(); Object prop = node.getProperty( "prop" ); assertEquals( point, prop ); assertFalse( nodes.hasNext() ); }
private void assertBothNodesArePresent( Pair<Long,Long> nodeIds ) { try ( Transaction tx = db.beginTx() ) { ResourceIterator<Node> origin = db.findNodes( LABEL, KEY, point1 ); assertTrue( origin.hasNext() ); assertEquals( nodeIds.first().longValue(), origin.next().getId() ); assertFalse( origin.hasNext() ); ResourceIterator<Node> center = db.findNodes( LABEL, KEY, point2 ); assertTrue( center.hasNext() ); assertEquals( nodeIds.other().longValue(), center.next().getId() ); assertFalse( center.hasNext() ); tx.success(); } }
private void doubleNumericPropertyValueForAllNodesWithLabel( Index<Node> index, String numericProperty, Label label ) { try ( Transaction transaction = graphDb.beginTx() ) { ResourceIterator<Node> nodes = graphDb.findNodes( label ); nodes.stream().forEach( node -> { node.setProperty( numericProperty, (Integer) node.getProperty( numericProperty ) * 2 ); index.remove( node, numericProperty ); index.add( node, numericProperty, new ValueContext( node.getProperty( numericProperty ) ).indexNumeric() ); } ); transaction.success(); } }
@Test public void shouldIncludeNodesCreatedInSameTxInIndexSeek() { // GIVEN createNodes( db, LABEL, nonMatching[0], nonMatching[1] ); MutableLongSet expected = createNodes( db, LABEL, matching[0], matching[1] ); // WHEN MutableLongSet found = new LongHashSet(); try ( Transaction tx = db.beginTx() ) { expected.add( createNode( db, map( KEY, matching[2] ), LABEL ).getId() ); createNode( db, map( KEY, nonMatching[2] ), LABEL ); collectNodes( found, db.findNodes( LABEL, KEY, template, searchMode ) ); } // THEN assertThat( found, equalTo( expected ) ); }
private static void assertDbAccessible( GraphDatabaseService db ) { Label label = () -> "Person"; String propertyKey = "name"; String propertyValue = "Thor Odinson"; try ( Transaction tx = db.beginTx() ) { db.createNode( label ).setProperty( propertyKey, propertyValue ); tx.success(); } try ( Transaction tx = db.beginTx() ) { Node node = single( db.findNodes( label ) ); assertEquals( propertyValue, node.getProperty( propertyKey ) ); tx.success(); } }