//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFollowSpecificRelationship()
        public virtual void ShouldFollowSpecificRelationship()
        {
            // given
            using (NodeCursor node = cursors.allocateNodeCursor(), RelationshipGroupCursor group = cursors.allocateRelationshipGroupCursor(), RelationshipTraversalCursor relationship = cursors.allocateRelationshipTraversalCursor())
            {
                // when - traversing from start to end
                read.singleNode(_start, node);
                assertTrue("access start node", node.Next());
                node.Relationships(group);
                assertTrue("access relationship group", group.next());
                group.Outgoing(relationship);
                assertTrue("access outgoing relationships", relationship.next());

                // then
                assertEquals("source node", _start, relationship.SourceNodeReference());
                assertEquals("target node", _end, relationship.TargetNodeReference());

                assertEquals("node of origin", _start, relationship.OriginNodeReference());
                assertEquals("neighbouring node", _end, relationship.NeighbourNodeReference());

                assertEquals("relationship should have same label as group", group.Type(), relationship.Type());

                assertFalse("only a single relationship", relationship.next());

                group.Incoming(relationship);
                assertFalse("no incoming relationships", relationship.next());
                group.Loops(relationship);
                assertFalse("no loop relationships", relationship.next());

                assertFalse("only a single group", group.next());

                // when - traversing from end to start
                read.singleNode(_end, node);
                assertTrue("access start node", node.Next());
                node.Relationships(group);
                assertTrue("access relationship group", group.next());
                group.Incoming(relationship);
                assertTrue("access incoming relationships", relationship.next());

                // then
                assertEquals("source node", _start, relationship.SourceNodeReference());
                assertEquals("target node", _end, relationship.TargetNodeReference());

                assertEquals("node of origin", _end, relationship.OriginNodeReference());
                assertEquals("neighbouring node", _start, relationship.NeighbourNodeReference());

                assertEquals("relationship should have same label as group", group.Type(), relationship.Type());

                assertFalse("only a single relationship", relationship.next());

                group.Outgoing(relationship);
                assertFalse("no outgoing relationships", relationship.next());
                group.Loops(relationship);
                assertFalse("no loop relationships", relationship.next());

                assertFalse("only a single group", group.next());
            }
        }
Пример #2
0
 /// <summary>
 /// Counts the number of incoming relationships from node where the cursor is positioned.
 /// <para>
 /// NOTE: The number of incoming relationships also includes eventual loops.
 ///
 /// </para>
 /// </summary>
 /// <param name="nodeCursor"> a cursor positioned at the node whose relationships we're counting </param>
 /// <param name="cursors"> a factory for cursors </param>
 /// <returns> the number of incoming - including loops - relationships from the node </returns>
 public static int CountIncoming(NodeCursor nodeCursor, CursorFactory cursors)
 {
     if (nodeCursor.Dense)
     {
         using (RelationshipGroupCursor group = cursors.AllocateRelationshipGroupCursor())
         {
             nodeCursor.Relationships(group);
             int count = 0;
             while (group.next())
             {
                 count += group.IncomingCount() + group.LoopCount();
             }
             return(count);
         }
     }
     else
     {
         using (RelationshipTraversalCursor traversal = cursors.AllocateRelationshipTraversalCursor())
         {
             int count = 0;
             nodeCursor.AllRelationships(traversal);
             while (traversal.next())
             {
                 if (traversal.TargetNodeReference() == nodeCursor.NodeReference())
                 {
                     count++;
                 }
             }
             return(count);
         }
     }
 }
Пример #3
0
 /// <summary>
 /// Counts all the relationships of the given type from node where the cursor is positioned.
 /// </summary>
 /// <param name="nodeCursor"> a cursor positioned at the node whose relationships we're counting </param>
 /// <param name="cursors"> a factory for cursors </param>
 /// <param name="type"> the type of the relationship we're counting </param>
 /// <returns> the number relationships from the node with the given type </returns>
 public static int CountAll(NodeCursor nodeCursor, CursorFactory cursors, int type)
 {
     if (nodeCursor.Dense)
     {
         using (RelationshipGroupCursor group = cursors.AllocateRelationshipGroupCursor())
         {
             nodeCursor.Relationships(group);
             int count = 0;
             while (group.next())
             {
                 if (group.Type() == type)
                 {
                     return(group.TotalCount());
                 }
             }
             return(count);
         }
     }
     else
     {
         using (RelationshipTraversalCursor traversal = cursors.AllocateRelationshipTraversalCursor())
         {
             int count = 0;
             nodeCursor.AllRelationships(traversal);
             while (traversal.next())
             {
                 if (traversal.Type() == type)
                 {
                     count++;
                 }
             }
             return(count);
         }
     }
 }
Пример #4
0
 /// <summary>
 /// Counts the number of outgoing relationships of the given type from node where the cursor is positioned.
 /// <para>
 /// NOTE: The number of outgoing relationships also includes eventual loops.
 ///
 /// </para>
 /// </summary>
 /// <param name="nodeCursor"> a cursor positioned at the node whose relationships we're counting </param>
 /// <param name="cursors"> a factory for cursors </param>
 /// <param name="type"> the type of the relationship we're counting </param>
 /// <returns> the number of outgoing - including loops - relationships from the node with the given type </returns>
 public static int CountOutgoing(NodeCursor nodeCursor, CursorFactory cursors, int type)
 {
     if (nodeCursor.Dense)
     {
         using (RelationshipGroupCursor group = cursors.AllocateRelationshipGroupCursor())
         {
             nodeCursor.Relationships(group);
             while (group.next())
             {
                 if (group.Type() == type)
                 {
                     return(group.OutgoingCount() + group.LoopCount());
                 }
             }
             return(0);
         }
     }
     else
     {
         using (RelationshipTraversalCursor traversal = cursors.AllocateRelationshipTraversalCursor())
         {
             int count = 0;
             nodeCursor.AllRelationships(traversal);
             while (traversal.next())
             {
                 if (traversal.SourceNodeReference() == nodeCursor.NodeReference() && traversal.Type() == type)
                 {
                     count++;
                 }
             }
             return(count);
         }
     }
 }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void traverseViaGroups(RelationshipTestSupport.StartNode start, boolean detached) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private void TraverseViaGroups(RelationshipTestSupport.StartNode start, bool detached)
        {
            // given
            IDictionary <string, int> expectedCounts = start.ExpectedCounts();

            using (NodeCursor node = cursors.allocateNodeCursor(), RelationshipGroupCursor group = cursors.allocateRelationshipGroupCursor(), RelationshipTraversalCursor relationship = cursors.allocateRelationshipTraversalCursor())
            {
                // when
                read.singleNode(start.Id, node);
                assertTrue("access node", node.Next());
                if (detached)
                {
                    read.relationshipGroups(start.Id, node.RelationshipGroupReference(), group);
                }
                else
                {
                    node.Relationships(group);
                }

                while (group.next())
                {
                    // outgoing
                    if (detached)
                    {
                        read.relationships(start.Id, group.OutgoingReference(), relationship);
                    }
                    else
                    {
                        group.Outgoing(relationship);
                    }
                    // then
                    assertCount(tx, relationship, expectedCounts, group.Type(), OUTGOING);

                    // incoming
                    if (detached)
                    {
                        read.relationships(start.Id, group.IncomingReference(), relationship);
                    }
                    else
                    {
                        group.Incoming(relationship);
                    }
                    // then
                    assertCount(tx, relationship, expectedCounts, group.Type(), INCOMING);

                    // loops
                    if (detached)
                    {
                        read.relationships(start.Id, group.LoopsReference(), relationship);
                    }
                    else
                    {
                        group.Loops(relationship);
                    }
                    // then
                    assertCount(tx, relationship, expectedCounts, group.Type(), BOTH);
                }
            }
        }
Пример #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTraverseTreeOfDepthThree()
        public virtual void ShouldTraverseTreeOfDepthThree()
        {
            using (NodeCursor node = cursors.allocateNodeCursor(), RelationshipGroupCursor group = cursors.allocateRelationshipGroupCursor(), RelationshipTraversalCursor relationship1 = cursors.allocateRelationshipTraversalCursor(), RelationshipTraversalCursor relationship2 = cursors.allocateRelationshipTraversalCursor())
            {
                MutableLongSet leafs = new LongHashSet();
                long           total = 0;

                // when
                read.singleNode(_threeRoot, node);
                assertTrue("access root node", node.Next());
                node.Relationships(group);
                assertFalse("single root", node.Next());

                assertTrue("access group of root", group.next());
                group.Incoming(relationship1);
                assertFalse("single group of root", group.next());

                while (relationship1.next())
                {
                    relationship1.Neighbour(node);

                    assertTrue("child level 1", node.Next());
                    node.Relationships(group);
                    assertFalse("single node", node.Next());

                    assertTrue("group of level 1 child", group.next());
                    group.Incoming(relationship2);
                    assertFalse("single group of level 1 child", group.next());

                    while (relationship2.next())
                    {
                        leafs.add(relationship2.NeighbourNodeReference());
                        total++;
                    }
                }

                // then
                assertEquals("total number of leaf nodes", _expectedTotal, total);
                assertEquals("number of distinct leaf nodes", _expectedUnique, leafs.size());
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTraverseRelationshipsOfGivenType()
        public virtual void ShouldTraverseRelationshipsOfGivenType()
        {
            // given
            using (NodeCursor node = cursors.allocateNodeCursor(), RelationshipGroupCursor group = cursors.allocateRelationshipGroupCursor(), RelationshipTraversalCursor relationship = cursors.allocateRelationshipTraversalCursor())
            {
                int empty = 0;
                // when
                read.allNodesScan(node);
                while (node.Next())
                {
                    node.Relationships(group);
                    bool none = true;
                    while (group.next())
                    {
                        none = false;
                        Sizes degree = new Sizes();
                        group.Outgoing(relationship);
                        while (relationship.next())
                        {
                            assertEquals("node #" + node.NodeReference() + " relationship should have same label as group", group.Type(), relationship.Type());
                            degree.Outgoing++;
                        }
                        group.Incoming(relationship);
                        while (relationship.next())
                        {
                            assertEquals("node #" + node.NodeReference() + "relationship should have same label as group", group.Type(), relationship.Type());
                            degree.Incoming++;
                        }
                        group.Loops(relationship);
                        while (relationship.next())
                        {
                            assertEquals("node #" + node.NodeReference() + "relationship should have same label as group", group.Type(), relationship.Type());
                            degree.Loop++;
                        }

                        // then
                        assertNotEquals("all", 0, degree.Incoming + degree.Outgoing + degree.Loop);
                        assertEquals("node #" + node.NodeReference() + " outgoing", group.OutgoingCount(), degree.Outgoing);
                        assertEquals("node #" + node.NodeReference() + " incoming", group.IncomingCount(), degree.Incoming);
                        assertEquals("node #" + node.NodeReference() + " loop", group.LoopCount(), degree.Loop);
                        assertEquals("node #" + node.NodeReference() + " all = incoming + outgoing - loop", group.TotalCount(), degree.Incoming + degree.Outgoing + degree.Loop);
                    }
                    if (none)
                    {
                        empty++;
                    }
                }

                // then
                assertEquals("number of empty nodes", 1, empty);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAccessGroupsOfBareNode()
        public virtual void ShouldNotAccessGroupsOfBareNode()
        {
            // given
            using (NodeCursor node = cursors.allocateNodeCursor(), RelationshipGroupCursor group = cursors.allocateRelationshipGroupCursor())
            {
                // when
                read.singleNode(_bare, node);
                assertTrue("access node", node.Next());
                node.Relationships(group);

                // then
                assertFalse("access group", group.next());
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldManageRandomTraversals()
        public virtual void ShouldManageRandomTraversals()
        {
            // given
            try
            {
                using (NodeCursor node = cursors.allocateNodeCursor(), RelationshipGroupCursor group = cursors.allocateRelationshipGroupCursor(), RelationshipTraversalCursor relationship = cursors.allocateRelationshipTraversalCursor())
                {
                    for (int i = 0; i < N_TRAVERSALS; i++)
                    {
                        // when
                        long nodeId = _nodeIds[_random.Next(_nNodes)];
                        read.singleNode(nodeId, node);
                        assertTrue("access root node", node.Next());
                        node.Relationships(group);
                        assertFalse("single root", node.Next());

                        // then
                        while (group.next())
                        {
                            group.Incoming(relationship);
                            while (relationship.next())
                            {
                                assertEquals("incoming origin", nodeId, relationship.OriginNodeReference());
                                relationship.Neighbour(node);
                            }
                            group.Outgoing(relationship);
                            while (relationship.next())
                            {
                                assertEquals("outgoing origin", nodeId, relationship.OriginNodeReference());
                                relationship.Neighbour(node);
                            }
                            group.Loops(relationship);
                            while (relationship.next())
                            {
                                assertEquals("loop origin", nodeId, relationship.OriginNodeReference());
                                relationship.Neighbour(node);
                            }
                        }
                    }
                }
            }
            catch (Exception t)
            {
                throw new Exception("Failed with random seed " + _seed, t);
            }
        }
Пример #10
0
        private static void SetupAllDense(RelationshipDenseSelection denseSelection, CursorFactory cursors, NodeCursor node, int[] types)
        {
            RelationshipGroupCursor     groupCursor     = cursors.AllocateRelationshipGroupCursor();
            RelationshipTraversalCursor traversalCursor = cursors.AllocateRelationshipTraversalCursor();

            try
            {
                node.Relationships(groupCursor);
                denseSelection.All(groupCursor, traversalCursor, types);
            }
            catch (Exception t)
            {
                groupCursor.close();
                traversalCursor.close();
                throw t;
            }
        }