예제 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldObserveFirstRelationshipAsEmptyInEachDirection()
        public virtual void ShouldObserveFirstRelationshipAsEmptyInEachDirection()
        {
            // GIVEN
            _cache = new NodeRelationshipCache(NumberArrayFactory_Fields.AutoWithoutPagecache, 1, 100, Base);
            int nodes  = 100;
            int typeId = 5;

            Direction[]  directions   = Direction.values();
            GroupVisitor groupVisitor = mock(typeof(GroupVisitor));

            _cache.setForwardScan(true, true);
            _cache.NodeCount = nodes + 1;
            for (int i = 0; i < nodes; i++)
            {
                assertEquals(-1L, _cache.getFirstRel(nodes, groupVisitor));
                _cache.incrementCount(i);
                long previous = _cache.getAndPutRelationship(i, typeId, directions[i % directions.Length], Random.Next(1_000_000), true);
                assertEquals(-1L, previous);
            }

            // WHEN
            _cache.setForwardScan(false, true);
            for (int i = 0; i < nodes; i++)
            {
                long previous = _cache.getAndPutRelationship(i, typeId, directions[i % directions.Length], Random.Next(1_000_000), false);
                assertEquals(-1L, previous);
            }

            // THEN
            _cache.setForwardScan(true, true);
            for (int i = 0; i < nodes; i++)
            {
                assertEquals(-1L, _cache.getFirstRel(nodes, groupVisitor));
            }
        }
예제 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldKeepNextGroupIdForNextRound()
        public virtual void ShouldKeepNextGroupIdForNextRound()
        {
            // GIVEN
            _cache = new NodeRelationshipCache(NumberArrayFactory.HEAP, 1, 100, Base);
            long nodeId = 0;
            int  typeId = 10;

            _cache.NodeCount = nodeId + 1;
            _cache.incrementCount(nodeId);
            GroupVisitor groupVisitor = mock(typeof(GroupVisitor));

            when(groupVisitor.Visit(anyLong(), anyInt(), anyLong(), anyLong(), anyLong())).thenReturn(1L, 2L, 3L);

            long firstRelationshipGroupId;
            {
                // WHEN importing the first type
                long relationshipId = 10;
                _cache.getAndPutRelationship(nodeId, typeId, OUTGOING, relationshipId, true);
                firstRelationshipGroupId = _cache.getFirstRel(nodeId, groupVisitor);

                // THEN
                assertEquals(1L, firstRelationshipGroupId);
                verify(groupVisitor).visit(nodeId, typeId, relationshipId, -1L, -1L);

                // Also simulate going back again ("clearing" of the cache requires this)
                _cache.setForwardScan(false, true);
                _cache.getAndPutRelationship(nodeId, typeId, OUTGOING, relationshipId, false);
                _cache.setForwardScan(true, true);
            }

            long secondRelationshipGroupId;
            {
                // WHEN importing the second type
                long relationshipId = 11;
                _cache.getAndPutRelationship(nodeId, typeId, INCOMING, relationshipId, true);
                secondRelationshipGroupId = _cache.getFirstRel(nodeId, groupVisitor);

                // THEN
                assertEquals(2L, secondRelationshipGroupId);
                verify(groupVisitor).visit(nodeId, typeId, -1, relationshipId, -1L);

                // Also simulate going back again ("clearing" of the cache requires this)
                _cache.setForwardScan(false, true);
                _cache.getAndPutRelationship(nodeId, typeId, OUTGOING, relationshipId, false);
                _cache.setForwardScan(true, true);
            }

            {
                // WHEN importing the third type
                long relationshipId = 10;
                _cache.getAndPutRelationship(nodeId, typeId, BOTH, relationshipId, true);
                long thirdRelationshipGroupId = _cache.getFirstRel(nodeId, groupVisitor);
                assertEquals(3L, thirdRelationshipGroupId);
                verify(groupVisitor).visit(nodeId, typeId, -1L, -1L, relationshipId);
            }
        }