Esempio n. 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldVisitUnacquiredIds() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldVisitUnacquiredIds()
        {
            // GIVEN a couple of released ids
            MutableLongSet expected = new LongHashSet();

            for (int i = 0; i < 100; i++)
            {
                expected.add(_freelist.acquireNewId(GENERATION_ONE, _generationTwo));
            }
            expected.forEach(id =>
            {
                try
                {
                    _freelist.releaseId(GENERATION_ONE, _generationTwo, id);
                }
                catch (IOException e)
                {
                    throw new Exception(e);
                }
            });
            // and only a few acquired
            for (int i = 0; i < 10; i++)
            {
                long acquiredId = _freelist.acquireNewId(_generationTwo, _generationThree);
                assertTrue(expected.remove(acquiredId));
            }

            // WHEN/THEN
            _freelist.visitFreelist(new IdProvider_IdProviderVisitor_AdaptorAnonymousInnerClass(this, expected));
            assertTrue(expected.Empty);
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldPutFreedFreeListPagesIntoFreeListAsWell() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldPutFreedFreeListPagesIntoFreeListAsWell()
        {
            // GIVEN
            long           prevId;
            long           acquiredId     = BASE_ID + 1;
            long           freelistPageId = BASE_ID + 1;
            MutableLongSet released       = new LongHashSet();

            do
            {
                prevId     = acquiredId;
                acquiredId = _freelist.acquireNewId(GENERATION_ONE, _generationTwo);
                _freelist.releaseId(GENERATION_ONE, _generationTwo, acquiredId);
                released.add(acquiredId);
            } while (acquiredId - prevId == 1);

            // WHEN
            while (!released.Empty)
            {
                long reAcquiredId = _freelist.acquireNewId(_generationTwo, _generationThree);
                released.remove(reAcquiredId);
            }

            // THEN
            assertEquals(freelistPageId, _freelist.acquireNewId(_generationThree, _generationFour));
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void scanningRecordsShouldVisitEachInUseRecordOnce() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ScanningRecordsShouldVisitEachInUseRecordOnce()
        {
            // GIVEN we have a NodeStore with data that spans several pages...
            EphemeralFileSystemAbstraction fs = _efs.get();

            _nodeStore = NewNodeStore(fs);

            ThreadLocalRandom rng = ThreadLocalRandom.current();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.set.primitive.MutableLongSet nextRelSet = new org.eclipse.collections.impl.set.mutable.primitive.LongHashSet();
            MutableLongSet nextRelSet = new LongHashSet();

            for (int i = 0; i < 10_000; i++)
            {
                // Enough records to span several pages
                int nextRelCandidate = rng.Next(0, int.MaxValue);
                if (nextRelSet.add(nextRelCandidate))
                {
                    long       nodeId = _nodeStore.nextId();
                    NodeRecord record = new NodeRecord(nodeId, false, nextRelCandidate, 20, true);
                    _nodeStore.updateRecord(record);
                    if (rng.Next(0, 10) < 3)
                    {
                        nextRelSet.remove(nextRelCandidate);
                        record.InUse = false;
                        _nodeStore.updateRecord(record);
                    }
                }
            }

            // ...WHEN we now have an interesting set of node records, and we
            // visit each and remove that node from our nextRelSet...

            Visitor <NodeRecord, IOException> scanner = record =>
            {
                // ...THEN we should observe that no nextRel is ever removed twice...
                assertTrue(nextRelSet.remove(record.NextRel));
                return(false);
            };

            _nodeStore.scanAllRecords(scanner);

            // ...NOR do we have anything left in the set afterwards.
            assertTrue(nextRelSet.Empty);
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldStayBoundUnderStress() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldStayBoundUnderStress()
        {
            // GIVEN
            MutableLongSet acquired           = new LongHashSet();
            IList <long>   acquiredList       = new List <long>();     // for quickly finding random to remove
            long           stableGeneration   = GenerationSafePointer.MIN_GENERATION;
            long           unstableGeneration = stableGeneration + 1;
            int            iterations         = 100;

            // WHEN
            for (int i = 0; i < iterations; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (_random.nextBoolean())
                    {
                        // acquire
                        int count = _random.intBetween(5, 10);
                        for (int k = 0; k < count; k++)
                        {
                            long acquiredId = _freelist.acquireNewId(stableGeneration, unstableGeneration);
                            assertTrue(acquired.add(acquiredId));
                            acquiredList.Add(acquiredId);
                        }
                    }
                    else
                    {
                        // release
                        int count = _random.intBetween(5, 20);
                        for (int k = 0; k < count && !acquired.Empty; k++)
                        {
                            long id = acquiredList.RemoveAt(_random.Next(acquiredList.Count));
                            assertTrue(acquired.remove(id));
                            _freelist.releaseId(stableGeneration, unstableGeneration, id);
                        }
                    }
                }

                foreach (long id in acquiredList)
                {
                    _freelist.releaseId(stableGeneration, unstableGeneration, id);
                }
                acquiredList.Clear();
                acquired.clear();

                // checkpoint, sort of
                stableGeneration = unstableGeneration;
                unstableGeneration++;
            }

            // THEN
            assertTrue(_freelist.lastId() < 200, _freelist.lastId().ToString());
        }
Esempio n. 5
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);
            }
        }