Unnamed: 0
int64
0
6.7k
func
stringlengths
12
89.6k
target
bool
2 classes
project
stringlengths
45
151
3,600
{ @Override public Iterator<Relationship> iterator() { return new ReverseArrayIterator<Relationship>( path ); } };
false
community_graph-algo_src_main_java_org_neo4j_graphalgo_impl_util_PathImpl.java
3,601
{ @Override public Iterator<Relationship> iterator() { return new ArrayIterator<Relationship>( path ); } };
false
community_graph-algo_src_main_java_org_neo4j_graphalgo_impl_util_PathImpl.java
3,602
{ Node current = start; int index = 0; public boolean hasNext() { return index <= path.length; } public Node next() { if ( current == null ) { throw new NoSuchElementException(); } Node next = null; if ( index < path.length ) { next = path[index].getOtherNode( current ); } index += 1; try { return current; } finally { current = next; } } public void remove() { throw new UnsupportedOperationException(); } };
false
community_graph-algo_src_main_java_org_neo4j_graphalgo_impl_util_PathImpl.java
3,603
{ public Iterator<Node> iterator() { return new Iterator<Node>() { Node current = start; int index = 0; public boolean hasNext() { return index <= path.length; } public Node next() { if ( current == null ) { throw new NoSuchElementException(); } Node next = null; if ( index < path.length ) { next = path[index].getOtherNode( current ); } index += 1; try { return current; } finally { current = next; } } public void remove() { throw new UnsupportedOperationException(); } }; } };
false
community_graph-algo_src_main_java_org_neo4j_graphalgo_impl_util_PathImpl.java
3,604
public final class PathImpl implements Path { public static final class Builder { private final Builder previous; private final Node start; private final Relationship relationship; private final int size; public Builder( Node start ) { if ( start == null ) { throw new NullPointerException(); } this.start = start; this.previous = null; this.relationship = null; this.size = 0; } private Builder( Builder prev, Relationship rel ) { this.start = prev.start; this.previous = prev; this.relationship = rel; this.size = prev.size + 1; } public Node getStartNode() { return start; } public Path build() { return new PathImpl( this, null ); } public Builder push( Relationship relationship ) { if ( relationship == null ) { throw new NullPointerException(); } return new Builder( this, relationship ); } public Path build( Builder other ) { return new PathImpl( this, other ); } @Override public String toString() { if ( previous == null ) { return start.toString(); } else { return relToString( relationship ) + ":" + previous.toString(); } } } private static String relToString( Relationship rel ) { return rel.getStartNode() + "--" + rel.getType() + "-->" + rel.getEndNode(); } private final Node start; private final Relationship[] path; private final Node end; private PathImpl( Builder left, Builder right ) { Node endNode = null; path = new Relationship[left.size + ( right == null ? 0 : right.size )]; if ( right != null ) { for ( int i = left.size, total = i + right.size; i < total; i++ ) { path[i] = right.relationship; right = right.previous; } assert right.relationship == null : "right Path.Builder size error"; endNode = right.start; } for ( int i = left.size - 1; i >= 0; i-- ) { path[i] = left.relationship; left = left.previous; } assert left.relationship == null : "left Path.Builder size error"; start = left.start; end = endNode; } public static Path singular( Node start ) { return new Builder( start ).build(); } public Node startNode() { return start; } public Node endNode() { if ( end != null ) { return end; } // TODO We could really figure this out in the constructor Node stepNode = null; for ( Node node : nodes() ) { stepNode = node; } return stepNode; } public Relationship lastRelationship() { return path != null && path.length > 0 ? path[path.length - 1] : null; } public Iterable<Node> nodes() { return nodeIterator( start ); } @Override public Iterable<Node> reverseNodes() { return nodeIterator( end ); } private Iterable<Node> nodeIterator( final Node start ) { return new Iterable<Node>() { public Iterator<Node> iterator() { return new Iterator<Node>() { Node current = start; int index = 0; public boolean hasNext() { return index <= path.length; } public Node next() { if ( current == null ) { throw new NoSuchElementException(); } Node next = null; if ( index < path.length ) { next = path[index].getOtherNode( current ); } index += 1; try { return current; } finally { current = next; } } public void remove() { throw new UnsupportedOperationException(); } }; } }; } public Iterable<Relationship> relationships() { return new Iterable<Relationship>() { @Override public Iterator<Relationship> iterator() { return new ArrayIterator<Relationship>( path ); } }; } @Override public Iterable<Relationship> reverseRelationships() { return new Iterable<Relationship>() { @Override public Iterator<Relationship> iterator() { return new ReverseArrayIterator<Relationship>( path ); } }; } public Iterator<PropertyContainer> iterator() { return new Iterator<PropertyContainer>() { Iterator<? extends PropertyContainer> current = nodes().iterator(); Iterator<? extends PropertyContainer> next = relationships().iterator(); public boolean hasNext() { return current.hasNext(); } public PropertyContainer next() { try { return current.next(); } finally { Iterator<? extends PropertyContainer> temp = current; current = next; next = temp; } } public void remove() { next.remove(); } }; } public int length() { return path.length; } @Override public int hashCode() { if ( path.length == 0 ) { return start.hashCode(); } else { return Arrays.hashCode( path ); } } @Override public boolean equals( Object obj ) { if ( this == obj ) { return true; } else if ( obj instanceof Path ) { Path other = (Path) obj; if ( !start.equals( other.startNode() ) ) { return false; } return iteratorsEqual( this.relationships().iterator(), other.relationships().iterator() ); } else { return false; } } @Override public String toString() { return Traversal.defaultPathToString( this ); } }
false
community_graph-algo_src_main_java_org_neo4j_graphalgo_impl_util_PathImpl.java
3,605
public static class DoubleVector { Map<Integer,Double> values = new HashMap<Integer,Double>(); /** * Increment a value in the vector. * @param index * @param increment */ public void incrementValue( Integer index, double increment ) { Double currentValue = values.get( index ); if ( currentValue == null ) { currentValue = 0.0; } currentValue += increment; values.put( index, currentValue ); } /** * Set a value for a certain index. * @param index * @param value */ public void set( Integer index, double value ) { values.put( index, value ); } /** * Get a value for a certain index. * @param index * @return The value or null. */ public Double get( Integer index ) { return values.get( index ); } /** * Get all indices for which values are stored. * @return The indices as a set. */ public Set<Integer> getIndices() { return values.keySet(); } @Override public String toString() { String res = ""; int maxIndex = 0; for ( Integer i : values.keySet() ) { if ( i > maxIndex ) { maxIndex = i; } } for ( int i = 0; i <= maxIndex; ++i ) { Double value = values.get( i ); if ( value == null ) { value = 0.0; } res += " " + value; } return res + "\n"; } }
false
community_graph-algo_src_main_java_org_neo4j_graphalgo_impl_util_MatrixUtil.java
3,606
public static class DoubleMatrix { Map<Integer,DoubleVector> rows = new HashMap<Integer,DoubleVector>(); /** * Increment a value at a certain position. * @param rowIndex * @param columnIndex * @param increment */ public void incrementValue( Integer rowIndex, Integer columnIndex, double increment ) { DoubleVector row = rows.get( rowIndex ); if ( row == null ) { row = new DoubleVector(); rows.put( rowIndex, row ); } row.incrementValue( columnIndex, increment ); } /** * Set a value at a certain position. * @param rowIndex * @param columnIndex * @param value */ public void set( Integer rowIndex, Integer columnIndex, double value ) { DoubleVector row = rows.get( rowIndex ); if ( row == null ) { row = new DoubleVector(); rows.put( rowIndex, row ); } row.set( columnIndex, value ); } /** * Get the value at a certain position. * @param rowIndex * @param columnIndex * @return The value or null. */ public Double get( Integer rowIndex, Integer columnIndex ) { DoubleVector row = rows.get( rowIndex ); if ( row == null ) { return null; } return row.get( columnIndex ); } /** * Gets an entire row as a vector. * @param rowIndex * @return The row vector or null. */ public DoubleVector getRow( Integer rowIndex ) { return rows.get( rowIndex ); } /** * Inserts or replaces an entire row as a vector. * @param rowIndex * @param row */ public void setRow( Integer rowIndex, DoubleVector row ) { rows.put( rowIndex, row ); } @Override public String toString() { String res = ""; for ( Integer i : rows.keySet() ) { res += rows.get( i ).toString(); } return res; } /** * @return The number of rows in the matrix. */ public int size() { return rows.keySet().size(); } }
false
community_graph-algo_src_main_java_org_neo4j_graphalgo_impl_util_MatrixUtil.java
3,607
public class MatrixUtil { /** * Vector of doubles */ public static class DoubleVector { Map<Integer,Double> values = new HashMap<Integer,Double>(); /** * Increment a value in the vector. * @param index * @param increment */ public void incrementValue( Integer index, double increment ) { Double currentValue = values.get( index ); if ( currentValue == null ) { currentValue = 0.0; } currentValue += increment; values.put( index, currentValue ); } /** * Set a value for a certain index. * @param index * @param value */ public void set( Integer index, double value ) { values.put( index, value ); } /** * Get a value for a certain index. * @param index * @return The value or null. */ public Double get( Integer index ) { return values.get( index ); } /** * Get all indices for which values are stored. * @return The indices as a set. */ public Set<Integer> getIndices() { return values.keySet(); } @Override public String toString() { String res = ""; int maxIndex = 0; for ( Integer i : values.keySet() ) { if ( i > maxIndex ) { maxIndex = i; } } for ( int i = 0; i <= maxIndex; ++i ) { Double value = values.get( i ); if ( value == null ) { value = 0.0; } res += " " + value; } return res + "\n"; } } /** * 2-Dimensional matrix of doubles. */ public static class DoubleMatrix { Map<Integer,DoubleVector> rows = new HashMap<Integer,DoubleVector>(); /** * Increment a value at a certain position. * @param rowIndex * @param columnIndex * @param increment */ public void incrementValue( Integer rowIndex, Integer columnIndex, double increment ) { DoubleVector row = rows.get( rowIndex ); if ( row == null ) { row = new DoubleVector(); rows.put( rowIndex, row ); } row.incrementValue( columnIndex, increment ); } /** * Set a value at a certain position. * @param rowIndex * @param columnIndex * @param value */ public void set( Integer rowIndex, Integer columnIndex, double value ) { DoubleVector row = rows.get( rowIndex ); if ( row == null ) { row = new DoubleVector(); rows.put( rowIndex, row ); } row.set( columnIndex, value ); } /** * Get the value at a certain position. * @param rowIndex * @param columnIndex * @return The value or null. */ public Double get( Integer rowIndex, Integer columnIndex ) { DoubleVector row = rows.get( rowIndex ); if ( row == null ) { return null; } return row.get( columnIndex ); } /** * Gets an entire row as a vector. * @param rowIndex * @return The row vector or null. */ public DoubleVector getRow( Integer rowIndex ) { return rows.get( rowIndex ); } /** * Inserts or replaces an entire row as a vector. * @param rowIndex * @param row */ public void setRow( Integer rowIndex, DoubleVector row ) { rows.put( rowIndex, row ); } @Override public String toString() { String res = ""; for ( Integer i : rows.keySet() ) { res += rows.get( i ).toString(); } return res; } /** * @return The number of rows in the matrix. */ public int size() { return rows.keySet().size(); } } /** * Destructive (in-place) LU-decomposition * @param matrix * input */ // TODO: extend to LUP? public static void LUDecomposition( DoubleMatrix matrix ) { int matrixSize = matrix.size(); for ( int i = 0; i < matrixSize - 1; ++i ) { double pivot = matrix.get( i, i ); DoubleVector row = matrix.getRow( i ); for ( int r = i + 1; r < matrixSize; ++r ) { Double rowStartValue = matrix.get( r, i ); if ( rowStartValue == null || rowStartValue == 0.0 ) { continue; } double factor = rowStartValue / pivot; matrix.set( r, i, factor ); for ( Integer c : row.values.keySet() ) { if ( c <= i ) { continue; } matrix.incrementValue( r, c, -row.get( c ) * factor ); } } } } /** * Solves the linear equation system ax = b. * @param a * Input matrix. Will be altered in-place. * @param b * Input vector. Will be altered in-place. * @return the vector x solving the equations. */ public static DoubleVector LinearSolve( DoubleMatrix a, DoubleVector b ) { LUDecomposition( a ); // first solve Ly = b ... for ( int r = 0; r < a.size(); ++r ) { DoubleVector row = a.getRow( r ); for ( Integer c : row.values.keySet() ) { if ( c >= r ) { continue; } b.incrementValue( r, -row.get( c ) * b.get( c ) ); } } // ... then Ux = y for ( int r = a.size() - 1; r >= 0; --r ) { DoubleVector row = a.getRow( r ); for ( Integer c : row.values.keySet() ) { if ( c <= r ) { continue; } b.incrementValue( r, -row.get( c ) * b.get( c ) ); } b.set( r, b.get( r ) / row.get( r ) ); } return b; } /** * Multiplies a matrix and a vector. * @param matrix * @param vector * @return The result as a new vector. */ public static DoubleVector multiply( DoubleMatrix matrix, DoubleVector vector ) { DoubleVector result = new DoubleVector(); for ( int rowIndex = 0; rowIndex < matrix.size(); ++rowIndex ) { DoubleVector row = matrix.getRow( rowIndex ); for ( Integer index : row.getIndices() ) { result.incrementValue( rowIndex, row.get( index ) * vector.get( index ) ); } } return result; } /** * In-place normalization of a vector. * @param vector * @return The initial euclidean length of the vector. */ public static double normalize( DoubleVector vector ) { double len = 0; for ( Integer index : vector.getIndices() ) { Double d = vector.get( index ); len += d * d; } len = Math.sqrt( len ); for ( Integer index : vector.getIndices() ) { vector.set( index, vector.get( index ) / len ); } return len; } }
false
community_graph-algo_src_main_java_org_neo4j_graphalgo_impl_util_MatrixUtil.java
3,608
public class LiteDepthFirstSelector implements BranchSelector { private final Queue<TraversalBranch> superNodes = new LinkedList<TraversalBranch>(); private TraversalBranch current; private final int threshold; private final PathExpander expander; public LiteDepthFirstSelector( TraversalBranch startSource, int startThreshold, PathExpander expander ) { this.current = startSource; this.threshold = startThreshold; this.expander = expander; } public LiteDepthFirstSelector( TraversalBranch startSource, int startThreshold, RelationshipExpander expander ) { this( startSource, startThreshold, toPathExpander( expander ) ); } public TraversalBranch next( TraversalContext metadata ) { TraversalBranch result = null; while ( result == null ) { if ( current == null ) { current = superNodes.poll(); if ( current == null ) { return null; } } else if ( current.expanded() > 0 && current.expanded() % threshold == 0 ) { superNodes.add( current ); current = current.parent(); continue; } TraversalBranch next = current.next( expander, metadata ); if ( next == null ) { current = current.parent(); continue; } else { current = next; } if ( current != null ) { result = current; } } return result; } }
false
community_graph-algo_src_main_java_org_neo4j_graphalgo_impl_util_LiteDepthFirstSelector.java
3,609
public class IntegerEvaluator implements CostEvaluator<Integer> { private String costpropertyName; public IntegerEvaluator( String costpropertyName ) { super(); this.costpropertyName = costpropertyName; } public Integer getCost( Relationship relationship, Direction direction ) { return (Integer) relationship.getProperty( costpropertyName ); } }
false
community_graph-algo_src_main_java_org_neo4j_graphalgo_impl_util_IntegerEvaluator.java
3,610
public class IntegerComparator implements Comparator<Integer> { public int compare(Integer o1, Integer o2) { return o1 - o2; } }
false
community_graph-algo_src_main_java_org_neo4j_graphalgo_impl_util_IntegerComparator.java
3,611
public class DijkstraDirectionTest extends Neo4jAlgoTestCase { @Test public void testDijkstraDirection1() { graph.makeEdge( "s", "e" ); Dijkstra<Double> dijkstra = new Dijkstra<Double>( (double) 0, graph.getNode( "s" ), graph.getNode( "e" ), new CostEvaluator<Double>() { public Double getCost( Relationship relationship, Direction direction ) { assertEquals( Direction.OUTGOING, direction ); return 1.0; } }, new org.neo4j.graphalgo.impl.util.DoubleAdder(), new org.neo4j.graphalgo.impl.util.DoubleComparator(), Direction.OUTGOING, MyRelTypes.R1 ); dijkstra.getCost(); dijkstra = new Dijkstra<Double>( (double) 0, graph.getNode( "s" ), graph.getNode( "e" ), new CostEvaluator<Double>() { public Double getCost( Relationship relationship, Direction direction ) { assertEquals( Direction.INCOMING, direction ); return 1.0; } }, new org.neo4j.graphalgo.impl.util.DoubleAdder(), new org.neo4j.graphalgo.impl.util.DoubleComparator(), Direction.INCOMING, MyRelTypes.R1 ); dijkstra.getCost(); } @Test public void testDijkstraDirection2() { graph.makeEdge( "a", "b" ); graph.makeEdge( "b", "c" ); graph.makeEdge( "c", "d" ); graph.makeEdge( "d", "a" ); graph.makeEdge( "s", "a" ); graph.makeEdge( "b", "s" ); graph.makeEdge( "e", "c" ); graph.makeEdge( "d", "e" ); Dijkstra<Double> dijkstra = new Dijkstra<Double>( (double) 0, graph.getNode( "s" ), graph.getNode( "e" ), new CostEvaluator<Double>() { public Double getCost( Relationship relationship, Direction direction ) { assertEquals( Direction.OUTGOING, direction ); return 1.0; } }, new org.neo4j.graphalgo.impl.util.DoubleAdder(), new org.neo4j.graphalgo.impl.util.DoubleComparator(), Direction.OUTGOING, MyRelTypes.R1 ); dijkstra.getCost(); dijkstra = new Dijkstra<Double>( (double) 0, graph.getNode( "s" ), graph.getNode( "e" ), new CostEvaluator<Double>() { public Double getCost( Relationship relationship, Direction direction ) { assertEquals( Direction.INCOMING, direction ); return 1.0; } }, new org.neo4j.graphalgo.impl.util.DoubleAdder(), new org.neo4j.graphalgo.impl.util.DoubleComparator(), Direction.INCOMING, MyRelTypes.R1 ); dijkstra.getCost(); } // This saves the first direction observed class directionSavingCostEvaluator implements CostEvaluator<Double> { HashMap<Relationship, Direction> dirs; public directionSavingCostEvaluator( HashMap<Relationship, Direction> dirs ) { super(); this.dirs = dirs; } public Double getCost( Relationship relationship, Direction direction ) { if ( !dirs.containsKey( relationship ) ) { dirs.put( relationship, direction ); } return 1.0; } } @Test public void testDijkstraDirection3() { Relationship r1 = graph.makeEdge( "start", "b" ); Relationship r2 = graph.makeEdge( "c", "b" ); Relationship r3 = graph.makeEdge( "c", "d" ); Relationship r4 = graph.makeEdge( "e", "d" ); Relationship r5 = graph.makeEdge( "e", "f" ); Relationship r6 = graph.makeEdge( "g", "f" ); Relationship r7 = graph.makeEdge( "g", "end" ); HashMap<Relationship, Direction> dirs = new HashMap<Relationship, Direction>(); Dijkstra<Double> dijkstra = new Dijkstra<Double>( (double) 0, graph .getNode( "start" ), graph.getNode( "end" ), new directionSavingCostEvaluator( dirs ), new org.neo4j.graphalgo.impl.util.DoubleAdder(), new org.neo4j.graphalgo.impl.util.DoubleComparator(), Direction.BOTH, MyRelTypes.R1 ); dijkstra.getCost(); assertEquals( Direction.OUTGOING, dirs.get( r1 ) ); assertEquals( Direction.INCOMING, dirs.get( r2 ) ); assertEquals( Direction.OUTGOING, dirs.get( r3 ) ); assertEquals( Direction.INCOMING, dirs.get( r4 ) ); assertEquals( Direction.OUTGOING, dirs.get( r5 ) ); assertEquals( Direction.INCOMING, dirs.get( r6 ) ); assertEquals( Direction.OUTGOING, dirs.get( r7 ) ); } }
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_DijkstraDirectionTest.java
3,612
{ public Double getCost( Relationship relationship, Direction direction ) { assertEquals( Direction.OUTGOING, direction ); return 1.0; } }, new org.neo4j.graphalgo.impl.util.DoubleAdder(),
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_DijkstraDirectionTest.java
3,613
{ public Double getCost( Relationship relationship, Direction direction ) { assertEquals( Direction.INCOMING, direction ); return 1.0; } }, new org.neo4j.graphalgo.impl.util.DoubleAdder(),
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_DijkstraDirectionTest.java
3,614
{ @Override public void call( IndexManager indexManager ) { indexManager.existsForNodes( "foo" ); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_IndexManagerFacadeMethods.java
3,615
{ @Override public void call( IndexDefinition self ) { self.isConstraintIndex(); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_IndexDefinitionFacadeMethods.java
3,616
{ @Override public void call( IndexDefinition self ) { self.drop(); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_IndexDefinitionFacadeMethods.java
3,617
{ @Override public void call( IndexDefinition self ) { self.getPropertyKeys(); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_IndexDefinitionFacadeMethods.java
3,618
{ @Override public void call( IndexDefinition self ) { self.getLabel(); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_IndexDefinitionFacadeMethods.java
3,619
public class IndexDefinitionFacadeMethods { private static final FacadeMethod<IndexDefinition> GET_LABEL = new FacadeMethod<IndexDefinition>( "Label getLabel()" ) { @Override public void call( IndexDefinition self ) { self.getLabel(); } }; private static final FacadeMethod<IndexDefinition> GET_PROPERTY_KEYS = new FacadeMethod<IndexDefinition>( "Iterable<String> getPropertyKeys()" ) { @Override public void call( IndexDefinition self ) { self.getPropertyKeys(); } }; private static final FacadeMethod<IndexDefinition> DROP = new FacadeMethod<IndexDefinition>( "void drop()" ) { @Override public void call( IndexDefinition self ) { self.drop(); } }; private static final FacadeMethod<IndexDefinition> IS_CONSTRAINT_INDEX = new FacadeMethod<IndexDefinition>( "boolean isConstraintIndex()" ) { @Override public void call( IndexDefinition self ) { self.isConstraintIndex(); } }; static final Iterable<FacadeMethod<IndexDefinition>> ALL_INDEX_DEFINITION_FACADE_METHODS = unmodifiableCollection( asList( GET_LABEL, GET_PROPERTY_KEYS, DROP, IS_CONSTRAINT_INDEX ) ); }
false
community_kernel_src_test_java_org_neo4j_graphdb_IndexDefinitionFacadeMethods.java
3,620
{ @Override public void call( IndexCreator self ) { self.on( "property" ); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_IndexCreatorFacadeMethods.java
3,621
{ @Override public void call( IndexCreator self ) { self.on( "property" ); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_IndexCreatorFacadeMethods.java
3,622
public class IndexCreatorFacadeMethods { private static final FacadeMethod<IndexCreator> ON = new FacadeMethod<IndexCreator>( "IndexCreator on( String propertyKey )" ) { @Override public void call( IndexCreator self ) { self.on( "property" ); } }; private static final FacadeMethod<IndexCreator> CREATE = new FacadeMethod<IndexCreator>( "IndexDefinition create()" ) { @Override public void call( IndexCreator self ) { self.on( "property" ); } }; static final Iterable<FacadeMethod<IndexCreator>> ALL_INDEX_CREATOR_FACADE_METHODS = unmodifiableCollection( asList( ON, CREATE ) ); }
false
community_kernel_src_test_java_org_neo4j_graphdb_IndexCreatorFacadeMethods.java
3,623
{ @Override public void run() { try { db.beginTx(); result.set( Boolean.TRUE ); } catch ( Exception e ) { result.set( e ); } synchronized ( result ) { result.notifyAll(); } } });
false
community_kernel_src_test_java_org_neo4j_graphdb_GraphDatabaseServiceTest.java
3,624
{ @Override public void run() { try(Transaction tx = db.beginTx()) { shutdown.countDown(); try { Thread.sleep( 2000 ); } catch ( InterruptedException e ) { throw new RuntimeException( e ); } db.createNode(); tx.success(); Executors.newSingleThreadExecutor().submit( new Runnable() { @Override public void run() { try { db.beginTx(); result.set( Boolean.TRUE ); } catch ( Exception e ) { result.set( e ); } synchronized ( result ) { result.notifyAll(); } } }); } catch(Throwable e) { e.printStackTrace(); } } });
false
community_kernel_src_test_java_org_neo4j_graphdb_GraphDatabaseServiceTest.java
3,625
{ @Override public void run() { try(Transaction tx = db.beginTx()) { started.countDown(); try { Thread.sleep( 2000 ); } catch ( InterruptedException e ) { throw new RuntimeException( e ); } db.createNode(); tx.success(); } catch(Throwable e) { e.printStackTrace(); } } });
false
community_kernel_src_test_java_org_neo4j_graphdb_GraphDatabaseServiceTest.java
3,626
@Ignore("JH: Working on this, part of the 1.9 merge for tuesday 12th") public class GraphDatabaseServiceTest { @Test public void givenShutdownDatabaseWhenBeginTxThenExceptionIsThrown() throws Exception { // Given GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase(); db.shutdown(); // When try { Transaction tx = db.beginTx(); Assert.fail(); } catch ( Exception e ) { // Then Assert.assertThat( e.getClass().getName(), CoreMatchers.equalTo( TransactionFailureException.class .getName() ) ); } } @Test public void givenDatabaseAndStartedTxWhenShutdownThenWaitForTxToFinish() throws Exception { // Given final GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase(); // When final CountDownLatch started = new CountDownLatch( 1 ); Executors.newSingleThreadExecutor().submit( new Runnable() { @Override public void run() { try(Transaction tx = db.beginTx()) { started.countDown(); try { Thread.sleep( 2000 ); } catch ( InterruptedException e ) { throw new RuntimeException( e ); } db.createNode(); tx.success(); } catch(Throwable e) { e.printStackTrace(); } } }); started.await(); db.shutdown(); } @Test public void givenDatabaseAndStartedTxWhenShutdownAndStartNewTxThenBeginTxTimesOut() throws Exception { // Given final GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase(); // When final CountDownLatch shutdown = new CountDownLatch( 1 ); final AtomicReference result = new AtomicReference(); Executors.newSingleThreadExecutor().submit( new Runnable() { @Override public void run() { try(Transaction tx = db.beginTx()) { shutdown.countDown(); try { Thread.sleep( 2000 ); } catch ( InterruptedException e ) { throw new RuntimeException( e ); } db.createNode(); tx.success(); Executors.newSingleThreadExecutor().submit( new Runnable() { @Override public void run() { try { db.beginTx(); result.set( Boolean.TRUE ); } catch ( Exception e ) { result.set( e ); } synchronized ( result ) { result.notifyAll(); } } }); } catch(Throwable e) { e.printStackTrace(); } } }); shutdown.await(); db.shutdown(); while ( result.get() == null ) { synchronized ( result ) { result.wait( 100 ); } } Assert.assertThat( result.get().getClass(), CoreMatchers.<Object>equalTo( TransactionFailureException.class ) ); } }
false
community_kernel_src_test_java_org_neo4j_graphdb_GraphDatabaseServiceTest.java
3,627
{ @Override public void call( GraphDatabaseService graphDatabaseService ) { graphDatabaseService.schema(); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_GraphDatabaseServiceFacadeMethods.java
3,628
{ @Override public void call( GraphDatabaseService graphDatabaseService ) { graphDatabaseService.getRelationshipTypes(); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_GraphDatabaseServiceFacadeMethods.java
3,629
{ @Override public void call( GraphDatabaseService graphDatabaseService ) { for ( Node node : graphDatabaseService.findNodesByLabelAndProperty( label( "bar" ), "baz", 23 ) ) { } } };
false
community_kernel_src_test_java_org_neo4j_graphdb_GraphDatabaseServiceFacadeMethods.java
3,630
{ @Override public void call( GraphDatabaseService graphDatabaseService ) { for ( Node node : graphDatabaseService.getAllNodes() ) { } } };
false
community_kernel_src_test_java_org_neo4j_graphdb_GraphDatabaseServiceFacadeMethods.java
3,631
{ @Override public void call( GraphDatabaseService graphDatabaseService ) { graphDatabaseService.getRelationshipById( 87 ); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_GraphDatabaseServiceFacadeMethods.java
3,632
{ @Override public void call( GraphDatabaseService graphDatabaseService ) { graphDatabaseService.getNodeById( 42 ); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_GraphDatabaseServiceFacadeMethods.java
3,633
{ @Override public void call( GraphDatabaseService graphDatabaseService ) { graphDatabaseService.createNode( label( "FOO" ) ); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_GraphDatabaseServiceFacadeMethods.java
3,634
public class IndexManagerFacadeMethods { private static final FacadeMethod<IndexManager> EXISTS_FOR_NODES = new FacadeMethod<IndexManager>( "boolean " + "existsForNodes( String indexName )" ) { @Override public void call( IndexManager indexManager ) { indexManager.existsForNodes( "foo" ); } }; private static final FacadeMethod<IndexManager> FOR_NODES = new FacadeMethod<IndexManager>( "Index<Node> forNodes" + "( String indexName )" ) { @Override public void call( IndexManager indexManager ) { indexManager.forNodes( "foo" ); } }; private static final FacadeMethod<IndexManager> FOR_NODES_WITH_CONFIGURATION = new FacadeMethod<IndexManager>( "Index<Node> forNodes( String indexName, Map<String, String> customConfiguration )" ) { @Override public void call( IndexManager indexManager ) { indexManager.forNodes( "foo", null ); } }; private static final FacadeMethod<IndexManager> NODE_INDEX_NAMES = new FacadeMethod<IndexManager>( "String[] " + "nodeIndexNames()" ) { @Override public void call( IndexManager indexManager ) { for ( String indexName : indexManager.nodeIndexNames() ) { } } }; private static final FacadeMethod<IndexManager> EXISTS_FOR_RELATIONSHIPS = new FacadeMethod<IndexManager>( "boolean existsForRelationships( String indexName )" ) { @Override public void call( IndexManager indexManager ) { indexManager.existsForRelationships( "foo" ); } }; private static final FacadeMethod<IndexManager> FOR_RELATIONSHIPS = new FacadeMethod<IndexManager>( "RelationshipIndex forRelationships( String indexName )" ) { @Override public void call( IndexManager indexManager ) { indexManager.forRelationships( "foo" ); } }; private static final FacadeMethod<IndexManager> FOR_RELATIONSHIPS_WITH_CONFIGURATION = new FacadeMethod<IndexManager> ( "RelationshipIndex forRelationships( String indexName, Map<String, String> customConfiguration )" ) { @Override public void call( IndexManager indexManager ) { indexManager.forRelationships( "foo", null ); } }; private static final FacadeMethod<IndexManager> RELATIONSHIP_INDEX_NAMES = new FacadeMethod<IndexManager>( "String[] relationshipIndexNames()" ) { @Override public void call( IndexManager indexManager ) { for ( String indexName : indexManager.relationshipIndexNames() ) { } } }; static final Iterable<FacadeMethod<IndexManager>> ALL_INDEX_MANAGER_FACADE_METHODS = unmodifiableCollection( asList( EXISTS_FOR_NODES, FOR_NODES, FOR_NODES_WITH_CONFIGURATION, NODE_INDEX_NAMES, EXISTS_FOR_RELATIONSHIPS, FOR_RELATIONSHIPS, FOR_RELATIONSHIPS_WITH_CONFIGURATION, RELATIONSHIP_INDEX_NAMES ) ); }
false
community_kernel_src_test_java_org_neo4j_graphdb_IndexManagerFacadeMethods.java
3,635
{ @Override public void call( IndexManager indexManager ) { indexManager.forNodes( "foo" ); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_IndexManagerFacadeMethods.java
3,636
{ public Double getCost( Relationship relationship, Direction direction ) { assertEquals( Direction.OUTGOING, direction ); return 1.0; } }, new org.neo4j.graphalgo.impl.util.DoubleAdder(),
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_DijkstraDirectionTest.java
3,637
{ @Override public void call( IndexManager indexManager ) { indexManager.forNodes( "foo", null ); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_IndexManagerFacadeMethods.java
3,638
{ @Override public long nextId() { // Same exception as the one thrown by IdGeneratorImpl throw new UnderlyingStorageException( "Id capacity exceeded" ); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_LabelsAcceptanceTest.java
3,639
{ @Override public IdGenerator open( FileSystemAbstraction fs, File fileName, int grabSize, IdType idType, long highId ) { switch ( idType ) { case LABEL_TOKEN: return new EphemeralIdGenerator( idType ) { @Override public long nextId() { // Same exception as the one thrown by IdGeneratorImpl throw new UnderlyingStorageException( "Id capacity exceeded" ); } }; default: return super.open( fs, fileName, grabSize, idType, Long.MAX_VALUE ); } } };
false
community_kernel_src_test_java_org_neo4j_graphdb_LabelsAcceptanceTest.java
3,640
{ @Override protected IdGeneratorFactory createIdGeneratorFactory() { return new EphemeralIdGenerator.Factory() { @Override public IdGenerator open( FileSystemAbstraction fs, File fileName, int grabSize, IdType idType, long highId ) { switch ( idType ) { case LABEL_TOKEN: return new EphemeralIdGenerator( idType ) { @Override public long nextId() { // Same exception as the one thrown by IdGeneratorImpl throw new UnderlyingStorageException( "Id capacity exceeded" ); } }; default: return super.open( fs, fileName, grabSize, idType, Long.MAX_VALUE ); } } }; } };
false
community_kernel_src_test_java_org_neo4j_graphdb_LabelsAcceptanceTest.java
3,641
{ @Override public String apply( Label label ) { return label.name(); } }, labels ), hasItems( Labels.MY_LABEL.name(), Labels.MY_OTHER_LABEL.name() ) );
false
community_kernel_src_test_java_org_neo4j_graphdb_LabelsAcceptanceTest.java
3,642
{ @Override public List<Label> apply( GraphDatabaseService db ) { List<Label> labels = new ArrayList<>(); for ( Label label : node.getLabels() ) { labels.add( label ); } return labels; } } );
false
community_kernel_src_test_java_org_neo4j_graphdb_LabelsAcceptanceTest.java
3,643
{ @Override public Void apply( GraphDatabaseService db ) { for ( Label label : node.getLabels() ) { node.removeLabel( label ); } node.addLabel( label( "BAZQUX" ) ); return null; } } );
false
community_kernel_src_test_java_org_neo4j_graphdb_LabelsAcceptanceTest.java
3,644
{ @Override public Void apply( GraphDatabaseService db ) { node.addLabel( label( "BAZQUX" ) ); return null; } } );
false
community_kernel_src_test_java_org_neo4j_graphdb_LabelsAcceptanceTest.java
3,645
{ @Override public Void apply( GraphDatabaseService db ) { node.addLabel( label( "FOOBAR" ) ); return null; } } );
false
community_kernel_src_test_java_org_neo4j_graphdb_LabelsAcceptanceTest.java
3,646
{ @Override public Node apply( GraphDatabaseService db ) { return db.createNode(); } } );
false
community_kernel_src_test_java_org_neo4j_graphdb_LabelsAcceptanceTest.java
3,647
public class LabelsAcceptanceTest { public @Rule ImpermanentDatabaseRule dbRule = new ImpermanentDatabaseRule(); private enum Labels implements Label { MY_LABEL, MY_OTHER_LABEL } /** https://github.com/neo4j/neo4j/issues/1279 */ @Test public void shouldInsertLabelsWithoutDuplicatingThem() throws Exception { final Node node = dbRule.executeAndCommit( new Function<GraphDatabaseService, Node>() { @Override public Node apply( GraphDatabaseService db ) { return db.createNode(); } } ); // POST "FOOBAR" dbRule.executeAndCommit( new Function<GraphDatabaseService, Void>() { @Override public Void apply( GraphDatabaseService db ) { node.addLabel( label( "FOOBAR" ) ); return null; } } ); // POST ["BAZQUX"] dbRule.executeAndCommit( new Function<GraphDatabaseService, Void>() { @Override public Void apply( GraphDatabaseService db ) { node.addLabel( label( "BAZQUX" ) ); return null; } } ); // PUT ["BAZQUX"] dbRule.executeAndCommit( new Function<GraphDatabaseService, Void>() { @Override public Void apply( GraphDatabaseService db ) { for ( Label label : node.getLabels() ) { node.removeLabel( label ); } node.addLabel( label( "BAZQUX" ) ); return null; } } ); // GET List<Label> labels = dbRule.executeAndCommit( new Function<GraphDatabaseService, List<Label>>() { @Override public List<Label> apply( GraphDatabaseService db ) { List<Label> labels = new ArrayList<>(); for ( Label label : node.getLabels() ) { labels.add( label ); } return labels; } } ); assertEquals( labels.toString(), 1, labels.size() ); assertEquals( "BAZQUX", labels.get( 0 ).name() ); } @Test public void addingALabelUsingAValidIdentifierShouldSucceed() throws Exception { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); Node myNode = null; // When Transaction tx = beansAPI.beginTx(); try { myNode = beansAPI.createNode(); myNode.addLabel( Labels.MY_LABEL ); tx.success(); } finally { tx.finish(); } // Then assertThat( "Label should have been added to node", myNode, inTx( beansAPI, hasLabel( Labels.MY_LABEL ) ) ); } @Test public void addingALabelUsingAnInvalidIdentifierShouldFail() throws Exception { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); // When I set an empty label Transaction tx = beansAPI.beginTx(); try { beansAPI.createNode().addLabel( label( "" ) ); fail( "Should have thrown exception" ); } catch ( ConstraintViolationException ex ) { // Happy } finally { tx.finish(); } // And When I set a null label Transaction tx2 = beansAPI.beginTx(); try { beansAPI.createNode().addLabel( label( null ) ); fail( "Should have thrown exception" ); } catch ( ConstraintViolationException ex ) { // Happy } finally { tx2.finish(); } } @Test public void addingALabelThatAlreadyExistsBehavesAsNoOp() throws Exception { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); Node myNode = null; // When Transaction tx = beansAPI.beginTx(); try { myNode = beansAPI.createNode(); myNode.addLabel( Labels.MY_LABEL ); myNode.addLabel( Labels.MY_LABEL ); tx.success(); } finally { tx.finish(); } // Then assertThat( "Label should have been added to node", myNode, inTx( beansAPI, hasLabel( Labels.MY_LABEL ) ) ); } @Test public void oversteppingMaxNumberOfLabelsShouldFailGracefully() throws Exception { // Given GraphDatabaseService beansAPI = beansAPIWithNoMoreLabelIds(); // When Transaction tx = beansAPI.beginTx(); try { beansAPI.createNode().addLabel( Labels.MY_LABEL ); fail( "Should have thrown exception" ); } catch ( ConstraintViolationException ex ) { // Happy } finally { tx.finish(); } } @Test public void removingCommittedLabel() throws Exception { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); Label label = Labels.MY_LABEL; Node myNode = createNode( beansAPI, label ); // When Transaction tx = beansAPI.beginTx(); try { myNode.removeLabel( label ); tx.success(); } finally { tx.finish(); } // Then assertThat( myNode, not( inTx( beansAPI, hasLabel( label ) ) ) ); } @Test public void createNodeWithLabels() throws Exception { // GIVEN GraphDatabaseService db = dbRule.getGraphDatabaseService(); // WHEN Node node = null; Transaction tx = db.beginTx(); try { node = db.createNode( Labels.values() ); tx.success(); } finally { tx.finish(); } // THEN assertThat( node, inTx( db, hasLabels( asEnumNameSet( Labels.class ) ) )); } @Test public void removingNonExistentLabel() throws Exception { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); Label label = Labels.MY_LABEL; // When Transaction tx = beansAPI.beginTx(); Node myNode; try { myNode = beansAPI.createNode(); myNode.removeLabel( label ); tx.success(); } finally { tx.finish(); } // THEN assertThat( myNode, not( inTx( beansAPI, hasLabel( label ) ) ) ); } @Test public void removingExistingLabelFromUnlabeledNode() throws Exception { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); Label label = Labels.MY_LABEL; createNode( beansAPI, label ); Node myNode = createNode( beansAPI ); // When Transaction tx = beansAPI.beginTx(); try { myNode.removeLabel( label ); tx.success(); } finally { tx.finish(); } // THEN assertThat( myNode, not( inTx( beansAPI, hasLabel( label ) ) ) ) ; } @Test public void removingUncommittedLabel() throws Exception { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); Label label = Labels.MY_LABEL; // When Transaction tx = beansAPI.beginTx(); Node myNode; try { myNode = beansAPI.createNode(); myNode.addLabel( label ); myNode.removeLabel( label ); // THEN assertFalse( myNode.hasLabel( label ) ); tx.success(); } finally { tx.finish(); } } @Test public void shouldBeAbleToListLabelsForANode() throws Exception { // GIVEN GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); Transaction tx = beansAPI.beginTx(); Node node = null; Set<String> expected = asSet( Labels.MY_LABEL.name(), Labels.MY_OTHER_LABEL.name() ); try { node = beansAPI.createNode(); for ( String label : expected ) { node.addLabel( label( label ) ); } tx.success(); } finally { tx.finish(); } assertThat(node, inTx( beansAPI, hasLabels( expected ) )); } @Test public void shouldReturnEmptyListIfNoLabels() throws Exception { // GIVEN GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); Node node = createNode( beansAPI ); // WHEN THEN assertThat(node, inTx( beansAPI, hasNoLabels() )); } @Test public void getNodesWithLabelCommitted() throws Exception { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); GlobalGraphOperations glops = GlobalGraphOperations.at( beansAPI ); // When Transaction tx = beansAPI.beginTx(); Node node = beansAPI.createNode(); node.addLabel( Labels.MY_LABEL ); tx.success(); tx.finish(); // THEN assertThat( glops, inTx( beansAPI, hasNodes( Labels.MY_LABEL, node ) ) ); assertThat( glops, inTx( beansAPI, hasNoNodes( Labels.MY_OTHER_LABEL ) ) ); } @Test public void getNodesWithLabelsWithTxAddsAndRemoves() throws Exception { // GIVEN GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); GlobalGraphOperations glops = GlobalGraphOperations.at( beansAPI ); Node node1 = createNode( beansAPI, Labels.MY_LABEL, Labels.MY_OTHER_LABEL ); Node node2 = createNode( beansAPI, Labels.MY_LABEL, Labels.MY_OTHER_LABEL ); // WHEN Transaction tx = beansAPI.beginTx(); Node node3 = null; Set<Node> nodesWithMyLabel = null, nodesWithMyOtherLabel = null; try { node3 = beansAPI.createNode( Labels.MY_LABEL ); node2.removeLabel( Labels.MY_LABEL ); // extracted here to be asserted below nodesWithMyLabel = asSet( glops.getAllNodesWithLabel( Labels.MY_LABEL ) ); nodesWithMyOtherLabel = asSet( glops.getAllNodesWithLabel( Labels.MY_OTHER_LABEL ) ); tx.success(); } finally { tx.finish(); } // THEN assertEquals( asSet( node1, node3 ), nodesWithMyLabel ); assertEquals( asSet( node1, node2 ), nodesWithMyOtherLabel ); } @Test public void shouldListLabels() throws Exception { // Given GraphDatabaseService db = dbRule.getGraphDatabaseService(); GlobalGraphOperations globalOps = GlobalGraphOperations.at( db ); createNode( db, Labels.MY_LABEL, Labels.MY_OTHER_LABEL ); List<Label> labels = null; // When Transaction tx = db.beginTx(); try { labels = toList( globalOps.getAllLabels() ); } finally { tx.finish(); } // Then assertEquals( 2, labels.size() ); assertThat( map( new Function<Label, String>() { @Override public String apply( Label label ) { return label.name(); } }, labels ), hasItems( Labels.MY_LABEL.name(), Labels.MY_OTHER_LABEL.name() ) ); } @Test public void deleteAllNodesAndTheirLabels() throws Exception { // GIVEN GraphDatabaseService db = dbRule.getGraphDatabaseService(); final Label label = DynamicLabel.label( "A" ); { final Transaction tx = db.beginTx(); final Node node = db.createNode(); node.addLabel( label ); node.setProperty( "name", "bla" ); tx.success(); tx.finish(); } // WHEN { final Transaction tx = db.beginTx(); for ( final Node node : GlobalGraphOperations.at( db ).getAllNodes() ) { node.removeLabel( label ); // remove Label ... node.delete(); // ... and afterwards the node } tx.success(); tx.finish(); // here comes the exception } // THEN Transaction transaction = db.beginTx(); assertEquals( 0, count( GlobalGraphOperations.at( db ).getAllNodes() ) ); transaction.finish(); } @Test public void removingLabelDoesNotBreakPreviouslyCreatedLabelsIterator() { // GIVEN GraphDatabaseService db = dbRule.getGraphDatabaseService(); Label label1 = DynamicLabel.label( "A" ); Label label2 = DynamicLabel.label( "B" ); try ( Transaction tx = db.beginTx() ) { Node node = db.createNode( label1, label2 ); Iterable<Label> labels = node.getLabels(); Iterator<Label> labelIterator = labels.iterator(); while ( labelIterator.hasNext() ) { Label next = labelIterator.next(); node.removeLabel( next ); } tx.success(); } } @Test public void removingPropertyDoesNotBreakPreviouslyCreatedNodePropertyKeysIterator() { // GIVEN GraphDatabaseService db = dbRule.getGraphDatabaseService(); try ( Transaction tx = db.beginTx() ) { Node node = db.createNode(); node.setProperty( "name", "Horst" ); node.setProperty( "age", "72" ); Iterator<String> iterator = node.getPropertyKeys().iterator(); while ( iterator.hasNext() ) { node.removeProperty( iterator.next() ); } tx.success(); } } @Test public void shouldCreateNodeWithLotsOfLabelsAndThenRemoveMostOfThem() throws Exception { // given final int TOTAL_NUMBER_OF_LABELS = 200, NUMBER_OF_PRESERVED_LABELS = 20; GraphDatabaseService db = dbRule.getGraphDatabaseService(); Node node; { Transaction tx = db.beginTx(); try { node = db.createNode(); for ( int i = 0; i < TOTAL_NUMBER_OF_LABELS; i++ ) { node.addLabel( DynamicLabel.label( "label:" + i ) ); } tx.success(); } finally { tx.finish(); } } // when { Transaction tx = db.beginTx(); try { for ( int i = NUMBER_OF_PRESERVED_LABELS; i < TOTAL_NUMBER_OF_LABELS; i++ ) { node.removeLabel( DynamicLabel.label( "label:" + i ) ); } tx.success(); } finally { tx.finish(); } } dbRule.clearCache(); // then Transaction transaction = db.beginTx(); try { List<String> labels = new ArrayList<>(); for ( Label label : node.getLabels() ) { labels.add( label.name() ); } assertEquals( "labels on node: " + labels, NUMBER_OF_PRESERVED_LABELS, labels.size() ); } finally { transaction.finish(); } } @SuppressWarnings("deprecation") private GraphDatabaseService beansAPIWithNoMoreLabelIds() { return new ImpermanentGraphDatabase() { @Override protected IdGeneratorFactory createIdGeneratorFactory() { return new EphemeralIdGenerator.Factory() { @Override public IdGenerator open( FileSystemAbstraction fs, File fileName, int grabSize, IdType idType, long highId ) { switch ( idType ) { case LABEL_TOKEN: return new EphemeralIdGenerator( idType ) { @Override public long nextId() { // Same exception as the one thrown by IdGeneratorImpl throw new UnderlyingStorageException( "Id capacity exceeded" ); } }; default: return super.open( fs, fileName, grabSize, idType, Long.MAX_VALUE ); } } }; } }; } private Node createNode( GraphDatabaseService db, Label... labels ) { Transaction tx = db.beginTx(); try { Node node = db.createNode( labels ); tx.success(); return node; } finally { tx.finish(); } } }
false
community_kernel_src_test_java_org_neo4j_graphdb_LabelsAcceptanceTest.java
3,648
public class LabelScanStoreIT { @Test public void shouldGetNodesWithCreatedLabel() throws Exception { // GIVEN Node node1 = createLabeledNode( Labels.First ); Node node2 = createLabeledNode( Labels.Second ); Node node3 = createLabeledNode( Labels.Third ); Node node4 = createLabeledNode( Labels.First, Labels.Second, Labels.Third ); Node node5 = createLabeledNode( Labels.First, Labels.Third ); // THEN assertEquals( asSet( node1, node4, node5 ), asSet( getAllNodesWithLabel( Labels.First ) ) ); assertEquals( asSet( node2, node4 ), asSet( getAllNodesWithLabel( Labels.Second ) ) ); assertEquals( asSet( node3, node4, node5 ), asSet( getAllNodesWithLabel( Labels.Third ) ) ); } @Test public void shouldGetNodesWithAddedLabel() throws Exception { // GIVEN Node node1 = createLabeledNode( Labels.First ); Node node2 = createLabeledNode( Labels.Second ); Node node3 = createLabeledNode( Labels.Third ); Node node4 = createLabeledNode( Labels.First ); Node node5 = createLabeledNode( Labels.First ); // WHEN addLabels( node4, Labels.Second, Labels.Third ); addLabels( node5, Labels.Third ); // THEN assertEquals( asSet( node1, node4, node5 ), asSet( getAllNodesWithLabel( Labels.First ) ) ); assertEquals( asSet( node2, node4 ), asSet( getAllNodesWithLabel( Labels.Second ) ) ); assertEquals( asSet( node3, node4, node5 ), asSet( getAllNodesWithLabel( Labels.Third ) ) ); } @Test public void shouldGetNodesAfterDeletedNodes() throws Exception { // GIVEN Node node1 = createLabeledNode( Labels.First, Labels.Second ); Node node2 = createLabeledNode( Labels.First, Labels.Third ); // WHEN deleteNode( node1 ); // THEN assertEquals( asSet( node2 ), getAllNodesWithLabel( Labels.First ) ); assertEquals( emptySetOf( Node.class ), getAllNodesWithLabel( Labels.Second ) ); assertEquals( asSet( node2 ), getAllNodesWithLabel( Labels.Third ) ); } @Test public void shouldGetNodesAfterRemovedLabels() throws Exception { // GIVEN Node node1 = createLabeledNode( Labels.First, Labels.Second ); Node node2 = createLabeledNode( Labels.First, Labels.Third ); // WHEN removeLabels( node1, Labels.First ); removeLabels( node2, Labels.Third ); // THEN assertEquals( asSet( node2 ), getAllNodesWithLabel( Labels.First ) ); assertEquals( asSet( node1 ), getAllNodesWithLabel( Labels.Second ) ); assertEquals( emptySetOf( Node.class ), getAllNodesWithLabel( Labels.Third ) ); } @Test public void shouldHandleLargeAmountsOfNodesAddedAndRemovedInSameTx() throws Exception { // Given GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); int labelsToAdd = 80; int labelsToRemove = 40; // When Node node; try( Transaction tx = db.beginTx() ) { node = db.createNode(); // I create a lot of labels, enough to push the store to use two dynamic records for(int l=0;l<labelsToAdd;l++) { node.addLabel( label("Label-" + l) ); } // and I delete some of them, enough to bring the number of dynamic records needed down to 1 for(int l=0;l<labelsToRemove;l++) { node.removeLabel( label("Label-" + l) ); } tx.success(); } // Then try( Transaction ignore = db.beginTx() ) { // All the labels remaining should be in the label scan store for(int l=labelsToAdd-1;l>=labelsToRemove;l--) { Label label = label( "Label-" + l ); assertThat( "Should have founnd node when looking for label " + label, single( GlobalGraphOperations.at( db ).getAllNodesWithLabel( label ) ), equalTo( node ) ); } } } private void removeLabels( Node node, Label... labels ) { try ( Transaction tx = dbRule.getGraphDatabaseService().beginTx() ) { for ( Label label : labels ) { node.removeLabel( label ); } tx.success(); } } private void deleteNode( Node node ) { try ( Transaction tx = dbRule.getGraphDatabaseService().beginTx() ) { node.delete(); tx.success(); } } private Set<Node> getAllNodesWithLabel( Label label ) { try ( Transaction tx = dbRule.getGraphDatabaseService().beginTx() ) { return asSet( GlobalGraphOperations.at( dbRule.getGraphDatabaseService() ).getAllNodesWithLabel( label ) ); } } private Node createLabeledNode( Label... labels ) { try ( Transaction tx = dbRule.getGraphDatabaseService().beginTx() ) { Node node = dbRule.getGraphDatabaseService().createNode( labels ); tx.success(); return node; } } private void addLabels( Node node, Label... labels ) { try ( Transaction tx = dbRule.getGraphDatabaseService().beginTx() ) { for ( Label label : labels ) { node.addLabel( label ); } tx.success(); } } public final @Rule DatabaseRule dbRule = new ImpermanentDatabaseRule(); private static enum Labels implements Label { First, Second, Third } }
false
community_kernel_src_test_java_org_neo4j_graphdb_LabelScanStoreIT.java
3,649
public class InvalidTransactionTypeException extends RuntimeException { public InvalidTransactionTypeException(String message, Throwable cause) { super(message, cause); } }
false
community_kernel_src_main_java_org_neo4j_graphdb_InvalidTransactionTypeException.java
3,650
{ @Override protected Iterable<Label> manifest() { return myNode.getLabels(); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_IndexingAcceptanceTest.java
3,651
public class IndexingAcceptanceTest { /* This test is a bit interesting. It tests a case where we've got a property that sits in one * property block and the value is of a long type. So given that plus that there's an index for that * label/property, do an update that changes the long value into a value that requires two property blocks. * This is interesting because the transaction logic compares before/after views per property record and * not per node as a whole. * * In this case this change will be converted into one "add" and one "remove" property updates instead of * a single "change" property update. At the very basic level it's nice to test for this corner-case so * that the externally observed behavior is correct, even if this test doesn't assert anything about * the underlying add/remove vs. change internal details. */ @Test public void shouldInterpretPropertyAsChangedEvenIfPropertyMovesFromOneRecordToAnother() throws Exception { // GIVEN GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); long smallValue = 10L, bigValue = 1L << 62; Node myNode; { try ( Transaction tx = beansAPI.beginTx() ) { myNode = beansAPI.createNode( LABEL1 ); myNode.setProperty( "pad0", true ); myNode.setProperty( "pad1", true ); myNode.setProperty( "pad2", true ); // Use a small long here which will only occupy one property block myNode.setProperty( "key", smallValue ); tx.success(); } } { IndexDefinition indexDefinition; try ( Transaction tx = beansAPI.beginTx() ) { indexDefinition = beansAPI.schema().indexFor( LABEL1 ).on( "key" ).create(); tx.success(); } waitForIndex( beansAPI, indexDefinition ); } // WHEN try ( Transaction tx = beansAPI.beginTx() ) { // A big long value which will occupy two property blocks myNode.setProperty( "key", bigValue ); tx.success(); } // THEN assertThat( findNodesByLabelAndProperty( LABEL1, "key", bigValue, beansAPI ), containsOnly( myNode ) ); assertThat( findNodesByLabelAndProperty( LABEL1, "key", smallValue, beansAPI ), isEmpty() ); } @Test public void shouldUseDynamicPropertiesToIndexANodeWhenAddedAlongsideExistingPropertiesInASeparateTransaction() throws Exception { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); // When long id; { try ( Transaction tx = beansAPI.beginTx() ) { Node myNode = beansAPI.createNode(); id = myNode.getId(); myNode.setProperty( "key0", true ); myNode.setProperty( "key1", true ); tx.success(); } } { IndexDefinition indexDefinition; try ( Transaction tx = beansAPI.beginTx() ) { indexDefinition = beansAPI.schema().indexFor( LABEL1 ).on( "key2" ).create(); tx.success(); } waitForIndex( beansAPI, indexDefinition ); } Node myNode; { try ( Transaction tx = beansAPI.beginTx() ) { myNode = beansAPI.getNodeById( id ); myNode.addLabel( LABEL1 ); myNode.setProperty( "key2", LONG_STRING ); myNode.setProperty( "key3", LONG_STRING ); tx.success(); } } // Then assertThat( myNode, inTx( beansAPI, hasProperty( "key2" ).withValue( LONG_STRING ) ) ); assertThat( myNode, inTx( beansAPI, hasProperty( "key3" ).withValue( LONG_STRING ) ) ); assertThat( findNodesByLabelAndProperty( LABEL1, "key2", LONG_STRING, beansAPI ), containsOnly( myNode ) ); } @Test public void searchingForNodeByPropertyShouldWorkWithoutIndex() throws Exception { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); Node myNode = createNode( beansAPI, map( "name", "Hawking" ), LABEL1 ); // When assertThat( findNodesByLabelAndProperty( LABEL1, "name", "Hawking", beansAPI ), containsOnly( myNode ) ); } @Test public void searchingUsesIndexWhenItExists() throws Exception { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); Node myNode = createNode( beansAPI, map( "name", "Hawking" ), LABEL1 ); createIndex( beansAPI, LABEL1, "name" ); // When assertThat( findNodesByLabelAndProperty( LABEL1, "name", "Hawking", beansAPI ), containsOnly( myNode ) ); } @Test public void shouldCorrectlyUpdateIndexesWhenChangingLabelsAndPropertyAtTheSameTime() throws Exception { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); Node myNode = createNode( beansAPI, map( "name", "Hawking" ), LABEL1, LABEL2 ); createIndex( beansAPI, LABEL1, "name" ); createIndex( beansAPI, LABEL2, "name" ); createIndex( beansAPI, LABEL3, "name" ); // When try ( Transaction tx = beansAPI.beginTx() ) { myNode.removeLabel( LABEL1 ); myNode.addLabel( LABEL3 ); myNode.setProperty( "name", "Einstein" ); tx.success(); } // Then assertThat( myNode, inTx( beansAPI, hasProperty("name").withValue( "Einstein" ) ) ); assertThat( labels( myNode ), containsOnly( LABEL2, LABEL3 ) ); assertThat( findNodesByLabelAndProperty( LABEL1, "name", "Hawking", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL1, "name", "Einstein", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL2, "name", "Hawking", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL2, "name", "Einstein", beansAPI ), containsOnly( myNode ) ); assertThat( findNodesByLabelAndProperty( LABEL3, "name", "Hawking", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL3, "name", "Einstein", beansAPI ), containsOnly( myNode ) ); } @Test public void shouldCorrectlyUpdateIndexesWhenChangingLabelsAndPropertyMultipleTimesAllAtOnce() throws Exception { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); Node myNode = createNode( beansAPI, map( "name", "Hawking" ), LABEL1, LABEL2 ); createIndex( beansAPI, LABEL1, "name" ); createIndex( beansAPI, LABEL2, "name" ); createIndex( beansAPI, LABEL3, "name" ); // When try ( Transaction tx = beansAPI.beginTx() ) { myNode.addLabel( LABEL3 ); myNode.setProperty( "name", "Einstein" ); myNode.removeLabel( LABEL1 ); myNode.setProperty( "name", "Feynman" ); tx.success(); } // Then assertThat( myNode, inTx( beansAPI, hasProperty("name").withValue( "Feynman" ) ) ); assertThat( labels( myNode ), containsOnly( LABEL2, LABEL3 ) ); assertThat( findNodesByLabelAndProperty( LABEL1, "name", "Hawking", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL1, "name", "Einstein", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL1, "name", "Feynman", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL2, "name", "Hawking", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL1, "name", "Einstein", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL2, "name", "Feynman", beansAPI ), containsOnly( myNode ) ); assertThat( findNodesByLabelAndProperty( LABEL3, "name", "Hawking", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL1, "name", "Einstein", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL3, "name", "Feynman", beansAPI ), containsOnly( myNode ) ); } @Test public void searchingByLabelAndPropertyReturnsEmptyWhenMissingLabelOrProperty() throws Exception { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); // When/Then assertThat( findNodesByLabelAndProperty( LABEL1, "name", "Hawking", beansAPI ), isEmpty() ); } @Test public void shouldSeeIndexUpdatesWhenQueryingOutsideTransaction() throws Exception { // GIVEN GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); createIndex( beansAPI, LABEL1, "name" ); Node firstNode = createNode( beansAPI, map( "name", "Mattias" ), LABEL1 ); // WHEN THEN assertThat( findNodesByLabelAndProperty( LABEL1, "name", "Mattias", beansAPI ), containsOnly( firstNode ) ); Node secondNode = createNode( beansAPI, map( "name", "Taylor" ), LABEL1 ); assertThat( findNodesByLabelAndProperty( LABEL1, "name", "Taylor", beansAPI ), containsOnly( secondNode ) ); } @Test public void createdNodeShouldShowUpWithinTransaction() throws Exception { // GIVEN GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); createIndex( beansAPI, LABEL1, "name" ); // WHEN Transaction tx = beansAPI.beginTx(); Node firstNode = createNode( beansAPI, map( "name", "Mattias" ), LABEL1 ); long sizeBeforeDelete = count( beansAPI.findNodesByLabelAndProperty( LABEL1, "name", "Mattias" ) ); firstNode.delete(); long sizeAfterDelete = count( beansAPI.findNodesByLabelAndProperty( LABEL1, "name", "Mattias" ) ); tx.close(); // THEN assertThat( sizeBeforeDelete, equalTo(1l) ); assertThat( sizeAfterDelete, equalTo(0l) ); } @Test public void deletedNodeShouldShowUpWithinTransaction() throws Exception { // GIVEN GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); createIndex( beansAPI, LABEL1, "name" ); Node firstNode = createNode( beansAPI, map( "name", "Mattias" ), LABEL1 ); // WHEN Transaction tx = beansAPI.beginTx(); long sizeBeforeDelete = count( beansAPI.findNodesByLabelAndProperty( LABEL1, "name", "Mattias" ) ); firstNode.delete(); long sizeAfterDelete = count( beansAPI.findNodesByLabelAndProperty( LABEL1, "name", "Mattias" ) ); tx.close(); // THEN assertThat( sizeBeforeDelete, equalTo(1l) ); assertThat( sizeAfterDelete, equalTo(0l) ); } @Test public void createdNodeShouldShowUpInIndexQuery() throws Exception { // GIVEN GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); createIndex( beansAPI, LABEL1, "name" ); createNode( beansAPI, map( "name", "Mattias" ), LABEL1 ); // WHEN Transaction tx = beansAPI.beginTx(); long sizeBeforeDelete = count( beansAPI.findNodesByLabelAndProperty( LABEL1, "name", "Mattias" ) ); createNode( beansAPI, map( "name", "Mattias" ), LABEL1 ); long sizeAfterDelete = count( beansAPI.findNodesByLabelAndProperty( LABEL1, "name", "Mattias" ) ); tx.close(); // THEN assertThat( sizeBeforeDelete, equalTo(1l) ); assertThat( sizeAfterDelete, equalTo(2l) ); } @Test public void shouldBeAbleToQuerySupportedPropertyTypes() throws Exception { // GIVEN String property = "name"; GraphDatabaseService db = dbRule.getGraphDatabaseService(); createIndex( db, LABEL1, property ); // WHEN & THEN assertCanCreateAndFind( db, LABEL1, property, "A String" ); assertCanCreateAndFind( db, LABEL1, property, true ); assertCanCreateAndFind( db, LABEL1, property, false ); assertCanCreateAndFind( db, LABEL1, property, (byte) 56 ); assertCanCreateAndFind( db, LABEL1, property, 'z' ); assertCanCreateAndFind( db, LABEL1, property, (short)12 ); assertCanCreateAndFind( db, LABEL1, property, 12 ); assertCanCreateAndFind( db, LABEL1, property, 12l ); assertCanCreateAndFind( db, LABEL1, property, (float)12. ); assertCanCreateAndFind( db, LABEL1, property, 12. ); assertCanCreateAndFind( db, LABEL1, property, new String[]{"A String"} ); assertCanCreateAndFind( db, LABEL1, property, new boolean[]{true} ); assertCanCreateAndFind( db, LABEL1, property, new Boolean[]{false} ); assertCanCreateAndFind( db, LABEL1, property, new byte[]{56} ); assertCanCreateAndFind( db, LABEL1, property, new Byte[]{57} ); assertCanCreateAndFind( db, LABEL1, property, new char[]{'a'} ); assertCanCreateAndFind( db, LABEL1, property, new Character[]{'b'} ); assertCanCreateAndFind( db, LABEL1, property, new short[]{12} ); assertCanCreateAndFind( db, LABEL1, property, new Short[]{13} ); assertCanCreateAndFind( db, LABEL1, property, new int[]{14} ); assertCanCreateAndFind( db, LABEL1, property, new Integer[]{15} ); assertCanCreateAndFind( db, LABEL1, property, new long[]{16l} ); assertCanCreateAndFind( db, LABEL1, property, new Long[]{17l} ); assertCanCreateAndFind( db, LABEL1, property, new float[]{(float)18.} ); assertCanCreateAndFind( db, LABEL1, property, new Float[]{(float)19.} ); assertCanCreateAndFind( db, LABEL1, property, new double[]{20.} ); assertCanCreateAndFind( db, LABEL1, property, new Double[]{21.} ); } @Test public void shouldRetrieveMultipleNodesWithSameValueFromIndex() throws Exception { // this test was included here for now as a precondition for the following test // given GraphDatabaseService graph = dbRule.getGraphDatabaseService(); createIndex( graph, LABEL1, "name" ); Node node1, node2; try ( Transaction tx = graph.beginTx() ) { node1 = graph.createNode( LABEL1 ); node1.setProperty( "name", "Stefan" ); node2 = graph.createNode( LABEL1 ); node2.setProperty( "name", "Stefan" ); tx.success(); } try ( Transaction tx = graph.beginTx() ) { ResourceIterable<Node> result = graph.findNodesByLabelAndProperty( LABEL1, "name", "Stefan" ); assertEquals( asSet( node1, node2 ), asSet( result ) ); tx.success(); } } private void assertCanCreateAndFind( GraphDatabaseService db, Label label, String propertyKey, Object value ) { Node created = createNode( db, map( propertyKey, value ), label ); try ( Transaction tx = db.beginTx() ) { Node found = single( db.findNodesByLabelAndProperty( label, propertyKey, value ) ); assertThat( found, equalTo( created ) ); found.delete(); tx.success(); } } public static final String LONG_STRING = "a long string that has to be stored in dynamic records"; public @Rule ImpermanentDatabaseRule dbRule = new ImpermanentDatabaseRule(); private Label LABEL1 = DynamicLabel.label( "LABEL1" ); private Label LABEL2 = DynamicLabel.label( "LABEL2" ); private Label LABEL3 = DynamicLabel.label( "LABEL3" ); private Node createNode( GraphDatabaseService beansAPI, Map<String, Object> properties, Label... labels ) { try ( Transaction tx = beansAPI.beginTx() ) { Node node = beansAPI.createNode( labels ); for ( Map.Entry<String, Object> property : properties.entrySet() ) node.setProperty( property.getKey(), property.getValue() ); tx.success(); return node; } } private Neo4jMatchers.Deferred<Label> labels( final Node myNode ) { return new Neo4jMatchers.Deferred<Label>( dbRule.getGraphDatabaseService() ) { @Override protected Iterable<Label> manifest() { return myNode.getLabels(); } }; } }
false
community_kernel_src_test_java_org_neo4j_graphdb_IndexingAcceptanceTest.java
3,652
{ @Override public void call( IndexManager indexManager ) { for ( String indexName : indexManager.relationshipIndexNames() ) { } } };
false
community_kernel_src_test_java_org_neo4j_graphdb_IndexManagerFacadeMethods.java
3,653
{ @Override public void call( IndexManager indexManager ) { indexManager.forRelationships( "foo", null ); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_IndexManagerFacadeMethods.java
3,654
{ @Override public void call( IndexManager indexManager ) { indexManager.forRelationships( "foo" ); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_IndexManagerFacadeMethods.java
3,655
{ @Override public void call( IndexManager indexManager ) { indexManager.existsForRelationships( "foo" ); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_IndexManagerFacadeMethods.java
3,656
{ @Override public void call( IndexManager indexManager ) { for ( String indexName : indexManager.nodeIndexNames() ) { } } };
false
community_kernel_src_test_java_org_neo4j_graphdb_IndexManagerFacadeMethods.java
3,657
{ @Override public void call( GraphDatabaseService graphDatabaseService ) { graphDatabaseService.createNode(); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_GraphDatabaseServiceFacadeMethods.java
3,658
public class GraphDatabaseServiceFacadeMethods { static final FacadeMethod<GraphDatabaseService> CREATE_NODE = new FacadeMethod<GraphDatabaseService>( "Node createNode()" ) { @Override public void call( GraphDatabaseService graphDatabaseService ) { graphDatabaseService.createNode(); } }; static final FacadeMethod<GraphDatabaseService> CREATE_NODE_WITH_LABELS = new FacadeMethod<GraphDatabaseService>( "Node createNode( Label... labels )" ) { @Override public void call( GraphDatabaseService graphDatabaseService ) { graphDatabaseService.createNode( label( "FOO" ) ); } }; static final FacadeMethod<GraphDatabaseService> GET_NODE_BY_ID = new FacadeMethod<GraphDatabaseService>( "Node getNodeById( long id )" ) { @Override public void call( GraphDatabaseService graphDatabaseService ) { graphDatabaseService.getNodeById( 42 ); } }; static final FacadeMethod<GraphDatabaseService> GET_RELATIONSHIP_BY_ID = new FacadeMethod<GraphDatabaseService>( "Relationship getRelationshipById( long id )" ) { @Override public void call( GraphDatabaseService graphDatabaseService ) { graphDatabaseService.getRelationshipById( 87 ); } }; static final FacadeMethod<GraphDatabaseService> GET_ALL_NODES = new FacadeMethod<GraphDatabaseService>( "Iterable<Node> getAllNodes()" ) { @Override public void call( GraphDatabaseService graphDatabaseService ) { for ( Node node : graphDatabaseService.getAllNodes() ) { } } }; static final FacadeMethod<GraphDatabaseService> FIND_NODES_BY_LABEL_AND_PROPERTY = new FacadeMethod<GraphDatabaseService>( "ResourceIterable<Node> findNodesByLabelAndProperty( Label label, String key, Object value )" ) { @Override public void call( GraphDatabaseService graphDatabaseService ) { for ( Node node : graphDatabaseService.findNodesByLabelAndProperty( label( "bar" ), "baz", 23 ) ) { } } }; static final FacadeMethod<GraphDatabaseService> GET_RELATIONSHIP_TYPES = new FacadeMethod<GraphDatabaseService>( "Iterable<RelationshipType> getRelationshipTypes()" ) { @Override public void call( GraphDatabaseService graphDatabaseService ) { graphDatabaseService.getRelationshipTypes(); } }; static final FacadeMethod<GraphDatabaseService> SCHEMA = new FacadeMethod<GraphDatabaseService>( "Schema schema()" ) { @Override public void call( GraphDatabaseService graphDatabaseService ) { graphDatabaseService.schema(); } }; static final Iterable<FacadeMethod<GraphDatabaseService>> ALL_NON_TRANSACTIONAL_GRAPH_DATABASE_METHODS = unmodifiableCollection( asList( CREATE_NODE, CREATE_NODE_WITH_LABELS, GET_NODE_BY_ID, GET_RELATIONSHIP_BY_ID, GET_ALL_NODES, FIND_NODES_BY_LABEL_AND_PROPERTY, GET_RELATIONSHIP_TYPES, SCHEMA // TODO: INDEX ) ); }
false
community_kernel_src_test_java_org_neo4j_graphdb_GraphDatabaseServiceFacadeMethods.java
3,659
{ @Override public void call( GlobalGraphOperations self ) { self.getAllNodesWithLabel( DynamicLabel.label( "Label" ) ); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_GlobalGraphOperationsFacadeMethods.java
3,660
{ @Override public void call( GlobalGraphOperations self ) { self.getAllLabels(); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_GlobalGraphOperationsFacadeMethods.java
3,661
public abstract class SingleSourceShortestPathTest extends Neo4jAlgoTestCase { protected abstract SingleSourceShortestPath<Integer> getSingleSourceAlgorithm( Node startNode ); protected abstract SingleSourceShortestPath<Integer> getSingleSourceAlgorithm( Node startNode, Direction direction, RelationshipType... relTypes ); @Test public void testRun() { // make the graph graph.makeEdgeChain( "a,b1,c1,d1,e1,f1,g1" ); graph.makeEdgeChain( "a,b2,c2,d2,e2,f2,g2" ); graph.makeEdgeChain( "a,b3,c3,d3,e3,f3,g3" ); graph.makeEdgeChain( "b1,b2,b3,b1" ); graph.makeEdgeChain( "d1,d2,d3,d1" ); graph.makeEdgeChain( "f1,f2,f3,f1" ); // make the computation SingleSourceShortestPath<Integer> singleSource = getSingleSourceAlgorithm( graph .getNode( "a" ) ); // check a few distances assertTrue( singleSource.getCost( graph.getNode( "a" ) ) == 0 ); assertTrue( singleSource.getCost( graph.getNode( "b2" ) ) == 1 ); assertTrue( singleSource.getCost( graph.getNode( "c3" ) ) == 2 ); assertTrue( singleSource.getCost( graph.getNode( "d1" ) ) == 3 ); assertTrue( singleSource.getCost( graph.getNode( "e2" ) ) == 4 ); assertTrue( singleSource.getCost( graph.getNode( "f3" ) ) == 5 ); assertTrue( singleSource.getCost( graph.getNode( "g1" ) ) == 6 ); // check one path List<Node> path = singleSource.getPathAsNodes( graph.getNode( "g2" ) ); assertTrue( path.size() == 7 ); assertTrue( path.get( 0 ).equals( graph.getNode( "a" ) ) ); assertTrue( path.get( 1 ).equals( graph.getNode( "b2" ) ) ); assertTrue( path.get( 2 ).equals( graph.getNode( "c2" ) ) ); assertTrue( path.get( 3 ).equals( graph.getNode( "d2" ) ) ); assertTrue( path.get( 4 ).equals( graph.getNode( "e2" ) ) ); assertTrue( path.get( 5 ).equals( graph.getNode( "f2" ) ) ); assertTrue( path.get( 6 ).equals( graph.getNode( "g2" ) ) ); // check it as relationships List<Relationship> rpath = singleSource.getPathAsRelationships( graph .getNode( "g2" ) ); assertTrue( rpath.size() == 6 ); assertTrue( rpath.get( 0 ).equals( graph.getRelationship( "a", "b2" ) ) ); assertTrue( rpath.get( 1 ).equals( graph.getRelationship( "b2", "c2" ) ) ); assertTrue( rpath.get( 2 ).equals( graph.getRelationship( "c2", "d2" ) ) ); assertTrue( rpath.get( 3 ).equals( graph.getRelationship( "d2", "e2" ) ) ); assertTrue( rpath.get( 4 ).equals( graph.getRelationship( "e2", "f2" ) ) ); assertTrue( rpath.get( 5 ).equals( graph.getRelationship( "f2", "g2" ) ) ); // check it as both List<PropertyContainer> cpath = singleSource.getPath( graph .getNode( "g2" ) ); assertTrue( cpath.size() == 13 ); assertTrue( cpath.get( 0 ).equals( graph.getNode( "a" ) ) ); assertTrue( cpath.get( 2 ).equals( graph.getNode( "b2" ) ) ); assertTrue( cpath.get( 4 ).equals( graph.getNode( "c2" ) ) ); assertTrue( cpath.get( 6 ).equals( graph.getNode( "d2" ) ) ); assertTrue( cpath.get( 8 ).equals( graph.getNode( "e2" ) ) ); assertTrue( cpath.get( 10 ).equals( graph.getNode( "f2" ) ) ); assertTrue( cpath.get( 12 ).equals( graph.getNode( "g2" ) ) ); assertTrue( cpath.get( 1 ).equals( graph.getRelationship( "a", "b2" ) ) ); assertTrue( cpath.get( 3 ).equals( graph.getRelationship( "b2", "c2" ) ) ); assertTrue( cpath.get( 5 ).equals( graph.getRelationship( "c2", "d2" ) ) ); assertTrue( cpath.get( 7 ).equals( graph.getRelationship( "d2", "e2" ) ) ); assertTrue( cpath.get( 9 ).equals( graph.getRelationship( "e2", "f2" ) ) ); assertTrue( cpath.get( 11 ) .equals( graph.getRelationship( "f2", "g2" ) ) ); graph.clear(); } @Test public void testMultipleRelTypes() { graph.setCurrentRelType( MyRelTypes.R1 ); graph.makeEdgeChain( "a,b,c,d,e" ); graph.setCurrentRelType( MyRelTypes.R2 ); graph.makeEdges( "a,c" ); // first shortcut graph.setCurrentRelType( MyRelTypes.R3 ); graph.makeEdges( "c,e" ); // second shortcut SingleSourceShortestPath<Integer> singleSource; // one path singleSource = getSingleSourceAlgorithm( graph.getNode( "a" ), Direction.BOTH, MyRelTypes.R1 ); assertTrue( singleSource.getCost( graph.getNode( "e" ) ) == 4 ); // one shortcut singleSource = getSingleSourceAlgorithm( graph.getNode( "a" ), Direction.BOTH, MyRelTypes.R1, MyRelTypes.R2 ); assertTrue( singleSource.getCost( graph.getNode( "e" ) ) == 3 ); // other shortcut singleSource = getSingleSourceAlgorithm( graph.getNode( "a" ), Direction.BOTH, MyRelTypes.R1, MyRelTypes.R3 ); assertTrue( singleSource.getCost( graph.getNode( "e" ) ) == 3 ); // both shortcuts singleSource = getSingleSourceAlgorithm( graph.getNode( "a" ), Direction.BOTH, MyRelTypes.R1, MyRelTypes.R2, MyRelTypes.R3 ); assertTrue( singleSource.getCost( graph.getNode( "e" ) ) == 2 ); } }
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_SingleSourceShortestPathTest.java
3,662
{ public Integer getCost( Relationship relationship, Direction direction ) { return 1; } }, new org.neo4j.graphalgo.impl.util.IntegerAdder(),
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_SingleSourceShortestPathDijkstraTest.java
3,663
{ public Integer getCost( Relationship relationship, Direction direction ) { return 1; } }, new org.neo4j.graphalgo.impl.util.IntegerAdder(),
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_SingleSourceShortestPathDijkstraTest.java
3,664
public class SingleSourceShortestPathDijkstraTest extends SingleSourceShortestPathTest { protected SingleSourceShortestPath<Integer> getSingleSourceAlgorithm( Node startNode ) { return new SingleSourceShortestPathDijkstra<Integer>( 0, startNode, new CostEvaluator<Integer>() { public Integer getCost( Relationship relationship, Direction direction ) { return 1; } }, new org.neo4j.graphalgo.impl.util.IntegerAdder(), new org.neo4j.graphalgo.impl.util.IntegerComparator(), Direction.BOTH, MyRelTypes.R1 ); } protected SingleSourceShortestPath<Integer> getSingleSourceAlgorithm( Node startNode, Direction direction, RelationshipType... relTypes ) { return new SingleSourceShortestPathDijkstra<Integer>( 0, startNode, new CostEvaluator<Integer>() { public Integer getCost( Relationship relationship, Direction direction ) { return 1; } }, new org.neo4j.graphalgo.impl.util.IntegerAdder(), new org.neo4j.graphalgo.impl.util.IntegerComparator(), direction, relTypes ); } }
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_SingleSourceShortestPathDijkstraTest.java
3,665
public class SingleSourceShortestPathBFSTest extends SingleSourceShortestPathTest { protected SingleSourceShortestPath<Integer> getSingleSourceAlgorithm( Node startNode ) { SingleSourceShortestPathBFS sourceBFS = new SingleSourceShortestPathBFS( startNode, Direction.BOTH, MyRelTypes.R1 ); return sourceBFS; } protected SingleSourceShortestPath<Integer> getSingleSourceAlgorithm( Node startNode, Direction direction, RelationshipType... relTypes ) { return new SingleSourceShortestPathBFS( startNode, direction, relTypes ); } }
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_SingleSourceShortestPathBFSTest.java
3,666
{ public Double getCost( Relationship relationship, Direction direction ) { assertEquals( Direction.INCOMING, direction ); return 1.0; } }, new org.neo4j.graphalgo.impl.util.DoubleAdder(),
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_FloydWarshallTest.java
3,667
{ public Double getCost( Relationship relationship, Direction direction ) { assertEquals( Direction.OUTGOING, direction ); return 1.0; } }, new org.neo4j.graphalgo.impl.util.DoubleAdder(),
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_FloydWarshallTest.java
3,668
public class FloydWarshallTest extends Neo4jAlgoTestCase { /** * Test case for paths of length 0 and 1, and an impossible path */ @Test public void testMinimal() { graph.makeEdge( "a", "b", "cost", (double) 1 ); graph.makeEdge( "a", "c", "cost", (double) 1 ); graph.makeEdge( "a", "d", "cost", (double) 1 ); graph.makeEdge( "a", "e", "cost", (double) 1 ); graph.makeEdge( "b", "c", "cost", (double) 1 ); graph.makeEdge( "c", "d", "cost", (double) 1 ); graph.makeEdge( "d", "e", "cost", (double) 1 ); graph.makeEdge( "e", "b", "cost", (double) 1 ); FloydWarshall<Double> floydWarshall = new FloydWarshall<Double>( 0.0, Double.MAX_VALUE, Direction.OUTGOING, CommonEvaluators.doubleCostEvaluator( "cost" ), new org.neo4j.graphalgo.impl.util.DoubleAdder(), new org.neo4j.graphalgo.impl.util.DoubleComparator(), graph .getAllNodes(), graph.getAllEdges() ); assertTrue( floydWarshall.getCost( graph.getNode( "a" ), graph .getNode( "a" ) ) == 0.0 ); assertTrue( floydWarshall.getCost( graph.getNode( "a" ), graph .getNode( "b" ) ) == 1.0 ); assertTrue( floydWarshall.getCost( graph.getNode( "b" ), graph .getNode( "a" ) ) == Double.MAX_VALUE ); } /** * Test case for extracting paths */ @Test public void testPath() { graph.makeEdge( "a", "b", "cost", (double) 1 ); graph.makeEdge( "b", "c", "cost", (double) 1 ); graph.makeEdge( "c", "d", "cost", (double) 1 ); graph.makeEdge( "d", "e", "cost", (double) 1 ); graph.makeEdge( "e", "f", "cost", (double) 1 ); FloydWarshall<Double> floydWarshall = new FloydWarshall<Double>( 0.0, Double.MAX_VALUE, Direction.OUTGOING, CommonEvaluators.doubleCostEvaluator( "cost" ), new org.neo4j.graphalgo.impl.util.DoubleAdder(), new org.neo4j.graphalgo.impl.util.DoubleComparator(), graph .getAllNodes(), graph.getAllEdges() ); List<Node> path = floydWarshall.getPath( graph.getNode( "a" ), graph .getNode( "f" ) ); assertTrue( path.size() == 6 ); assertTrue( path.get( 0 ).equals( graph.getNode( "a" ) ) ); assertTrue( path.get( 1 ).equals( graph.getNode( "b" ) ) ); assertTrue( path.get( 2 ).equals( graph.getNode( "c" ) ) ); assertTrue( path.get( 3 ).equals( graph.getNode( "d" ) ) ); assertTrue( path.get( 4 ).equals( graph.getNode( "e" ) ) ); assertTrue( path.get( 5 ).equals( graph.getNode( "f" ) ) ); } @Test public void testDirection() { graph.makeEdge( "a", "b" ); graph.makeEdge( "b", "c" ); graph.makeEdge( "c", "d" ); graph.makeEdge( "d", "a" ); graph.makeEdge( "s", "a" ); graph.makeEdge( "b", "s" ); graph.makeEdge( "e", "c" ); graph.makeEdge( "d", "e" ); new FloydWarshall<Double>( 0.0, Double.MAX_VALUE, Direction.OUTGOING, new CostEvaluator<Double>() { public Double getCost( Relationship relationship, Direction direction ) { assertEquals( Direction.OUTGOING, direction ); return 1.0; } }, new org.neo4j.graphalgo.impl.util.DoubleAdder(), new org.neo4j.graphalgo.impl.util.DoubleComparator(), graph .getAllNodes(), graph.getAllEdges() ).calculate(); new FloydWarshall<Double>( 0.0, Double.MAX_VALUE, Direction.INCOMING, new CostEvaluator<Double>() { public Double getCost( Relationship relationship, Direction direction ) { assertEquals( Direction.INCOMING, direction ); return 1.0; } }, new org.neo4j.graphalgo.impl.util.DoubleAdder(), new org.neo4j.graphalgo.impl.util.DoubleComparator(), graph .getAllNodes(), graph.getAllEdges() ).calculate(); } }
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_FloydWarshallTest.java
3,669
public class DijkstraTest extends Neo4jAlgoTestCase { protected Dijkstra<Double> getDijkstra( SimpleGraphBuilder graph, Double startCost, String startNode, String endNode ) { return new Dijkstra<Double>( startCost, graph.getNode( startNode ), graph.getNode( endNode ), CommonEvaluators.doubleCostEvaluator( "cost" ), new org.neo4j.graphalgo.impl.util.DoubleAdder(), new org.neo4j.graphalgo.impl.util.DoubleComparator(), Direction.BOTH, MyRelTypes.R1 ); } /** * Test case for just a single node (path length zero) */ @Test public void testDijkstraMinimal() { graph.makeNode( "lonely" ); Dijkstra<Double> dijkstra = getDijkstra( graph, 0.0, "lonely", "lonely" ); assertTrue( dijkstra.getCost() == 0.0 ); assertTrue( dijkstra.getPathAsNodes().size() == 1 ); dijkstra = getDijkstra( graph, 3.0, "lonely", "lonely" ); assertTrue( dijkstra.getCost() == 6.0 ); assertTrue( dijkstra.getPathAsNodes().size() == 1 ); assertTrue( dijkstra.getPathsAsNodes().size() == 1 ); } /** * Test case for a path of length zero, with some surrounding nodes */ @Test public void testDijkstraMinimal2() { graph.makeEdge( "a", "b", "cost", (double) 1 ); graph.makeEdge( "a", "c", "cost", (double) 1 ); graph.makeEdge( "a", "d", "cost", (double) 1 ); graph.makeEdge( "a", "e", "cost", (double) 1 ); graph.makeEdge( "b", "c", "cost", (double) 1 ); graph.makeEdge( "c", "d", "cost", (double) 1 ); graph.makeEdge( "d", "e", "cost", (double) 1 ); graph.makeEdge( "e", "f", "cost", (double) 1 ); Dijkstra<Double> dijkstra = getDijkstra( graph, 0.0, "a", "a" ); assertTrue( dijkstra.getCost() == 0.0 ); assertTrue( dijkstra.getPathAsNodes().size() == 1 ); dijkstra = getDijkstra( graph, 3.0, "a", "a" ); assertTrue( dijkstra.getCost() == 6.0 ); assertTrue( dijkstra.getPathAsNodes().size() == 1 ); assertTrue( dijkstra.getPathAsRelationships().size() == 0 ); assertTrue( dijkstra.getPath().size() == 1 ); assertTrue( dijkstra.getPathsAsNodes().size() == 1 ); } @Test public void testDijkstraChain() { graph.makeEdge( "a", "b", "cost", (double) 1 ); graph.makeEdge( "b", "c", "cost", (double) 2 ); graph.makeEdge( "c", "d", "cost", (double) 3 ); Dijkstra<Double> dijkstra = getDijkstra( graph, 0.0, "a", "d" ); assertTrue( dijkstra.getCost() == 6.0 ); assertTrue( dijkstra.getPathAsNodes() != null ); assertTrue( dijkstra.getPathAsNodes().size() == 4 ); assertTrue( dijkstra.getPathsAsNodes().size() == 1 ); dijkstra = getDijkstra( graph, 0.0, "d", "a" ); assertTrue( dijkstra.getCost() == 6.0 ); assertTrue( dijkstra.getPathAsNodes().size() == 4 ); dijkstra = getDijkstra( graph, 0.0, "d", "b" ); assertTrue( dijkstra.getCost() == 5.0 ); assertTrue( dijkstra.getPathAsNodes().size() == 3 ); assertTrue( dijkstra.getPathAsRelationships().size() == 2 ); assertTrue( dijkstra.getPath().size() == 5 ); } /** * /--2--A--7--B--2--\ S E \----7---C---7----/ */ @Test public void testDijstraTraverserMeeting() { graph.makeEdge( "s", "c", "cost", (double) 7 ); graph.makeEdge( "c", "e", "cost", (double) 7 ); graph.makeEdge( "s", "a", "cost", (double) 2 ); graph.makeEdge( "a", "b", "cost", (double) 7 ); graph.makeEdge( "b", "e", "cost", (double) 2 ); Dijkstra<Double> dijkstra = getDijkstra( graph, 0.0, "s", "e" ); assertTrue( dijkstra.getCost() == 11.0 ); assertTrue( dijkstra.getPathAsNodes() != null ); assertTrue( dijkstra.getPathAsNodes().size() == 4 ); assertTrue( dijkstra.getPathsAsNodes().size() == 1 ); } }
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_DijkstraTest.java
3,670
{ public Double getCost( Relationship relationship, Direction direction ) { return 1.0; } }, new DoubleAdder(), new DoubleComparator(), Direction.BOTH,
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_DijkstraMultipleRelationshipTypesTest.java
3,671
public class DijkstraMultipleRelationshipTypesTest extends Neo4jAlgoTestCase { protected Dijkstra<Double> getDijkstra( String startNode, String endNode, RelationshipType... relTypes ) { return new Dijkstra<Double>( 0.0, graph.getNode( startNode ), graph.getNode( endNode ), new CostEvaluator<Double>() { public Double getCost( Relationship relationship, Direction direction ) { return 1.0; } }, new DoubleAdder(), new DoubleComparator(), Direction.BOTH, relTypes ); } @Test public void testRun() { graph.setCurrentRelType( MyRelTypes.R1 ); graph.makeEdgeChain( "a,b,c,d,e" ); graph.setCurrentRelType( MyRelTypes.R2 ); graph.makeEdges( "a,c" ); // first shortcut graph.setCurrentRelType( MyRelTypes.R3 ); graph.makeEdges( "c,e" ); // second shortcut Dijkstra<Double> dijkstra; dijkstra = getDijkstra( "a", "e", MyRelTypes.R1 ); assertTrue( dijkstra.getCost() == 4.0 ); dijkstra = getDijkstra( "a", "e", MyRelTypes.R1, MyRelTypes.R2 ); assertTrue( dijkstra.getCost() == 3.0 ); dijkstra = getDijkstra( "a", "e", MyRelTypes.R1, MyRelTypes.R3 ); assertTrue( dijkstra.getCost() == 3.0 ); dijkstra = getDijkstra( "a", "e", MyRelTypes.R1, MyRelTypes.R2, MyRelTypes.R3 ); assertTrue( dijkstra.getCost() == 2.0 ); } }
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_DijkstraMultipleRelationshipTypesTest.java
3,672
{ public Double getCost( Relationship relationship, Direction direction ) { return 1.0; } }, new DoubleAdder(), new DoubleComparator(), Direction.OUTGOING,
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_DijkstraMultiplePathsTest.java
3,673
{ public Double getCost( Relationship relationship, Direction direction ) { return 1.0; } }, new DoubleAdder(), new DoubleComparator(), Direction.OUTGOING,
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_DijkstraMultiplePathsTest.java
3,674
public class DijkstraMultiplePathsTest extends Neo4jAlgoTestCase { protected Dijkstra<Double> getDijkstra( SimpleGraphBuilder graph, Double startCost, String startNode, String endNode ) { return new Dijkstra<Double>( startCost, graph.getNode( startNode ), graph.getNode( endNode ), CommonEvaluators.doubleCostEvaluator( "cost" ), new org.neo4j.graphalgo.impl.util.DoubleAdder(), new org.neo4j.graphalgo.impl.util.DoubleComparator(), Direction.BOTH, MyRelTypes.R1 ); } /** * A triangle with 0 cost should generate two paths between every pair of * nodes. */ @Test public void testTriangle() { graph.makeEdge( "a", "b", "cost", (double) 0 ); graph.makeEdge( "b", "c", "cost", (double) 0 ); graph.makeEdge( "c", "a", "cost", (double) 0 ); Dijkstra<Double> dijkstra; String[] nodes = { "a", "b", "c" }; for ( String node1 : nodes ) { for ( String node2 : nodes ) { dijkstra = getDijkstra( graph, 0.0, node1, node2 ); int nrPaths = dijkstra.getPathsAsNodes().size(); if ( !node1.equals( node2 ) ) { assertTrue( "Number of paths (" + node1 + "->" + node2 + "): " + nrPaths, nrPaths == 2 ); } assertTrue( dijkstra.getCost() == 0.0 ); } } } /** * From each direction 2 ways are possible so 4 ways should be the total. */ @Test public void test1() { graph.makeEdge( "a", "b", "cost", (double) 1 ); graph.makeEdge( "b", "d", "cost", (double) 1 ); graph.makeEdge( "a", "c", "cost", (double) 1 ); graph.makeEdge( "c", "d", "cost", (double) 1 ); graph.makeEdge( "d", "e", "cost", (double) 1 ); graph.makeEdge( "e", "f", "cost", (double) 1 ); graph.makeEdge( "f", "h", "cost", (double) 1 ); graph.makeEdge( "e", "g", "cost", (double) 1 ); graph.makeEdge( "g", "h", "cost", (double) 1 ); Dijkstra<Double> dijkstra = getDijkstra( graph, 0.0, "a", "h" ); assertTrue( dijkstra.getPaths().size() == 4 ); assertTrue( dijkstra.getPathsAsNodes().size() == 4 ); assertTrue( dijkstra.getPathsAsRelationships().size() == 4 ); assertTrue( dijkstra.getCost() == 5.0 ); } /** * Two different ways. This is supposed to test when the traversers meet in * several places. */ @Test public void test2() { graph.makeEdge( "a", "b", "cost", (double) 1 ); graph.makeEdge( "a", "f", "cost", (double) 1 ); graph.makeEdge( "b", "c", "cost", (double) 1 ); graph.makeEdge( "f", "g", "cost", (double) 1 ); graph.makeEdge( "c", "d", "cost", (double) 1 ); graph.makeEdge( "g", "h", "cost", (double) 1 ); graph.makeEdge( "d", "e", "cost", (double) 1 ); graph.makeEdge( "h", "e", "cost", (double) 1 ); Dijkstra<Double> dijkstra = getDijkstra( graph, 0.0, "a", "e" ); assertTrue( dijkstra.getPaths().size() == 2 ); assertTrue( dijkstra.getPathsAsNodes().size() == 2 ); assertTrue( dijkstra.getPathsAsRelationships().size() == 2 ); assertTrue( dijkstra.getCost() == 4.0 ); } /** * One side finding several paths to one node previously visited by the * other side. The other side is kept busy with a chain of cost zero. */ @Test public void test3() { // "zero" side graph.makeEdge( "a", "b", "cost", (double) 0 ); graph.makeEdge( "b", "c", "cost", (double) 0 ); graph.makeEdge( "c", "d", "cost", (double) 0 ); graph.makeEdge( "d", "e", "cost", (double) 0 ); graph.makeEdge( "e", "f", "cost", (double) 0 ); graph.makeEdge( "f", "g", "cost", (double) 0 ); graph.makeEdge( "g", "h", "cost", (double) 0 ); graph.makeEdge( "h", "i", "cost", (double) 0 ); graph.makeEdge( "i", "j", "cost", (double) 0 ); graph.makeEdge( "j", "k", "cost", (double) 0 ); // "discovering" side graph.makeEdge( "z", "y", "cost", (double) 0 ); graph.makeEdge( "y", "x", "cost", (double) 0 ); graph.makeEdge( "x", "w", "cost", (double) 0 ); graph.makeEdge( "w", "b", "cost", (double) 1 ); graph.makeEdge( "x", "b", "cost", (double) 2 ); graph.makeEdge( "y", "b", "cost", (double) 1 ); graph.makeEdge( "z", "b", "cost", (double) 1 ); graph.makeEdge( "zz", "z", "cost", (double) 0 ); Dijkstra<Double> dijkstra = getDijkstra( graph, 0.0, "a", "zz" ); assertTrue( dijkstra.getPathsAsNodes().size() == 3 ); assertTrue( dijkstra.getCost() == 1.0 ); } /** * another variant of the test above, but the discovering is a bit mixed. */ @Test public void test4() { // "zero" side graph.makeEdge( "a", "b", "cost", (double) 0 ); graph.makeEdge( "b", "c", "cost", (double) 0 ); graph.makeEdge( "c", "d", "cost", (double) 0 ); graph.makeEdge( "d", "e", "cost", (double) 0 ); graph.makeEdge( "e", "f", "cost", (double) 0 ); graph.makeEdge( "f", "g", "cost", (double) 0 ); graph.makeEdge( "g", "h", "cost", (double) 0 ); graph.makeEdge( "h", "i", "cost", (double) 0 ); graph.makeEdge( "i", "j", "cost", (double) 0 ); graph.makeEdge( "j", "k", "cost", (double) 0 ); // "discovering" side graph.makeEdge( "z", "y", "cost", (double) 0 ); graph.makeEdge( "y", "x", "cost", (double) 0 ); graph.makeEdge( "x", "w", "cost", (double) 0 ); graph.makeEdge( "w", "b", "cost", (double) 1 ); graph.makeEdge( "x", "b", "cost", (double) 2 ); graph.makeEdge( "y", "b", "cost", (double) 1 ); graph.makeEdge( "z", "b", "cost", (double) 1 ); Dijkstra<Double> dijkstra = getDijkstra( graph, 0.0, "a", "z" ); assertTrue( dijkstra.getPathsAsNodes().size() == 3 ); assertTrue( dijkstra.getCost() == 1.0 ); } /** * "Diamond" shape, with some weights to resemble the test case above. */ @Test public void test5() { graph.makeEdge( "a", "b", "cost", (double) 0 ); graph.makeEdge( "z", "y", "cost", (double) 0 ); graph.makeEdge( "y", "b", "cost", (double) 1 ); graph.makeEdge( "z", "b", "cost", (double) 1 ); graph.makeEdge( "y", "a", "cost", (double) 1 ); Dijkstra<Double> dijkstra = getDijkstra( graph, 0.0, "a", "z" ); List<List<Node>> paths = dijkstra.getPathsAsNodes(); assertTrue( paths.size() == 3 ); assertTrue( dijkstra.getCost() == 1.0 ); } @Test public void test6() { graph.makeEdgeChain( "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,z", "cost", (double) 1 ); graph.makeEdge( "a", "b2", "cost", (double) 4 ); graph.makeEdge( "b2", "c", "cost", (double) -2 ); Dijkstra<Double> dijkstra = new Dijkstra<Double>( 0.0, graph .getNode( "a" ), graph.getNode( "z" ), CommonEvaluators.doubleCostEvaluator( "cost" ), new org.neo4j.graphalgo.impl.util.DoubleAdder(), new org.neo4j.graphalgo.impl.util.DoubleComparator(), Direction.OUTGOING, MyRelTypes.R1 ); List<List<Node>> paths = dijkstra.getPathsAsNodes(); assertTrue( paths.size() == 2 ); } @Test public void test7() { Relationship edgeAB = graph.makeEdge( "a", "b" ); Relationship edgeBC = graph.makeEdge( "b", "c" ); Relationship edgeCD = graph.makeEdge( "c", "d" ); Relationship edgeDE = graph.makeEdge( "d", "e" ); Relationship edgeAB2 = graph.makeEdge( "a", "b2" ); Relationship edgeB2C = graph.makeEdge( "b2", "c" ); Relationship edgeCD2 = graph.makeEdge( "c", "d2" ); Relationship edgeD2E = graph.makeEdge( "d2", "e" ); Dijkstra<Double> dijkstra = new Dijkstra<Double>( 0.0, graph.getNode( "a" ), graph.getNode( "e" ), new CostEvaluator<Double>() { public Double getCost( Relationship relationship, Direction direction ) { return 1.0; } }, new DoubleAdder(), new DoubleComparator(), Direction.OUTGOING, MyRelTypes.R1 ); // path discovery flags boolean pathBD = false; boolean pathB2D = false; boolean pathBD2 = false; boolean pathB2D2 = false; List<List<PropertyContainer>> paths = dijkstra.getPaths(); assertTrue( paths.size() == 4 ); for ( List<PropertyContainer> path : paths ) { assertTrue( path.size() == 9 ); assertTrue( path.get( 0 ).equals( graph.getNode( "a" ) ) ); assertTrue( path.get( 4 ).equals( graph.getNode( "c" ) ) ); assertTrue( path.get( 8 ).equals( graph.getNode( "e" ) ) ); // first choice if ( path.get( 2 ).equals( graph.getNode( "b" ) ) ) { assertTrue( path.get( 1 ).equals( edgeAB ) ); assertTrue( path.get( 3 ).equals( edgeBC ) ); } else { assertTrue( path.get( 1 ).equals( edgeAB2 ) ); assertTrue( path.get( 2 ).equals( graph.getNode( "b2" ) ) ); assertTrue( path.get( 3 ).equals( edgeB2C ) ); } // second choice if ( path.get( 6 ).equals( graph.getNode( "d" ) ) ) { assertTrue( path.get( 5 ).equals( edgeCD ) ); assertTrue( path.get( 7 ).equals( edgeDE ) ); } else { assertTrue( path.get( 5 ).equals( edgeCD2 ) ); assertTrue( path.get( 6 ).equals( graph.getNode( "d2" ) ) ); assertTrue( path.get( 7 ).equals( edgeD2E ) ); } // combinations if ( path.get( 2 ).equals( graph.getNode( "b" ) ) ) { if ( path.get( 6 ).equals( graph.getNode( "d" ) ) ) { pathBD = true; } else if ( path.get( 6 ).equals( graph.getNode( "d2" ) ) ) { pathBD2 = true; } } else { if ( path.get( 6 ).equals( graph.getNode( "d" ) ) ) { pathB2D = true; } else if ( path.get( 6 ).equals( graph.getNode( "d2" ) ) ) { pathB2D2 = true; } } } assertTrue( pathBD ); assertTrue( pathB2D ); assertTrue( pathBD2 ); assertTrue( pathB2D2 ); } @Test public void test8() { Relationship edgeAB = graph.makeEdge( "a", "b" ); Relationship edgeBC = graph.makeEdge( "b", "c" ); Relationship edgeCD = graph.makeEdge( "c", "d" ); Relationship edgeDE = graph.makeEdge( "d", "e" ); Relationship edgeAB2 = graph.makeEdge( "a", "b2" ); Relationship edgeB2C = graph.makeEdge( "b2", "c" ); Relationship edgeCD2 = graph.makeEdge( "c", "d2" ); Relationship edgeD2E = graph.makeEdge( "d2", "e" ); Dijkstra<Double> dijkstra = new Dijkstra<Double>( 0.0, graph.getNode( "a" ), graph.getNode( "e" ), new CostEvaluator<Double>() { public Double getCost( Relationship relationship, Direction direction ) { return 1.0; } }, new DoubleAdder(), new DoubleComparator(), Direction.OUTGOING, MyRelTypes.R1 ); // path discovery flags boolean pathBD = false; boolean pathB2D = false; boolean pathBD2 = false; boolean pathB2D2 = false; List<List<Relationship>> paths = dijkstra.getPathsAsRelationships(); assertTrue( paths.size() == 4 ); for ( List<Relationship> path : paths ) { assertTrue( path.size() == 4 ); // first choice if ( path.get( 0 ).equals( edgeAB ) ) { assertTrue( path.get( 1 ).equals( edgeBC ) ); } else { assertTrue( path.get( 0 ).equals( edgeAB2 ) ); assertTrue( path.get( 1 ).equals( edgeB2C ) ); } // second choice if ( path.get( 2 ).equals( edgeCD ) ) { assertTrue( path.get( 3 ).equals( edgeDE ) ); } else { assertTrue( path.get( 2 ).equals( edgeCD2 ) ); assertTrue( path.get( 3 ).equals( edgeD2E ) ); } // combinations if ( path.get( 0 ).equals( edgeAB ) ) { if ( path.get( 2 ).equals( edgeCD ) ) { pathBD = true; } else if ( path.get( 2 ).equals( edgeCD2 ) ) { pathBD2 = true; } } else { if ( path.get( 2 ).equals( edgeCD ) ) { pathB2D = true; } else if ( path.get( 2 ).equals( edgeCD2 ) ) { pathB2D2 = true; } } } assertTrue( pathBD ); assertTrue( pathB2D ); assertTrue( pathBD2 ); assertTrue( pathB2D2 ); } }
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_DijkstraMultiplePathsTest.java
3,675
protected class TestIterator extends Dijkstra<Double>.DijstraIterator { public TestIterator( Node startNode, HashMap<Node,List<Relationship>> predecessors, HashMap<Node,Double> mySeen, HashMap<Node,Double> otherSeen, HashMap<Node,Double> myDistances, HashMap<Node,Double> otherDistances, boolean backwards ) { super( startNode, predecessors, mySeen, otherSeen, myDistances, otherDistances, backwards ); } }
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_DijkstraIteratorTest.java
3,676
protected class TestDijkstra extends Dijkstra<Double> { public TestDijkstra() { super( 0.0, null, null, CommonEvaluators.doubleCostEvaluator( "cost" ), new DoubleAdder(), new DoubleComparator(), Direction.BOTH, MyRelTypes.R1 ); } protected class TestIterator extends Dijkstra<Double>.DijstraIterator { public TestIterator( Node startNode, HashMap<Node,List<Relationship>> predecessors, HashMap<Node,Double> mySeen, HashMap<Node,Double> otherSeen, HashMap<Node,Double> myDistances, HashMap<Node,Double> otherDistances, boolean backwards ) { super( startNode, predecessors, mySeen, otherSeen, myDistances, otherDistances, backwards ); } } @Test public void runTest() { graph.makeEdge( "start", "a", "cost", (double) 1 ); graph.makeEdge( "a", "x", "cost", (double) 9 ); graph.makeEdge( "a", "b", "cost", (double) 1 ); graph.makeEdge( "b", "x", "cost", (double) 7 ); graph.makeEdge( "b", "c", "cost", (double) 1 ); graph.makeEdge( "c", "x", "cost", (double) 5 ); graph.makeEdge( "c", "d", "cost", (double) 1 ); graph.makeEdge( "d", "x", "cost", (double) 3 ); graph.makeEdge( "d", "e", "cost", (double) 1 ); graph.makeEdge( "e", "x", "cost", (double) 1 ); HashMap<Node,Double> seen1, seen2, dists1, dists2; seen1 = new HashMap<Node,Double>(); seen2 = new HashMap<Node,Double>(); dists1 = new HashMap<Node,Double>(); dists2 = new HashMap<Node,Double>(); DijstraIterator iter1 = new TestIterator( graph.getNode( "start" ), predecessors1, seen1, seen2, dists1, dists2, false ); // while ( iter1.hasNext() && !limitReached() && !iter1.isDone() ) assertTrue( iter1.next().equals( graph.getNode( "start" ) ) ); assertTrue( iter1.next().equals( graph.getNode( "a" ) ) ); assertTrue( seen1.get( graph.getNode( "x" ) ) == 10.0 ); assertTrue( iter1.next().equals( graph.getNode( "b" ) ) ); assertTrue( seen1.get( graph.getNode( "x" ) ) == 9.0 ); assertTrue( iter1.next().equals( graph.getNode( "c" ) ) ); assertTrue( seen1.get( graph.getNode( "x" ) ) == 8.0 ); assertTrue( iter1.next().equals( graph.getNode( "d" ) ) ); assertTrue( seen1.get( graph.getNode( "x" ) ) == 7.0 ); assertTrue( iter1.next().equals( graph.getNode( "e" ) ) ); assertTrue( seen1.get( graph.getNode( "x" ) ) == 6.0 ); assertTrue( iter1.next().equals( graph.getNode( "x" ) ) ); assertTrue( seen1.get( graph.getNode( "x" ) ) == 6.0 ); assertFalse( iter1.hasNext() ); int count = 0; // This code below is correct for the alternative priority queue // while ( iter1.hasNext() ) // { // iter1.next(); // ++count; // } // assertTrue( count == 4 ); // assertTrue( seen1.get( graph.getNode( "x" ) ) == 6.0 ); // Now test node limit seen1 = new HashMap<Node,Double>(); seen2 = new HashMap<Node,Double>(); dists1 = new HashMap<Node,Double>(); dists2 = new HashMap<Node,Double>(); iter1 = new TestIterator( graph.getNode( "start" ), predecessors1, seen1, seen2, dists1, dists2, false ); this.numberOfNodesTraversed = 0; this.limitMaxNodesToTraverse( 3 ); count = 0; while ( iter1.hasNext() ) { iter1.next(); ++count; } assertTrue( count == 3 ); } }
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_DijkstraIteratorTest.java
3,677
public class DijkstraIteratorTest extends Neo4jAlgoTestCase { @Test public void testRun() { new TestDijkstra().runTest(); } protected class TestDijkstra extends Dijkstra<Double> { public TestDijkstra() { super( 0.0, null, null, CommonEvaluators.doubleCostEvaluator( "cost" ), new DoubleAdder(), new DoubleComparator(), Direction.BOTH, MyRelTypes.R1 ); } protected class TestIterator extends Dijkstra<Double>.DijstraIterator { public TestIterator( Node startNode, HashMap<Node,List<Relationship>> predecessors, HashMap<Node,Double> mySeen, HashMap<Node,Double> otherSeen, HashMap<Node,Double> myDistances, HashMap<Node,Double> otherDistances, boolean backwards ) { super( startNode, predecessors, mySeen, otherSeen, myDistances, otherDistances, backwards ); } } @Test public void runTest() { graph.makeEdge( "start", "a", "cost", (double) 1 ); graph.makeEdge( "a", "x", "cost", (double) 9 ); graph.makeEdge( "a", "b", "cost", (double) 1 ); graph.makeEdge( "b", "x", "cost", (double) 7 ); graph.makeEdge( "b", "c", "cost", (double) 1 ); graph.makeEdge( "c", "x", "cost", (double) 5 ); graph.makeEdge( "c", "d", "cost", (double) 1 ); graph.makeEdge( "d", "x", "cost", (double) 3 ); graph.makeEdge( "d", "e", "cost", (double) 1 ); graph.makeEdge( "e", "x", "cost", (double) 1 ); HashMap<Node,Double> seen1, seen2, dists1, dists2; seen1 = new HashMap<Node,Double>(); seen2 = new HashMap<Node,Double>(); dists1 = new HashMap<Node,Double>(); dists2 = new HashMap<Node,Double>(); DijstraIterator iter1 = new TestIterator( graph.getNode( "start" ), predecessors1, seen1, seen2, dists1, dists2, false ); // while ( iter1.hasNext() && !limitReached() && !iter1.isDone() ) assertTrue( iter1.next().equals( graph.getNode( "start" ) ) ); assertTrue( iter1.next().equals( graph.getNode( "a" ) ) ); assertTrue( seen1.get( graph.getNode( "x" ) ) == 10.0 ); assertTrue( iter1.next().equals( graph.getNode( "b" ) ) ); assertTrue( seen1.get( graph.getNode( "x" ) ) == 9.0 ); assertTrue( iter1.next().equals( graph.getNode( "c" ) ) ); assertTrue( seen1.get( graph.getNode( "x" ) ) == 8.0 ); assertTrue( iter1.next().equals( graph.getNode( "d" ) ) ); assertTrue( seen1.get( graph.getNode( "x" ) ) == 7.0 ); assertTrue( iter1.next().equals( graph.getNode( "e" ) ) ); assertTrue( seen1.get( graph.getNode( "x" ) ) == 6.0 ); assertTrue( iter1.next().equals( graph.getNode( "x" ) ) ); assertTrue( seen1.get( graph.getNode( "x" ) ) == 6.0 ); assertFalse( iter1.hasNext() ); int count = 0; // This code below is correct for the alternative priority queue // while ( iter1.hasNext() ) // { // iter1.next(); // ++count; // } // assertTrue( count == 4 ); // assertTrue( seen1.get( graph.getNode( "x" ) ) == 6.0 ); // Now test node limit seen1 = new HashMap<Node,Double>(); seen2 = new HashMap<Node,Double>(); dists1 = new HashMap<Node,Double>(); dists2 = new HashMap<Node,Double>(); iter1 = new TestIterator( graph.getNode( "start" ), predecessors1, seen1, seen2, dists1, dists2, false ); this.numberOfNodesTraversed = 0; this.limitMaxNodesToTraverse( 3 ); count = 0; while ( iter1.hasNext() ) { iter1.next(); ++count; } assertTrue( count == 3 ); } } }
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_DijkstraIteratorTest.java
3,678
class directionSavingCostEvaluator implements CostEvaluator<Double> { HashMap<Relationship, Direction> dirs; public directionSavingCostEvaluator( HashMap<Relationship, Direction> dirs ) { super(); this.dirs = dirs; } public Double getCost( Relationship relationship, Direction direction ) { if ( !dirs.containsKey( relationship ) ) { dirs.put( relationship, direction ); } return 1.0; } }
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_DijkstraDirectionTest.java
3,679
{ public Double getCost( Relationship relationship, Direction direction ) { assertEquals( Direction.INCOMING, direction ); return 1.0; } }, new org.neo4j.graphalgo.impl.util.DoubleAdder(),
false
community_graph-algo_src_test_java_org_neo4j_graphalgo_shortestpath_DijkstraDirectionTest.java
3,680
public abstract class AbstractMandatoryTransactionsTest<T> { @Rule public EmbeddedDatabaseRule dbRule = new EmbeddedDatabaseRule(); public T obtainEntity() { GraphDatabaseService graphDatabaseService = dbRule.getGraphDatabaseService(); try ( Transaction tx = graphDatabaseService.beginTx() ) { T result = obtainEntityInTransaction( graphDatabaseService ); tx.success(); return result; } } protected abstract T obtainEntityInTransaction( GraphDatabaseService graphDatabaseService ); public static <T> void assertFacadeMethodsThrowNotInTransaction( T entity, Iterable<FacadeMethod<T>> methods ) { for ( FacadeMethod<T> method : methods ) { try { method.call( entity ); fail( "Transactions are mandatory, also for reads: " + method ); } catch ( NotInTransactionException e ) { // awesome } } } }
false
community_kernel_src_test_java_org_neo4j_graphdb_AbstractMandatoryTransactionsTest.java
3,681
public class ConstraintCreatorFacadeMethods { private static final FacadeMethod<ConstraintCreator> UNIQUE = new FacadeMethod<ConstraintCreator>( "ConstraintCreator unique()") { @Override public void call( ConstraintCreator self ) { self.assertPropertyIsUnique( "property" ); } }; private static final FacadeMethod<ConstraintCreator> CREATE = new FacadeMethod<ConstraintCreator>( "ConstraintDefinition create()" ) { @Override public void call( ConstraintCreator self ) { self.create(); } }; static final Iterable<FacadeMethod<ConstraintCreator>> ALL_CONSTRAINT_CREATOR_FACADE_METHODS = unmodifiableCollection( asList( UNIQUE, CREATE ) ); }
false
community_kernel_src_test_java_org_neo4j_graphdb_ConstraintCreatorFacadeMethods.java
3,682
{ @Override public void call( ConstraintCreator self ) { self.assertPropertyIsUnique( "property" ); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_ConstraintCreatorFacadeMethods.java
3,683
{ @Override public <T> T select( Class<T> type, Iterable<T> candidates ) throws IllegalArgumentException { Iterator<T> iterator = candidates.iterator(); if ( !iterator.hasNext() ) throw new IllegalArgumentException( "Could not resolve dependency of type:" + type.getName() ); return iterator.next(); } };
false
community_kernel_src_main_java_org_neo4j_graphdb_DependencyResolver.java
3,684
{ @Override public void call( GlobalGraphOperations self ) { self.getAllRelationshipTypes(); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_GlobalGraphOperationsFacadeMethods.java
3,685
{ @Override public void call( GlobalGraphOperations self ) { self.getAllRelationships(); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_GlobalGraphOperationsFacadeMethods.java
3,686
{ @Override public void call( GlobalGraphOperations self ) { self.getAllNodes(); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_GlobalGraphOperationsFacadeMethods.java
3,687
public class GlobalGraphOperationsFacadeMethods { private static final FacadeMethod<GlobalGraphOperations> GET_ALL_NODES = new FacadeMethod<GlobalGraphOperations>( "Iterable<Node> getAllNodes()" ) { @Override public void call( GlobalGraphOperations self ) { self.getAllNodes(); } }; private static final FacadeMethod<GlobalGraphOperations> GET_ALL_RELATIONSHIPS = new FacadeMethod<GlobalGraphOperations>( "Iterable<Relationship> getAllRelationships()" ) { @Override public void call( GlobalGraphOperations self ) { self.getAllRelationships(); } }; private static final FacadeMethod<GlobalGraphOperations> GET_ALL_RELATIONSHIP_TYPES = new FacadeMethod<GlobalGraphOperations>( "Iterable<RelationshipType> getAllRelationshipTypes()" ) { @Override public void call( GlobalGraphOperations self ) { self.getAllRelationshipTypes(); } }; private static final FacadeMethod<GlobalGraphOperations> GET_ALL_LABELS = new FacadeMethod<GlobalGraphOperations>( "ResourceIterable<Label> getAllLabels()" ) { @Override public void call( GlobalGraphOperations self ) { self.getAllLabels(); } }; private static final FacadeMethod<GlobalGraphOperations> GET_ALL_NODES_WITH_LABEL = new FacadeMethod<GlobalGraphOperations>( "ResourceIterable<Node> getAllNodesWithLabel( Label label )" ) { @Override public void call( GlobalGraphOperations self ) { self.getAllNodesWithLabel( DynamicLabel.label( "Label" ) ); } }; static final Iterable<FacadeMethod<GlobalGraphOperations>> ALL_GLOBAL_GRAPH_OPERATIONS_FACADE_METHODS = unmodifiableCollection( asList( GET_ALL_NODES, GET_ALL_RELATIONSHIPS, GET_ALL_RELATIONSHIP_TYPES, GET_ALL_LABELS, GET_ALL_NODES_WITH_LABEL ) ); }
false
community_kernel_src_test_java_org_neo4j_graphdb_GlobalGraphOperationsFacadeMethods.java
3,688
public class FirstStartupIT { @Rule public TargetDirectory.TestDirectory testDir = TargetDirectory.testDirForTest( getClass() ); @Test public void shouldBeEmptyWhenFirstStarted() throws Exception { // When GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase( testDir .absolutePath() ); // Then try(Transaction ignore = db.beginTx()) { GlobalGraphOperations global = GlobalGraphOperations.at( db ); assertEquals(0, count( global.getAllNodes() )); assertEquals(0, count( global.getAllRelationships() )); assertEquals(0, count( global.getAllRelationshipTypes() )); assertEquals(0, count( global.getAllLabels() )); assertEquals(0, count( global.getAllPropertyKeys() )); } db.shutdown(); } }
false
community_kernel_src_test_java_org_neo4j_graphdb_FirstStartupIT.java
3,689
public abstract class FacadeMethod<T> { private final String methodSignature; public FacadeMethod( String methodSignature ) { this.methodSignature = methodSignature; } public abstract void call( T self ); @Override public String toString() { return methodSignature; } }
false
community_kernel_src_test_java_org_neo4j_graphdb_FacadeMethod.java
3,690
public final class DynamicRelationshipType implements RelationshipType { private final String name; private DynamicRelationshipType( final String name ) { if ( name == null ) { throw new IllegalArgumentException( "A relationship type cannot " + "have a null name" ); } this.name = name; } /** * Instantiates a new DynamicRelationshipType with the given name. * There's more information regarding relationship types over at * {@link RelationshipType}. * * @param name the name of the dynamic relationship type * @return a DynamicRelationshipType with the given name * @throws IllegalArgumentException if name is <code>null</code> */ public static DynamicRelationshipType withName( final String name ) { return new DynamicRelationshipType( name ); } /** * Returns the name of this relationship type. The name uniquely identifies * a relationship type, i.e. two different RelationshipType instances with * different object identifiers (and possibly even different classes) are * semantically equivalent if they have {@link String#equals(Object) equal} * names. * * @return the name of the relationship type */ public String name() { return this.name; } /** * Returns a string representation of this dynamic relationship type. * * @return a string representation of this dynamic relationship type * @see java.lang.Object#toString() */ @Override public String toString() { return this.name; } /** * Implements the identity-based equals defined by {@link Object * java.lang.Object}. This means that this dynamic relationship type * instance will NOT be equal to other relationship types with the same * name. As outlined in the documentation for {@link RelationshipType * RelationshipType}, the proper way to check for equivalence between two * relationship types is to compare their {@link RelationshipType#name() * names}. * * @return <code>true</code> if <code>other</code> is the same instance as * this dynamic relationship type, <code>false</code> otherwise * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals( final Object other ) { return super.equals( other ); } /** * Implements the default hash function as defined by {@link Object * java.lang.Object}. This means that if you put a dynamic relationship * instance into a hash-based collection, it most likely will NOT behave as * you expect. Please see the documentation of {@link #equals(Object) * equals} and the {@link DynamicRelationshipType class documentation} for * more details. * * @return a hash code value for this dynamic relationship type instance * @see java.lang.Object#hashCode() */ @Override public int hashCode() { return super.hashCode(); } }
false
community_kernel_src_main_java_org_neo4j_graphdb_DynamicRelationshipType.java
3,691
public class DynamicLabel implements Label { /** * @param labelName the name of the label. * @return a {@link Label} instance for the given {@code labelName}. */ public static Label label( String labelName ) { return new DynamicLabel( labelName ); } private final String name; private DynamicLabel( String labelName ) { this.name = labelName; } @Override public String name() { return this.name; } @Override public String toString() { return this.name; } @Override public boolean equals(Object other) { return other instanceof Label && ((Label) other).name().equals( name ); } @Override public int hashCode() { return 26578 ^ name.hashCode(); } }
false
community_kernel_src_main_java_org_neo4j_graphdb_DynamicLabel.java
3,692
abstract class Adapter implements DependencyResolver { @SuppressWarnings( "rawtypes" ) private static final SelectionStrategy FIRST = new SelectionStrategy() { @Override public <T> T select( Class<T> type, Iterable<T> candidates ) throws IllegalArgumentException { Iterator<T> iterator = candidates.iterator(); if ( !iterator.hasNext() ) throw new IllegalArgumentException( "Could not resolve dependency of type:" + type.getName() ); return iterator.next(); } }; @Override public <T> T resolveDependency( Class<T> type ) throws IllegalArgumentException { return resolveDependency( type, FIRST ); } }
false
community_kernel_src_main_java_org_neo4j_graphdb_DependencyResolver.java
3,693
{ @Override public void call( ConstraintCreator self ) { self.create(); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_ConstraintCreatorFacadeMethods.java
3,694
public class DatabaseShutdownException extends RuntimeException { public DatabaseShutdownException( ) { super( "This database is shutdown." ); } }
false
community_kernel_src_main_java_org_neo4j_graphdb_DatabaseShutdownException.java
3,695
public class CreateAndDeleteNodesIT { public @Rule ImpermanentDatabaseRule dbRule = new ImpermanentDatabaseRule(); enum RelTypes implements RelationshipType { ASD } @Test public void addingALabelUsingAValidIdentifierShouldSucceed() throws Exception { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService(); Node myNode; // When Transaction tx = beansAPI.beginTx(); try { myNode = beansAPI.createNode(); myNode.setProperty( "Name", "Bob" ); myNode.createRelationshipTo( beansAPI.createNode(), RelTypes.ASD ); tx.success(); } finally { tx.finish(); } // When Transaction tx2 = beansAPI.beginTx(); try { for ( Relationship r : GlobalGraphOperations.at( beansAPI ).getAllRelationships() ) { r.delete(); } for ( Node n : GlobalGraphOperations.at( beansAPI ).getAllNodes() ) { n.delete(); } tx2.success(); } finally { tx2.finish(); } } }
false
community_kernel_src_test_java_org_neo4j_graphdb_CreateAndDeleteNodesIT.java
3,696
public class ConstraintViolationException extends RuntimeException { public ConstraintViolationException( String msg ) { super(msg); } public ConstraintViolationException( String msg, Throwable cause ) { super(msg, cause); } }
false
community_kernel_src_main_java_org_neo4j_graphdb_ConstraintViolationException.java
3,697
{ @Override public void call( ConstraintDefinition self ) { self.getPropertyKeys(); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_ConstraintDefinitionFacadeMethods.java
3,698
{ @Override public void call( ConstraintDefinition self ) { self.isConstraintType( ConstraintType.UNIQUENESS ); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_ConstraintDefinitionFacadeMethods.java
3,699
{ @Override public void call( ConstraintDefinition self ) { self.drop(); } };
false
community_kernel_src_test_java_org_neo4j_graphdb_ConstraintDefinitionFacadeMethods.java