コード例 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void verifyUniqueSeek(org.neo4j.cursor.RawCursor<org.neo4j.index.internal.gbptree.Hit<KEY,VALUE>,java.io.IOException> seek) throws java.io.IOException, org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
        private void VerifyUniqueSeek(RawCursor <Hit <KEY, VALUE>, IOException> seek)
        {
            if (seek != null)
            {
                if (seek.Next())
                {
                    long firstEntityId = seek.get().key().EntityId;
                    if (seek.Next())
                    {
                        long secondEntityId = seek.get().key().EntityId;
                        throw new IndexEntryConflictException(firstEntityId, secondEntityId, seek.get().key().asValues());
                    }
                }
            }
        }
コード例 #2
0
        public override AllEntriesLabelScanReader AllNodeLabelRanges()
        {
            System.Func <int, RawCursor <Hit <LabelScanKey, LabelScanValue>, IOException> > seekProvider = labelId =>
            {
                try
                {
                    return(_index.seek((new LabelScanKey()).Set(labelId, 0), (new LabelScanKey()).Set(labelId, long.MaxValue)));
                }
                catch (IOException e)
                {
                    throw new Exception(e);
                }
            };

            int highestLabelId = -1;

            try
            {
                using (RawCursor <Hit <LabelScanKey, LabelScanValue>, IOException> cursor = _index.seek((new LabelScanKey()).Set(int.MaxValue, long.MaxValue), (new LabelScanKey()).Set(0, -1)))
                {
                    if (cursor.Next())
                    {
                        highestLabelId = cursor.get().key().labelId;
                    }
                }
            }
            catch (IOException e)
            {
                throw new Exception(e);
            }
            return(new NativeAllEntriesLabelScanReader(seekProvider, highestLabelId));
        }
コード例 #3
0
        public override long CountIndexedNodes(long nodeId, int[] propertyKeyIds, params Value[] propertyValues)
        {
            KEY treeKeyFrom = Layout.newKey();
            KEY treeKeyTo   = Layout.newKey();

            treeKeyFrom.initialize(nodeId);
            treeKeyTo.initialize(nodeId);
            for (int i = 0; i < propertyValues.Length; i++)
            {
                treeKeyFrom.initFromValue(i, propertyValues[i], NEUTRAL);
                treeKeyTo.initFromValue(i, propertyValues[i], NEUTRAL);
            }
            try
            {
                using (RawCursor <Hit <KEY, VALUE>, IOException> seeker = Tree.seek(treeKeyFrom, treeKeyTo))
                {
                    long count = 0;
                    while (seeker.Next())
                    {
                        if (seeker.get().key().EntityId == nodeId)
                        {
                            count++;
                        }
                    }
                    return(count);
                }
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
        }
コード例 #4
0
ファイル: GBPTreeFormatTest.cs プロジェクト: Neo4Net/Neo4Net
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void assertHit(org.neo4j.cursor.RawCursor<Hit<org.apache.commons.lang3.mutable.MutableLong,org.apache.commons.lang3.mutable.MutableLong>,java.io.IOException> cursor, System.Nullable<long> expectedKey) throws java.io.IOException
		 private static void AssertHit( RawCursor<Hit<MutableLong, MutableLong>, IOException> cursor, long? expectedKey )
		 {
			  assertTrue( "Had no next when expecting key " + expectedKey, cursor.Next() );
			  Hit<MutableLong, MutableLong> hit = cursor.get();
			  assertEquals( expectedKey.Value, hit.Key().longValue() );
			  assertEquals( Value( expectedKey.Value ), hit.Value().longValue() );
		 }
コード例 #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: void perform(io.netty.channel.ChannelHandlerContext ctx) throws java.io.IOException
        internal virtual void Perform(ChannelHandlerContext ctx)
        {
            CheckPointer checkPointer   = _checkPointerSupplier.get();
            Resource     checkPointLock = _mutex.storeCopy(() => checkPointer.TryCheckPoint(new SimpleTriggerInfo("Store copy")));

            Future <Void> completion = null;

            try
            {
                using (RawCursor <StoreResource, IOException> resources = _resourceStreamFactory.create())
                {
                    while (resources.Next())
                    {
                        StoreResource resource = resources.get();
                        _protocol.stream(ctx, resource);
                    }
                    completion = _protocol.end(ctx, SUCCESS);
                }
            }
            finally
            {
                if (completion != null)
                {
                    completion.addListener(f => checkPointLock.close());
                }
                else
                {
                    checkPointLock.Close();
                }
            }
        }
コード例 #6
0
        public override IndexSample Result()
        {
            KEY lowest = _layout.newKey();

            lowest.initialize(long.MinValue);
            lowest.initValuesAsLowest();
            KEY highest = _layout.newKey();

            highest.initialize(long.MaxValue);
            highest.initValuesAsHighest();
            KEY prev = _layout.newKey();

            try
            {
                using (RawCursor <Hit <KEY, VALUE>, IOException> seek = _gbpTree.seek(lowest, highest))
                {
                    long sampledValues = 0;
                    long uniqueValues  = 0;

                    // Get the first one so that prev gets initialized
                    if (seek.Next())
                    {
                        prev = _layout.copyKey(seek.get().key(), prev);
                        sampledValues++;
                        uniqueValues++;

                        // Then do the rest
                        while (seek.Next())
                        {
                            Hit <KEY, VALUE> hit = seek.get();
                            if (_layout.compareValue(prev, hit.Key()) != 0)
                            {
                                uniqueValues++;
                                _layout.copyKey(hit.Key(), prev);
                            }
                            // else this is a duplicate of the previous one
                            sampledValues++;
                        }
                    }
                    return(new IndexSample(sampledValues, uniqueValues, sampledValues));
                }
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
        }
コード例 #7
0
ファイル: LargeDynamicKeysIT.cs プロジェクト: Neo4Net/Neo4Net
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void shouldWriteAndReadEntriesOfRandomSizes(int minKeySize, int maxKeySize, int minValueSize, int maxValueSize) throws java.io.IOException
        private void ShouldWriteAndReadEntriesOfRandomSizes(int minKeySize, int maxKeySize, int minValueSize, int maxValueSize)
        {
            // given
            using (GBPTree <RawBytes, RawBytes> tree = CreateIndex(Layout()))
            {
                // when
                ISet <string> generatedStrings             = new HashSet <string>();
                IList <Pair <RawBytes, RawBytes> > entries = new List <Pair <RawBytes, RawBytes> >();
                using (Writer <RawBytes, RawBytes> writer = tree.Writer())
                {
                    for (int i = 0; i < 1_000; i++)
                    {
                        // value, based on i
                        RawBytes value = new RawBytes();
                        value.Bytes = new sbyte[Random.Next(minValueSize, maxValueSize)];
                        Random.NextBytes(value.Bytes);

                        // key, randomly generated
                        string @string;
                        do
                        {
                            @string = Random.nextAlphaNumericString(minKeySize, maxKeySize);
                        } while (!generatedStrings.Add(@string));
                        RawBytes key = new RawBytes();
                        key.Bytes = UTF8.encode(@string);
                        entries.Add(Pair.of(key, value));

                        // write
                        writer.Put(key, value);
                    }
                }

                // then
                foreach (Pair <RawBytes, RawBytes> entry in entries)
                {
                    using (RawCursor <Hit <RawBytes, RawBytes>, IOException> seek = tree.Seek(entry.First(), entry.First()))
                    {
                        assertTrue(seek.Next());
                        assertArrayEquals(entry.First().Bytes, seek.get().key().bytes);
                        assertArrayEquals(entry.Other().Bytes, seek.get().value().bytes);
                        assertFalse(seek.Next());
                    }
                }
            }
        }
コード例 #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void scanAndVerifyDuplicates(org.neo4j.storageengine.api.NodePropertyAccessor nodePropertyAccessor, org.neo4j.storageengine.api.schema.StoreIndexDescriptor descriptor, org.neo4j.cursor.RawCursor<org.neo4j.index.internal.gbptree.Hit<SpatialIndexKey,NativeIndexValue>,java.io.IOException> seek) throws java.io.IOException, org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
        private static void ScanAndVerifyDuplicates(NodePropertyAccessor nodePropertyAccessor, StoreIndexDescriptor descriptor, RawCursor <Hit <SpatialIndexKey, NativeIndexValue>, IOException> seek)
        {
            LongArrayList nodesWithCollidingPoints = new LongArrayList();
            long          prevRawBits = long.MinValue;

            // Bootstrap starting state
            if (seek.Next())
            {
                Hit <SpatialIndexKey, NativeIndexValue> hit = seek.get();
                prevRawBits = hit.Key().RawValueBits;
                nodesWithCollidingPoints.add(hit.Key().EntityId);
            }

            while (seek.Next())
            {
                Hit <SpatialIndexKey, NativeIndexValue> hit = seek.get();
                SpatialIndexKey key            = hit.Key();
                long            currentRawBits = key.RawValueBits;
                long            currentNodeId  = key.EntityId;
                if (prevRawBits != currentRawBits)
                {
                    if (nodesWithCollidingPoints.size() > 1)
                    {
                        VerifyConstraintOn(nodesWithCollidingPoints, nodePropertyAccessor, descriptor);
                    }
                    nodesWithCollidingPoints.clear();
                }
                nodesWithCollidingPoints.add(currentNodeId);
                prevRawBits = currentRawBits;
            }

            // Verify the last batch if needed
            if (nodesWithCollidingPoints.size() > 1)
            {
                VerifyConstraintOn(nodesWithCollidingPoints, nodePropertyAccessor, descriptor);
            }
        }
コード例 #9
0
        /* Randomized tests */

//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSplitCorrectly() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSplitCorrectly()
        {
            // GIVEN
            using (GBPTree <KEY, VALUE> index = index())
            {
                // WHEN
                int         count = 1_000;
                IList <KEY> seen  = new List <KEY>(count);
                using (Writer <KEY, VALUE> writer = index.Writer())
                {
                    for (int i = 0; i < count; i++)
                    {
                        KEY key;
                        do
                        {
                            key = key(_random.Next(100_000));
                        } while (ListContains(seen, key));
                        VALUE value = value(i);
                        writer.Put(key, value);
                        seen.Add(key);
                    }
                }

                // THEN
                using (RawCursor <Hit <KEY, VALUE>, IOException> cursor = index.Seek(Key(0), Key(long.MaxValue)))
                {
                    long prev = -1;
                    while (cursor.Next())
                    {
                        KEY  hit     = cursor.get().key();
                        long hitSeed = _layout.keySeed(hit);
                        if (hitSeed < prev)
                        {
                            fail(hit + " smaller than prev " + prev);
                        }
                        prev = hitSeed;
                        assertTrue(RemoveFromList(seen, hit));
                    }

                    if (seen.Count > 0)
                    {
                        fail("expected hits " + seen);
                    }
                }
            }
        }
コード例 #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") @Test public void shouldFindMultipleNodesInEachRange() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFindMultipleNodesInEachRange()
        {
            // GIVEN
            GBPTree <LabelScanKey, LabelScanValue> index = mock(typeof(GBPTree));
            RawCursor <Hit <LabelScanKey, LabelScanValue>, IOException> cursor = mock(typeof(RawCursor));

            when(cursor.Next()).thenReturn(true, true, true, false);
            when(cursor.get()).thenReturn(Hit(0, 0b1000_1000__1100_0010L), Hit(1, 0b0000_0010__0000_1000L), Hit(3, 0b0010_0000__1010_0001L), null);
            when(index.Seek(any(typeof(LabelScanKey)), any(typeof(LabelScanKey)))).thenReturn(cursor);
            using (NativeLabelScanReader reader = new NativeLabelScanReader(index))
            {
                // WHEN
                LongIterator iterator = reader.NodesWithLabel(LABEL_ID);

                // THEN
                assertArrayEquals(new long[] { 1, 6, 7, 11, 15, 64 + 3, 64 + 9, 192 + 0, 192 + 5, 192 + 7, 192 + 13 }, asArray(iterator));
            }
        }
コード例 #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldStartFromGivenId() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldStartFromGivenId()
        {
            // given
            GBPTree <LabelScanKey, LabelScanValue> index = mock(typeof(GBPTree));
            RawCursor <Hit <LabelScanKey, LabelScanValue>, IOException> cursor = mock(typeof(RawCursor));

            when(cursor.Next()).thenReturn(true, true, false);
            when(cursor.get()).thenReturn(Hit(1, 0b0001_1000__0101_1110L), Hit(3, 0b0010_0000__1010_0001L), null);
            when(index.Seek(any(typeof(LabelScanKey)), any(typeof(LabelScanKey)))).thenReturn(cursor);

            // when
            long fromId = LabelScanValue.RangeSize + 3;

            using (NativeLabelScanReader reader = new NativeLabelScanReader(index), PrimitiveLongResourceIterator iterator = reader.NodesWithAnyOfLabels(fromId, LABEL_ID))
            {
                // then
                assertArrayEquals(new long[] { 64 + 4, 64 + 6, 64 + 11, 64 + 12, 192 + 0, 192 + 5, 192 + 7, 192 + 13 }, asArray(iterator));
            }
        }
コード例 #12
0
ファイル: NativeHitIterator.cs プロジェクト: Neo4Net/Neo4Net
 protected internal override bool FetchNext()
 {
     try
     {
         while (_seeker.next())
         {
             KEY key = _seeker.get().key();
             if (AcceptValues(key.asValues()))
             {
                 return(next(key.EntityId));
             }
         }
         return(false);
     }
     catch (IOException e)
     {
         throw new UncheckedIOException(e);
     }
 }
コード例 #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRecoverFromCrashBeforeFirstCheckpoint() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRecoverFromCrashBeforeFirstCheckpoint()
        {
            // GIVEN
            // a tree with only small amount of data that has not yet seen checkpoint from outside
            KEY   key   = key(1L);
            VALUE value = value(10L);
            File  file  = _directory.file("index");

            {
                using (PageCache pageCache = CreatePageCache(), GBPTree <KEY, VALUE> index = CreateIndex(pageCache, file), Writer <KEY, VALUE> writer = index.Writer())
                {
                    writer.Put(key, value);
                    pageCache.FlushAndForce();
                    // No checkpoint
                }
            }

            // WHEN
            using (PageCache pageCache = CreatePageCache(), GBPTree <KEY, VALUE> index = CreateIndex(pageCache, file))
            {
                using (Writer <KEY, VALUE> writer = index.Writer())
                {
                    writer.Put(key, value);
                }

                // THEN
                // we should end up with a consistent index
                index.ConsistencyCheck();

                // ... containing all the stuff load says
                using (RawCursor <Hit <KEY, VALUE>, IOException> cursor = index.Seek(key(long.MinValue), key(long.MaxValue)))
                {
                    assertTrue(cursor.Next());
                    Hit <KEY, VALUE> hit = cursor.get();
                    AssertEqualsKey(key, hit.Key());
                    AssertEqualsValue(value, hit.Value());
                }
            }
        }
コード例 #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSeeSimpleInsertions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSeeSimpleInsertions()
        {
            using (GBPTree <KEY, VALUE> index = index())
            {
                int count = 1000;
                using (Writer <KEY, VALUE> writer = index.Writer())
                {
                    for (int i = 0; i < count; i++)
                    {
                        writer.Put(Key(i), Value(i));
                    }
                }

                using (RawCursor <Hit <KEY, VALUE>, IOException> cursor = index.Seek(Key(0), Key(long.MaxValue)))
                {
                    for (int i = 0; i < count; i++)
                    {
                        assertTrue(cursor.Next());
                        AssertEqualsKey(Key(i), cursor.get().key());
                    }
                    assertFalse(cursor.Next());
                }
            }
        }
コード例 #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldStreamResources() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldStreamResources()
        {
            // given
            StoreFileStreamingProtocol protocol = new StoreFileStreamingProtocol();
            ChannelHandlerContext      ctx      = mock(typeof(ChannelHandlerContext));

            Fs.mkdir(new File("dirA"));
            Fs.mkdir(new File("dirB"));

            string[] files = new string[] { "dirA/one", "dirA/two", "dirB/one", "dirB/two", "one", "two", "three" };

            IList <StoreResource> resourceList = new List <StoreResource>();

            foreach (string file in files)
            {
                resourceList.Add(CreateResource(new File(file), ThreadLocalRandom.current().Next(1, 4096)));
            }
            RawCursor <StoreResource, IOException> resources = rawCursorOf(resourceList);

            // when
            while (resources.Next())
            {
                protocol.Stream(ctx, resources.get());
            }

            // then
            InOrder inOrder = Mockito.inOrder(ctx);

            foreach (StoreResource resource in resourceList)
            {
                inOrder.verify(ctx).write(ResponseMessageType.FILE);
                inOrder.verify(ctx).write(new FileHeader(resource.Path(), resource.RecordSize()));
                inOrder.verify(ctx).write(new FileSender(resource));
            }
            verifyNoMoreInteractions(ctx);
        }
コード例 #16
0
        public override IEnumerator <NodeLabelRange> Iterator()
        {
            try
            {
                long lowestRange = long.MaxValue;
                CloseCursors();
                for (int labelId = 0; labelId <= _highestLabelId; labelId++)
                {
                    RawCursor <Hit <LabelScanKey, LabelScanValue>, IOException> cursor = _seekProvider.apply(labelId);

                    // Bootstrap the cursor, which also provides a great opportunity to exclude if empty
                    if (cursor.Next())
                    {
                        lowestRange = min(lowestRange, cursor.get().key().idRange);
                        _cursors.Add(cursor);
                    }
                }
                return(new NodeLabelRangeIterator(this, lowestRange));
            }
            catch (IOException e)
            {
                throw new Exception(e);
            }
        }
コード例 #17
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void doRead() throws java.io.IOException
            internal virtual void DoRead()
            {
                ReaderInstruction  readerInstruction = TestCoordinator.get();
                IEnumerator <long> expectToSee       = readerInstruction.ExpectToSee().GetEnumerator();
                long start   = readerInstruction.Start();
                long end     = readerInstruction.End();
                bool forward = start <= end;

                using (RawCursor <Hit <KEY, VALUE>, IOException> cursor = outerInstance.index.Seek(outerInstance.key(start), outerInstance.key(end)))
                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                    if (expectToSee.hasNext())
                    {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                        long nextToSee = expectToSee.next();
                        while (cursor.Next())
                        {
                            // Actual
                            long lastSeenKey   = outerInstance.keySeed(cursor.get().key());
                            long lastSeenValue = outerInstance.valueSeed(cursor.get().value());

                            if (lastSeenKey != lastSeenValue)
                            {
//JAVA TO C# CONVERTER TODO TASK: The following line has a Java format specifier which cannot be directly translated to .NET:
//ORIGINAL LINE: fail(String.format("Read mismatching key value pair, key=%d, value=%d%n", lastSeenKey, lastSeenValue));
                                fail(string.Format("Read mismatching key value pair, key=%d, value=%d%n", lastSeenKey, lastSeenValue));
                            }

                            while ((forward && lastSeenKey > nextToSee) || (!forward && lastSeenKey < nextToSee))
                            {
                                if (TestCoordinator.isReallyExpected(nextToSee))
                                {
                                    fail(string.Format("Expected to see {0:D} but went straight to {1:D}. ", nextToSee, lastSeenKey));
                                }
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                if (expectToSee.hasNext())
                                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                    nextToSee = expectToSee.next();
                                }
                                else
                                {
                                    break;
                                }
                            }
                            if (nextToSee == lastSeenKey)
                            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                if (expectToSee.hasNext())
                                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                    nextToSee = expectToSee.next();
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
コード例 #18
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void doShouldRecoverFromAnything(boolean replayRecoveryExactlyFromCheckpoint) throws Exception
        private void DoShouldRecoverFromAnything(bool replayRecoveryExactlyFromCheckpoint)
        {
            AssertInitialized();
            // GIVEN
            // a tree which has had random updates and checkpoints in it, load generated with specific seed
            File           file                = _directory.file("index");
            IList <Action> load                = GenerateLoad();
            IList <Action> shuffledLoad        = RandomCausalAwareShuffle(load);
            int            lastCheckPointIndex = IndexOfLastCheckpoint(load);

            {
                // _,_,_,_,_,_,_,c,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,c,_,_,_,_,_,_,_,_,_,_,_
                //                                                 ^             ^
                //                                                 |             |------------ crash flush index
                //                                                 |-------------------------- last checkpoint index
                //

                PageCache            pageCache = CreatePageCache();
                GBPTree <KEY, VALUE> index     = CreateIndex(pageCache, file);
                // Execute all actions up to and including last checkpoint ...
                Execute(shuffledLoad.subList(0, lastCheckPointIndex + 1), index);
                // ... a random amount of the remaining "unsafe" actions ...
                int numberOfRemainingActions = shuffledLoad.Count - lastCheckPointIndex - 1;
                int crashFlushIndex          = lastCheckPointIndex + _random.Next(numberOfRemainingActions) + 1;
                Execute(shuffledLoad.subList(lastCheckPointIndex + 1, crashFlushIndex), index);
                // ... flush ...
                pageCache.FlushAndForce();
                // ... execute the remaining actions
                Execute(shuffledLoad.subList(crashFlushIndex, shuffledLoad.Count), index);
                // ... and finally crash
                _fs.snapshot(throwing(() =>
                {
                    index.Dispose();
                    pageCache.Close();
                }));
            }

            // WHEN doing recovery
            IList <Action> recoveryActions;

            if (replayRecoveryExactlyFromCheckpoint)
            {
                recoveryActions = recoveryActions(load, lastCheckPointIndex + 1);
            }
            else
            {
                recoveryActions = recoveryActions(load, _random.Next(lastCheckPointIndex + 1));
            }

            // first crashing during recovery
            int numberOfCrashesDuringRecovery = _random.intBetween(0, 3);

            for (int i = 0; i < numberOfCrashesDuringRecovery; i++)
            {
                using (PageCache pageCache = CreatePageCache(), GBPTree <KEY, VALUE> index = CreateIndex(pageCache, file))
                {
                    int numberOfActionsToRecoverBeforeCrashing = _random.intBetween(1, recoveryActions.Count);
                    Recover(recoveryActions.subList(0, numberOfActionsToRecoverBeforeCrashing), index);
                    // ... crash
                }
            }

            // to finally apply all actions after last checkpoint and verify tree
            using (PageCache pageCache = CreatePageCache(), GBPTree <KEY, VALUE> index = CreateIndex(pageCache, file))
            {
                Recover(recoveryActions, index);

                // THEN
                // we should end up with a consistent index containing all the stuff load says
                index.ConsistencyCheck();
                long[] aggregate = ExpectedSortedAggregatedDataFromGeneratedLoad(load);
                using (RawCursor <Hit <KEY, VALUE>, IOException> cursor = index.Seek(Key(long.MinValue), Key(long.MaxValue)))
                {
                    for (int i = 0; i < aggregate.Length;)
                    {
                        assertTrue(cursor.Next());
                        Hit <KEY, VALUE> hit = cursor.get();
                        AssertEqualsKey(Key(aggregate[i++]), hit.Key());
                        AssertEqualsValue(Value(aggregate[i++]), hit.Value());
                    }
                    assertFalse(cursor.Next());
                }
            }
        }
コード例 #19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldStayCorrectAfterRandomModifications() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldStayCorrectAfterRandomModifications()
        {
            // GIVEN
            using (GBPTree <KEY, VALUE> index = CreateIndex())
            {
                IComparer <KEY>          keyComparator = _layout;
                IDictionary <KEY, VALUE> data          = new SortedDictionary <KEY, VALUE>(keyComparator);
                int count = 100;
                int totalNumberOfRounds = 10;
                for (int i = 0; i < count; i++)
                {
                    data[RandomKey(Random.random())] = RandomValue(Random.random());
                }

                // WHEN
                using (Writer <KEY, VALUE> writer = CreateWriter(index))
                {
                    foreach (KeyValuePair <KEY, VALUE> entry in data.SetOfKeyValuePairs())
                    {
                        writer.Put(entry.Key, entry.Value);
                    }
                }

                for (int round = 0; round < totalNumberOfRounds; round++)
                {
                    // THEN
                    for (int i = 0; i < count; i++)
                    {
                        KEY first  = RandomKey(Random.random());
                        KEY second = RandomKey(Random.random());
                        KEY from;
                        KEY to;
                        if (_layout.keySeed(first) < _layout.keySeed(second))
                        {
                            from = first;
                            to   = second;
                        }
                        else
                        {
                            from = second;
                            to   = first;
                        }
                        IDictionary <KEY, VALUE> expectedHits = expectedHits(data, from, to, keyComparator);
                        using (RawCursor <Hit <KEY, VALUE>, IOException> result = index.Seek(from, to))
                        {
                            while (result.Next())
                            {
                                KEY key = result.get().key();
                                if (expectedHits.Remove(key) == null)
                                {
                                    fail("Unexpected hit " + key + " when searching for " + from + " - " + to);
                                }

                                assertTrue(keyComparator.Compare(key, from) >= 0);
                                if (keyComparator.Compare(from, to) != 0)
                                {
                                    assertTrue(keyComparator.Compare(key, to) < 0);
                                }
                            }
                            if (expectedHits.Count > 0)
                            {
                                fail("There were results which were expected to be returned, but weren't:" + expectedHits + " when searching range " + from + " - " + to);
                            }
                        }
                    }

                    index.Checkpoint(Org.Neo4j.Io.pagecache.IOLimiter_Fields.Unlimited);
                    RandomlyModifyIndex(index, data, Random.random(), (double)round / totalNumberOfRounds);
                }

                // and finally
                index.ConsistencyCheck();
            }
        }