Beispiel #1
0
 internal SSTableBuilder(Stream stream, PlaneDBOptions options)
 {
     writer     = new BlockWriteOnceStream(stream, options.BlockTransformer);
     comparer   = options.Comparer;
     fullySync  = options.MaxJournalActions < 0;
     dictionary = new SortedList <byte[], byte[]?>(comparer);
 }
Beispiel #2
0
        private static void BlockStreamWriterOnceTest(IBlockTransformer transformer, IBlockCache cache)
        {
            using var ms = new KeepOpenMemoryStream();
            const int COUNT = 100_000;

            long expectedLength;

            using (var writer = new BlockWriteOnceStream(ms, transformer)) {
                using var binaryWriter = new BinaryWriter(writer, Encoding.ASCII, true);
                for (var i = 0; i < COUNT; ++i)
                {
                    binaryWriter.Write(i);
                }

                writer.Write(new byte[1 << 22]);
                expectedLength = writer.Length;
            }

            using (var writer = new BlockReadOnlyStream(ms, transformer, cache: cache)) {
                Assert.AreEqual(expectedLength, writer.Length);
                using var binaryReader       = new BinaryReader(writer, Encoding.ASCII, true);
                using var binaryCursorReader = new BinaryReader(writer.CreateCursor(), Encoding.ASCII, true);
                for (var i = 0; i < COUNT; ++i)
                {
                    Assert.AreEqual(i, binaryReader.ReadInt32());
                    Assert.AreEqual(i, binaryCursorReader.ReadInt32());
                }

                var buf = new byte[1 << 22];
                Assert.AreEqual(buf.Length, writer.Read(buf));
                Assert.IsTrue(buf.All(i => i == 0));
            }
        }