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