예제 #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);
            }
        }
예제 #2
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));
        }
예제 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReportCorrectNumberOfDenseNodes()
        public virtual void ShouldReportCorrectNumberOfDenseNodes()
        {
            // GIVEN
            _cache           = new NodeRelationshipCache(NumberArrayFactory_Fields.AutoWithoutPagecache, 5, 100, Base);
            _cache.NodeCount = 26;
            Increment(_cache, 2, 10);
            Increment(_cache, 5, 2);
            Increment(_cache, 7, 12);
            Increment(_cache, 23, 4);
            Increment(_cache, 24, 5);
            Increment(_cache, 25, 6);

            // THEN
            assertFalse(_cache.isDense(0));
            assertTrue(_cache.isDense(2));
            assertFalse(_cache.isDense(5));
            assertTrue(_cache.isDense(7));
            assertFalse(_cache.isDense(23));
            assertTrue(_cache.isDense(24));
            assertTrue(_cache.isDense(25));
        }
예제 #4
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;
            }
        }