public void Append_returns_index() { var layout = new byte[50]; var block = new Block(layout); Assert.That(block.Append(BitConverter.GetBytes(1111)), Is.EqualTo(0)); Assert.That(block.Append(BitConverter.GetBytes(2222)), Is.EqualTo(4)); }
public void BlockFullException_when_full() { var layout = new byte[10]; var block = new Block(layout); Assert.Throws<BlockFullException>(() => { block.Append(BitConverter.GetBytes(1111)); block.Append(BitConverter.GetBytes(7777)); }); }
public HotSegment(long capacity, List<Block> blocks) { _capacity = capacity; Blocks = blocks; if (blocks.Count > 0) _current = blocks.Last(); else { _current = Block.New(); Blocks.Add(_current); } }
public void Burn(Block current, int count) { var blockLength = current.Payload.Length; var offset = blockLength * (count - 1); if (_fsSegment.Position != offset) { _fsSegment.Seek(offset, SeekOrigin.Begin); } _fsSegment.Write(current.Payload, 0, blockLength); _fsSegment.Flush(true); //Console.WriteLine("Burn [{0}] {1}", count, Path); }
public IEnumerable<Block> FetchForward() { Reader.BaseStream.Position = 0; Console.WriteLine("Fetch file#{0} {1}", Position, Name); var blockBuffer = new byte[Units.KILO * 4]; while (Reader.Read(blockBuffer, 0, blockBuffer.Length) > 0) { var block = new Block(blockBuffer.ToArray()); if (block.Records().Count == 0) break; yield return block; } }
public void Format_Payload_and_Size() { var layout = new byte[50]; var block = new Block(layout); block.Append(BitConverter.GetBytes(1111)); block.Append(Encoding.UTF8.GetBytes("hello this is very cool")); Assert.That(BitConverter.ToInt32(layout, 0), Is.EqualTo(1111)); Assert.That(BitConverter.ToInt32(layout, 46), Is.EqualTo(4)); Assert.That(BitConverter.ToInt32(layout, 42), Is.EqualTo(23)); }
public void EmptyBlockTest() { var block = new Block(new byte[] {}); Assert.That(block.Records().Count, Is.EqualTo(0)); }
public void Size_tracking() { var layout = new byte[50]; var block = new Block(layout); block.Append(BitConverter.GetBytes(1111)); block.Append(BitConverter.GetBytes(1111)); Assert.That(BitConverter.ToInt32(layout, 42), Is.EqualTo(4)); Assert.That(BitConverter.ToInt32(layout, 46), Is.EqualTo(4)); }
public void Parse_3_Records() { var layout = new byte[50]; var idx = layout.Length - 4; var first = BitConverter.GetBytes(1111); Array.Copy(first, 0, layout, idx, 4); idx = idx - 4; var second = BitConverter.GetBytes(2222); Array.Copy(second, 0, layout, idx, 4); idx = idx - 4; var third = BitConverter.GetBytes(3333); Array.Copy(third, 0, layout, idx, 4); var block = new Block(layout); var records = block.Records(); Assert.That(records.Count, Is.EqualTo(3)); Assert.That(records[0], Is.EqualTo(1111)); Assert.That(records[1], Is.EqualTo(2222)); Assert.That(records[2], Is.EqualTo(3333)); }
private void RollCurrentBlock() { _current = Block.New(); Blocks.Add(_current); }