예제 #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);
            }
        }