示例#1
0
        public void GetBlockBoundsTest()
        {
            const int blockSize = 8192;

            var data = Factory.CreateDoubleChunk(blockSize / sizeof(DoubleEntry) * 21);

            var handle = GCHandle.Alloc(data, GCHandleType.Pinned);

            try
            {
                var stream = new ColumnStream <DoubleEntry>(
                    new MinotaurMemoryStream(),
                    new VoidCodec <DoubleEntry>(),
                    blockSize);

                var pdata = (byte *)handle.AddrOfPinnedObject();

                stream.Write(pdata, data.Length * sizeof(DoubleEntry));
                stream.Flush();

                stream.Reset();

                var blocks = stream.ReadBlockInfos();

                Assert.AreEqual(21, blocks.Count);
                for (int i = 0, j = 0; i < blocks.Count; i++)
                {
                    Assert.AreEqual(blocks[i].PayloadLength, blockSize);
                    Assert.AreEqual(blocks[i].DataLength, blockSize / sizeof(DoubleEntry));
                    Assert.AreEqual(blocks[i].ShellSize, sizeof(PayloadHeader) + 2 * sizeof(DoubleEntry) + sizeof(byte));
                    Assert.AreEqual(blocks[i].Version, 1);

                    Assert.AreEqual(blocks[i].FirstValue.ticks, data[j].ticks);
                    Assert.AreEqual(blocks[i].FirstValue.value, data[j].value);
                    j += blocks[i].DataLength;
                    Assert.AreEqual(blocks[i].LastValue.ticks, data[j - 1].ticks);
                    Assert.AreEqual(blocks[i].LastValue.value, data[j - 1].value);
                }
            }
            finally
            {
                handle.Free();
            }
        }
示例#2
0
        public void AddSignature(string name, int level, Action <Stream> action)
        {
            using (var update = new Update(session, Signatures, JET_prep.Insert))
            {
                Api.SetColumn(session, Signatures, tableColumnsCache.SignaturesColumns["name"], name, Encoding.Unicode);
                Api.SetColumn(session, Signatures, tableColumnsCache.SignaturesColumns["level"], level);
                Api.SetColumn(session, Signatures, tableColumnsCache.SignaturesColumns["created_at"], DateTime.UtcNow);

                using (var stream = new ColumnStream(session, Signatures, tableColumnsCache.SignaturesColumns["data"]))
                    using (var buffer = new BufferedStream(stream))
                    {
                        action(buffer);
                        buffer.Flush();
                        stream.Flush();
                    }

                update.Save();
            }
        }
示例#3
0
        public void GetSignatureStream(int id, int level, Action <Stream> action)
        {
            Api.JetSetCurrentIndex(session, Signatures, "by_id");
            Api.MakeKey(session, Signatures, id, MakeKeyGrbit.NewKey);
            Api.MakeKey(session, Signatures, level, MakeKeyGrbit.None);
            if (Api.TrySeek(session, Signatures, SeekGrbit.SeekEQ) == false)
            {
                throw new InvalidOperationException("Could not find signature with id " + id + " and level " + level);
            }


            using (var stream = new ColumnStream(session, Signatures, tableColumnsCache.SignaturesColumns["data"]))
                using (var buffer = new BufferedStream(stream))
                {
                    action(buffer);
                    buffer.Flush();
                    stream.Flush();
                }
        }
示例#4
0
 public override void Flush()
 {
     // не вызывает ESENT API, поэтому можно вызывать с любого треда
     _inlinedStream.Flush();
 }
示例#5
0
        public void ReadWriteWorkflowTest()
        {
            var ms = new MinotaurMemoryStream();

            const int bufferSize = 1024;
            var       wrapSize   = sizeof(PayloadHeader) + sizeof(byte) * 2 + sizeof(byte);
            var       bufferSizeWithoutWrapSize = bufferSize - wrapSize;
            const int fullBufferSize            = bufferSize * 5 + 512;

            var writeBuffer = new UnsafeBuffer(fullBufferSize);
            var readBuffer  = new UnsafeBuffer(fullBufferSize);

            writeBuffer.SetAll(2);
            readBuffer.SetAll(0);

            var stream = new ColumnStream <byte>(ms, new VoidCodec <byte>(), bufferSize);

            // 1. Test write less than buffer
            var write = 100;
            var wrote = stream.Write(writeBuffer.Ptr, write);

            wrote.Check(write);
            ms.Position.Check(0);

            stream.Flush();
            ms.Position.Check(write + wrapSize);

            ReadWf(stream, readBuffer, 2, write);

            // 2. Test write more than buffer
            writeBuffer.SetAll(2);
            stream.Reset();
            ms.SetLength(0);

            write = bufferSize * 4 + 512;
            wrote = stream.Write(writeBuffer.Ptr, write);
            wrote.Check(write);
            ms.Position.Check((bufferSize + wrapSize) * 4);

            stream.Flush();
            ms.Position.Check(write + 5 * wrapSize);

            ReadWf(stream, readBuffer, 2, write);

            // 2. Test write exactly buffer size
            writeBuffer.SetAllUntil(bufferSizeWithoutWrapSize, 2);
            stream.Reset();
            ms.SetLength(0);

            write = bufferSize;
            wrote = stream.Write(writeBuffer.Ptr, write);
            wrote.Check(write);
            ms.Position.Check(bufferSize + wrapSize);

            stream.Flush();
            ms.Position.Check(bufferSize + wrapSize);
            stream.Reset();

            ReadWf(stream, readBuffer, 2, write);

            stream.Dispose();
            writeBuffer.Dispose();
            readBuffer.Dispose();
        }