//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void execute(GBPTree<KEY,VALUE> index) throws java.io.IOException public override void Execute(GBPTree <KEY, VALUE> index) { using (Writer <KEY, VALUE> writer = index.Writer()) { for (int i = 0; i < DataConflict.Length;) { writer.Put(outerInstance.key(DataConflict[i++]), outerInstance.value(DataConflict[i++])); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void execute(GBPTree<KEY,VALUE> index) throws java.io.IOException public override void Execute(GBPTree <KEY, VALUE> index) { using (Writer <KEY, VALUE> writer = index.Writer()) { for (int i = 0; i < DataConflict.Length;) { KEY key = key(DataConflict[i++]); i++; // value writer.Remove(key); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: protected void createStoreFile(java.io.File storeFile) throws java.io.IOException protected internal override void CreateStoreFile( File storeFile ) { IList<long> initialKeys = initialKeys(); PageCache pageCache = _pageCacheRule.getPageCache( GlobalFs.get() ); using ( GBPTree<MutableLong, MutableLong> tree = ( new GBPTreeBuilder<MutableLong, MutableLong>( pageCache, storeFile, Layout ) ).build() ) { using ( Writer<MutableLong, MutableLong> writer = tree.Writer() ) { foreach ( long? key in initialKeys ) { Put( writer, key.Value ); } } tree.Checkpoint( Org.Neo4j.Io.pagecache.IOLimiter_Fields.Unlimited ); } }
/* 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); } } } }
//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()); } } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void buildTree(org.neo4j.values.storable.Value[] values) throws java.io.IOException private void BuildTree(Value[] values) { using (GBPTree <NumberIndexKey, NativeIndexValue> gbpTree = Tree) { using (Writer <NumberIndexKey, NativeIndexValue> writer = gbpTree.Writer()) { NumberIndexKey key = Layout.newKey(); NativeIndexValue value = Layout.newValue(); long nodeId = 0; foreach (Value number in values) { key.initialize(nodeId); key.initFromValue(0, number, NEUTRAL); value.From(number); writer.Put(key, value); nodeId++; } } gbpTree.Checkpoint(Org.Neo4j.Io.pagecache.IOLimiter_Fields.Unlimited); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: void prepareIndex(GBPTree<KEY,VALUE> index, java.util.TreeSet<long> dataInIndex, java.util.Queue<long> toRemove, java.util.Queue<long> toAdd, java.util.Random random) throws java.io.IOException internal virtual void PrepareIndex(GBPTree <KEY, VALUE> index, SortedSet <long> dataInIndex, LinkedList <long> toRemove, LinkedList <long> toAdd, Random random) { IList <long> fullRange = LongStream.range(MinRange, MaxRange).boxed().collect(Collectors.toList()); IList <long> rangeOutOfOrder = ShuffleToNewList(fullRange, random); using (Writer <KEY, VALUE> writer = index.Writer()) { foreach (long?key in rangeOutOfOrder) { bool addForRemoval = random.NextDouble() > WritePercentage; if (addForRemoval) { writer.Put(key(key), outerInstance.value(key.Value)); dataInIndex.Add(key); toRemove.AddLast(key); } else { toAdd.AddLast(key); } } } }
//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()); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void mustStayCorrectWhenInsertingValuesOfIncreasingLength() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void MustStayCorrectWhenInsertingValuesOfIncreasingLength() { Layout <RawBytes, RawBytes> layout = layout(); using (GBPTree <RawBytes, RawBytes> index = CreateIndex(layout), Writer <RawBytes, RawBytes> writer = index.Writer()) { RawBytes emptyValue = layout.NewValue(); emptyValue.Bytes = new sbyte[0]; for (int keySize = 1; keySize < index.KeyValueSizeCap(); keySize++) { RawBytes key = layout.NewKey(); key.Bytes = new sbyte[keySize]; writer.Put(key, emptyValue); } } }
//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 Writer<KEY,VALUE> createWriter(GBPTree<KEY,VALUE> index) throws java.io.IOException private Writer <KEY, VALUE> CreateWriter(GBPTree <KEY, VALUE> index) { return(index.Writer(_ratioToKeepInLeftOnSplit)); }