Пример #1
0
//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);
                }
            }
        }
Пример #2
0
//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());
                    }
                }
            }
        }