/** * Counts the number of items in the {@code iterator} by looping * through it. * @param <T> the type of items in the iterator. * @param iterable the {@link Iterable} to count items in. * @return the number of items found in {@code iterable}. */ public static <T> long count( Iterable<T> iterable ) { return count( iterable, Predicates.alwaysTrue() ); }
@Test void whenContextClassLoaderDuplicatesServiceShouldLoadItOnce() { Thread.currentThread().setContextClassLoader( Service.class.getClassLoader() ); Iterable<FooService> services = Service.load( FooService.class ); assertEquals( 1, Iterables.count( services ) ); }
@Test void mustBeAbleToRemoveAddedKernelExtensions() { DummyExtensionFactory extensionFactory = new DummyExtensionFactory(); GraphDatabaseFactoryState state = new GraphDatabaseFactoryState(); long initialCount = count( state.getKernelExtension() ); state.addKernelExtensions( Collections.singleton( extensionFactory ) ); assertThat( count( state.getKernelExtension() ), is( initialCount + 1 ) ); state.removeKernelExtensions( e -> e == extensionFactory ); assertThat( count( state.getKernelExtension() ), is( initialCount ) ); } }
private void loadNode( GraphDatabaseAPI db, Node node ) { try ( Transaction ignored = db.beginTx() ) { Iterables.count( node.getRelationships() ); } }
private Runnable getRelationships() { return () -> assertEquals( 1, Iterables.count( node.getRelationships() ) ); }
@SuppressWarnings( "boxing" ) @Override public Void beforeCommit( TransactionData data ) { if ( Iterables.count( data.createdRelationships() ) == 0 ) { return null; } node.setProperty( "counter", ((Long) node.removeProperty( "counter" )) + 1 ); return null; }
private long countIndexes() { try ( Transaction transaction = database.beginTx() ) { return Iterables.count( database.schema().getIndexes() ); } }
private long nodeCount() { Transaction transaction = db.beginTx(); long count = Iterables.count( db.getAllNodes() ); transaction.close(); return count; }
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() ); } } }
private long countNodes() { try ( Transaction transaction = graphdb().beginTx() ) { return Iterables.count( graphdb().getAllNodes() ); } } }
private void tryOnce( final GraphDatabaseAPI db, final Node node ) throws Throwable { Race race = new Race().withRandomStartDelays(); race.addContestants( Runtime.getRuntime().availableProcessors(), () -> { try ( Transaction ignored = db.beginTx() ) { assertEquals( relCount, count( node.getRelationships() ) ); } } ); race.go(); }
@Test public void eagerResultHaveNotifications() { Result result = database.execute( " CYPHER planner=rule MATCH (n) RETURN n.c" ); assertEquals( 1, testCursorContext.getAdditionalAttempts() ); assertThat( Iterables.count( result.getNotifications() ), greaterThan( 0L ) ); }
private void execute( TraversalDescription traversal, Uniqueness uniqueness ) { try ( Transaction transaction = beginTx() ) { Traverser traverser = traversal.uniqueness( uniqueness ).traverse( node( "1" ) ); assertNotEquals( "empty traversal", 0, Iterables.count( traverser ) ); } }
private void assertDegrees( Node node ) { for ( RelationshipType type : node.getRelationshipTypes() ) { for ( Direction direction : Direction.values() ) { long degree = node.getDegree( type, direction ); long actualDegree = count( node.getRelationships( type, direction ) ); assertEquals( actualDegree, degree ); } } }
public long getLabelCount( long nodeId ) { try ( Transaction transaction = database.getGraph().beginTransaction( implicit, AnonymousContext.read() ) ) { return count( database.getGraph().getNodeById( nodeId ).getLabels()); } } }
@Test public void createAndClearCacheBeforeCommit() { Node node = getGraphDb().createNode(); node.createRelationshipTo( getGraphDb().createNode(), TEST ); assertEquals( 1, Iterables.count( node.getRelationships() ) ); }
@Test public void maximumOfSevenInlinedLabels() { // GIVEN long[] labels = new long[] {0, 1, 2, 3, 4, 5, 6}; NodeRecord node = nodeRecordWithInlinedLabels( labels ); NodeLabels nodeLabels = NodeLabelsField.parseLabelsField( node ); // WHEN Iterable<DynamicRecord> changedDynamicRecords = nodeLabels.add( 23, nodeStore, nodeStore.getDynamicLabelStore() ); // THEN assertEquals( dynamicLabelsLongRepresentation( changedDynamicRecords ), node.getLabelField() ); assertEquals( 1, Iterables.count( changedDynamicRecords ) ); }
@Test public void testTraverseRelationshipsWithStartNodeNotIncluded() { try ( Transaction transaction = beginTx() ) { TraversalDescription traversal = getGraphDb().traversalDescription().evaluator( excludeStartPosition() ); assertEquals( 1, Iterables.count( traversal.traverse( node( "1" ) ).relationships() ) ); } } }
@Test public void shouldNotGetTheSameRelationshipMoreThanOnceWhenAskingForTheSameTypeMultipleTimes() { // given Node node = getGraphDb().createNode(); node.createRelationshipTo( getGraphDb().createNode(), withName( "FOO" ) ); // when long relationships = Iterables.count( node.getRelationships( withName( "FOO" ), withName( "FOO" ) ) ); // then assertEquals( 1, relationships ); }
@Test public void testNarrowingFilters() { Evaluator mustBeConnectedToK = new MustBeConnectedToNodeFilter( getNodeWithName( "k" ) ); Evaluator mustNotHaveMoreThanTwoOutRels = path -> Evaluation.ofIncludes( Iterables .count( path.endNode().getRelationships( Direction.OUTGOING ) ) <= 2 ); TraversalDescription description = getGraphDb().traversalDescription().evaluator( mustBeConnectedToK ); expectNodes( description.traverse( node( "a" ) ), "b", "c" ); expectNodes( description.evaluator( mustNotHaveMoreThanTwoOutRels ).traverse( node( "a" ) ), "c" ); }