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); }
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(); }