Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldVisitChangedNodes()
        public virtual void ShouldVisitChangedNodes()
        {
            // GIVEN
            int nodes  = 10;
            int typeId = 10;

            _cache           = new NodeRelationshipCache(NumberArrayFactory.HEAP, 2, 100, Base);
            _cache.NodeCount = nodes;
            for (long nodeId = 0; nodeId < nodes; nodeId++)
            {
                _cache.incrementCount(nodeId);
                if (Random.nextBoolean())
                {
                    _cache.incrementCount(nodeId);
                }
            }
            MutableLongSet keySparseChanged = new LongHashSet();
            MutableLongSet keyDenseChanged  = new LongHashSet();

            for (int i = 0; i < nodes / 2; i++)
            {
                long nodeId = Random.nextLong(nodes);
                _cache.getAndPutRelationship(nodeId, typeId, Direction.OUTGOING, Random.nextLong(1_000_000), false);
                bool dense = _cache.isDense(nodeId);
                (dense ? keyDenseChanged : keySparseChanged).add(nodeId);
            }

            {
                // WHEN (sparse)
                NodeChangeVisitor visitor = (nodeId, array) =>
                {
                    // THEN (sparse)
                    assertTrue("Unexpected sparse change reported for " + nodeId, keySparseChanged.remove(nodeId));
                };
                _cache.visitChangedNodes(visitor, NodeType.NODE_TYPE_SPARSE);
                assertTrue("There was " + keySparseChanged.size() + " expected sparse changes that weren't reported", keySparseChanged.Empty);
            }

            {
                // WHEN (dense)
                NodeChangeVisitor visitor = (nodeId, array) =>
                {
                    // THEN (dense)
                    assertTrue("Unexpected dense change reported for " + nodeId, keyDenseChanged.remove(nodeId));
                };
                _cache.visitChangedNodes(visitor, NodeType.NODE_TYPE_DENSE);
                assertTrue("There was " + keyDenseChanged.size() + " expected dense changes that weren reported", keyDenseChanged.Empty);
            }
        }
Beispiel #2
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));
            }
        }
Beispiel #3
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);
            }
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldResetCountAfterGetOnDenseNodes()
        public virtual void ShouldResetCountAfterGetOnDenseNodes()
        {
            // GIVEN
            _cache = new NodeRelationshipCache(NumberArrayFactory_Fields.AutoWithoutPagecache, 1, 100, Base);
            long nodeId = 0;
            int  typeId = 3;

            _cache.NodeCount = 1;
            _cache.incrementCount(nodeId);
            _cache.incrementCount(nodeId);
            _cache.getAndPutRelationship(nodeId, typeId, OUTGOING, 10, true);
            _cache.getAndPutRelationship(nodeId, typeId, OUTGOING, 12, true);
            assertTrue(_cache.isDense(nodeId));

            // WHEN
            long count = _cache.getCount(nodeId, typeId, OUTGOING);

            assertEquals(2, count);

            // THEN
            assertEquals(0, _cache.getCount(nodeId, typeId, OUTGOING));
        }
Beispiel #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailFastOnTooHighCountOnNode()
        public virtual void ShouldFailFastOnTooHighCountOnNode()
        {
            // GIVEN
            _cache = new NodeRelationshipCache(NumberArrayFactory.HEAP, 10, 100, Base);
            long nodeId = 5;
            long count  = NodeRelationshipCache.MaxCount - 1;
            int  typeId = 10;

            _cache.NodeCount = 10;
            _cache.setCount(nodeId, count, typeId, OUTGOING);

            // WHEN
            _cache.incrementCount(nodeId);
            try
            {
                _cache.incrementCount(nodeId);
                fail("Should have failed");
            }
            catch (System.InvalidOperationException)
            {
                // THEN Good
            }
        }
Beispiel #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHaveSparseNodesWithBigCounts()
        public virtual void ShouldHaveSparseNodesWithBigCounts()
        {
            // GIVEN
            _cache = new NodeRelationshipCache(NumberArrayFactory.HEAP, 1, 100, Base);
            long nodeId = 1;
            int  typeId = 10;

            _cache.NodeCount = nodeId + 1;

            // WHEN
            long highCount = NodeRelationshipCache.MaxCount - 100;

            _cache.setCount(nodeId, highCount, typeId, OUTGOING);
            long nextHighCount = _cache.incrementCount(nodeId);

            // THEN
            assertEquals(highCount + 1, nextHighCount);
        }
Beispiel #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPut6ByteRelationshipIds()
        public virtual void ShouldPut6ByteRelationshipIds()
        {
            // GIVEN
            _cache = new NodeRelationshipCache(NumberArrayFactory.HEAP, 1, 100, Base);
            long sparseNode     = 0;
            long denseNode      = 1;
            long relationshipId = (1L << 48) - 2;
            int  typeId         = 10;

            _cache.NodeCount = 2;
            _cache.incrementCount(denseNode);

            // WHEN
            assertEquals(-1L, _cache.getAndPutRelationship(sparseNode, typeId, OUTGOING, relationshipId, false));
            assertEquals(-1L, _cache.getAndPutRelationship(denseNode, typeId, OUTGOING, relationshipId, false));

            // THEN
            assertEquals(relationshipId, _cache.getAndPutRelationship(sparseNode, typeId, OUTGOING, 1, false));
            assertEquals(relationshipId, _cache.getAndPutRelationship(denseNode, typeId, OUTGOING, 1, false));
        }
Beispiel #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPutRandomStuff()
        public virtual void ShouldPutRandomStuff()
        {
            // GIVEN
            int typeId = 10;
            int nodes  = 10_000;
            MutableLongObjectMap <long[]> key = new LongObjectHashMap <long[]>(nodes);

            _cache = new NodeRelationshipCache(NumberArrayFactory.HEAP, 1, 1000, Base);

            // mark random nodes as dense (dense node threshold is 1 so enough with one increment
            _cache.NodeCount = nodes;
            for (long nodeId = 0; nodeId < nodes; nodeId++)
            {
                if (Random.nextBoolean())
                {
                    _cache.incrementCount(nodeId);
                }
            }

            // WHEN
            for (int i = 0; i < 100_000; i++)
            {
                long      nodeId         = Random.nextLong(nodes);
                bool      dense          = _cache.isDense(nodeId);
                Direction direction      = Random.among(Direction.values());
                long      relationshipId = Random.nextLong(1_000_000);
                long      previousHead   = _cache.getAndPutRelationship(nodeId, typeId, direction, relationshipId, false);
                long[]    keyIds         = key.get(nodeId);
                int       keyIndex       = dense ? direction.ordinal() : 0;
                if (keyIds == null)
                {
                    key.put(nodeId, keyIds = MinusOneLongs(Direction.values().length));
                }
                assertEquals(keyIds[keyIndex], previousHead);
                keyIds[keyIndex] = relationshipId;
            }
        }