Esempio n. 1
0
        private FileTimeSlice CreateSlice <TEntry, T>(string symbol, string column, long startTicks, long endTicks)
            where TEntry : unmanaged, IFieldEntry <T>
        {
            var slice = new FileTimeSlice {
                Start = new DateTime(startTicks), End = new DateTime(endTicks)
            };

            var fs     = new MinotaurFileStream(new[] { GetFileOffset(symbol, column, slice.Start, 0) });
            var cs     = new ColumnStream <TEntry>(fs, new VoidCodec <TEntry>());
            var blocks = cs.ReadBlockInfos();

            slice.Blocks = blocks.Sample <TEntry, T>(OPTIMAL_FILE_BLOCK_SLICE);

            cs.Dispose();
            fs.Dispose();
            return(slice);
        }
Esempio n. 2
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();
            }
        }