//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleRemoveEntireTree() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleRemoveEntireTree() { // given using (GBPTree <KEY, VALUE> index = CreateIndex()) { int numberOfNodes = 200_000; using (Writer <KEY, VALUE> writer = CreateWriter(index)) { for (int i = 0; i < numberOfNodes; i++) { writer.Put(Key(i), Value(i)); } } // when BitArray removed = new BitArray(); using (Writer <KEY, VALUE> writer = CreateWriter(index)) { for (int i = 0; i < numberOfNodes - numberOfNodes / 10; i++) { int candidate; do { candidate = Random.Next(max(1, Random.Next(numberOfNodes))); } while (removed.Get(candidate)); removed.Set(candidate, true); writer.Remove(Key(candidate)); } } int next = 0; using (Writer <KEY, VALUE> writer = CreateWriter(index)) { for (int i = 0; i < numberOfNodes / 10; i++) { next = removed.nextClearBit(next); removed.Set(next, true); writer.Remove(Key(next)); } } // then using (RawCursor <Hit <KEY, VALUE>, IOException> seek = index.Seek(Key(0), Key(numberOfNodes))) { assertFalse(seek.Next()); } // and finally index.ConsistencyCheck(); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void verifyContent(java.io.File storeFile) throws java.io.IOException public override void VerifyContent( File storeFile ) { PageCache pageCache = _pageCacheRule.getPageCache( GlobalFs.get() ); using ( GBPTree<MutableLong, MutableLong> tree = ( new GBPTreeBuilder<MutableLong, MutableLong>( pageCache, storeFile, Layout ) ).build() ) { { // WHEN reading from the tree // THEN initial keys should be there tree.ConsistencyCheck(); using ( RawCursor<Hit<MutableLong, MutableLong>, IOException> cursor = tree.Seek( Layout.key( 0 ), Layout.key( long.MaxValue ) ) ) { foreach ( long? expectedKey in _initialKeys ) { AssertHit( cursor, expectedKey ); } assertFalse( cursor.Next() ); } } { // WHEN writing more to the tree // THEN we should not see any format conflicts using ( Writer<MutableLong, MutableLong> writer = tree.Writer() ) { while ( _keysToAdd.Count > 0 ) { int next = _random.Next( _keysToAdd.Count ); Put( writer, _keysToAdd[next] ); _keysToAdd.RemoveAt( next ); } } } { // WHEN reading from the tree again // THEN all keys including newly added should be there tree.ConsistencyCheck(); using ( RawCursor<Hit<MutableLong, MutableLong>, IOException> cursor = tree.Seek( Layout.key( 0 ), Layout.key( 2 * INITIAL_KEY_COUNT ) ) ) { foreach ( long? expectedKey in _allKeys ) { AssertHit( cursor, expectedKey ); } assertFalse( cursor.Next() ); } } { // WHEN randomly removing half of tree content // THEN we should not see any format conflicts using ( Writer<MutableLong, MutableLong> writer = tree.Writer() ) { int size = _allKeys.Count; while ( _allKeys.Count > size / 2 ) { int next = _random.Next( _allKeys.Count ); MutableLong key = Layout.key( _allKeys[next] ); writer.Remove( key ); _allKeys.RemoveAt( next ); } } } { // WHEN reading from the tree after remove // THEN we should see everything that is left in the tree tree.ConsistencyCheck(); using ( RawCursor<Hit<MutableLong, MutableLong>, IOException> cursor = tree.Seek( Layout.key( 0 ), Layout.key( 2 * INITIAL_KEY_COUNT ) ) ) { foreach ( long? expectedKey in _allKeys ) { AssertHit( cursor, expectedKey ); } assertFalse( cursor.Next() ); } } } }
//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()); } } }
//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(); } }