public void if_asked_for_more_than_buffer_size_will_only_read_buffer_size()
        {
            var chunk = TFChunk.CreateNew(GetFilePathFor("file1"), 3000, 0, 0, isScavenged: false, inMem: false, unbuffered: false, writethrough: false);

            using (var reader = chunk.AcquireReader())
            {
                var buffer = new byte[1024];
                var result = reader.ReadNextRawBytes(3000, buffer);
                Assert.IsFalse(result.IsEOF);
                Assert.AreEqual(1024, result.BytesRead);
            }
            chunk.MarkForDeletion();
            chunk.WaitForDestroy(5000);
        }
        public void a_read_past_eof_returns_eof_and_no_footer()
        {
            var chunk = TFChunk.CreateNew(GetFilePathFor("file1"), 300, 0, 0, isScavenged: false, inMem: false, unbuffered: false, writethrough: false);

            using (var reader = chunk.AcquireReader())
            {
                var buffer = new byte[8092];
                var result = reader.ReadNextRawBytes(8092, buffer);
                Assert.IsTrue(result.IsEOF);
                Assert.AreEqual(4096, result.BytesRead); //does not includes header and footer space
            }
            chunk.MarkForDeletion();
            chunk.WaitForDestroy(5000);
        }
Exemplo n.º 3
0
        public void a_read_on_new_file_can_be_performed_but_returns_nothing()
        {
            var chunk = TFChunk.CreateNew(GetFilePathFor("file1"), 2000, 0, 0, false);

            using (var reader = chunk.AcquireReader())
            {
                var buffer = new byte[1024];
                var result = reader.ReadNextDataBytes(1024, buffer);
                Assert.IsFalse(result.IsEOF);
                Assert.AreEqual(0, result.BytesRead);
            }
            chunk.MarkForDeletion();
            chunk.WaitForDestroy(5000);
        }
        public void a_read_past_eof_returns_eof_and_no_footer()
        {
            var chunk = TFChunk.CreateNew(GetFilePathFor("file1"), 300, 0, 0, false);

            using (var reader = chunk.AcquireReader())
            {
                var buffer = new byte[1024];
                var result = reader.ReadNextRawBytes(1024, buffer);
                Assert.IsTrue(result.IsEOF);
                Assert.AreEqual(556, result.BytesRead); //does not includes header and footer space
            }
            chunk.MarkForDeletion();
            chunk.WaitForDestroy(5000);
        }
Exemplo n.º 5
0
        public void the_file_will_not_be_deleted_until_reader_released()
        {
            var chunk = TFChunk.CreateNew(GetFilePathFor("file1"), 2000, 0, 0, false);

            using (var reader = chunk.AcquireReader())
            {
                chunk.MarkForDeletion();
                var buffer = new byte[1024];
                var result = reader.ReadNextDataBytes(1024, buffer);
                Assert.IsFalse(result.IsEOF);
                Assert.AreEqual(0, result.BytesRead); // no data yet
            }
            chunk.WaitForDestroy(5000);
        }
        public void a_read_on_new_file_can_be_performed()
        {
            var chunk = TFChunk.CreateNew(GetFilePathFor("file1"), 2000, 0, 0, isScavenged: false, inMem: false, unbuffered: false, writethrough: false);

            using (var reader = chunk.AcquireReader())
            {
                var buffer = new byte[1024];
                var result = reader.ReadNextRawBytes(1024, buffer);
                Assert.IsFalse(result.IsEOF);
                Assert.AreEqual(1024, result.BytesRead);
            }
            chunk.MarkForDeletion();
            chunk.WaitForDestroy(5000);
        }
        public void a_read_past_end_of_completed_chunk_does_include_header_or_footer()
        {
            var chunk = TFChunk.CreateNew(GetFilePathFor("File1"), 300, 0, 0, false);

            chunk.Complete();
            using (var reader = chunk.AcquireReader())
            {
                var buffer = new byte[1024];
                var result = reader.ReadNextRawBytes(1024, buffer);
                Assert.IsTrue(result.IsEOF);
                Assert.AreEqual(ChunkHeader.Size + ChunkFooter.Size, result.BytesRead); //just header + footer = 256
            }
            chunk.MarkForDeletion();
            chunk.WaitForDestroy(5000);
        }
        public void a_read_on_scavenged_chunk_includes_map()
        {
            var chunk = TFChunk.CreateNew(GetFilePathFor("afile"), 200, 0, 0, true);

            chunk.CompleteScavenge(new [] { new PosMap(0, 0), new PosMap(1, 1) });
            using (var reader = chunk.AcquireReader())
            {
                var buffer = new byte[1024];
                var result = reader.ReadNextRawBytes(1024, buffer);
                Assert.IsTrue(result.IsEOF);
                Assert.AreEqual(ChunkHeader.Size + ChunkHeader.Size + 2 * PosMap.FullSize, result.BytesRead);
            }
            chunk.MarkForDeletion();
            chunk.WaitForDestroy(5000);
        }
Exemplo n.º 9
0
        public void a_read_on_scavenged_chunk_does_not_include_map()
        {
            var chunk = TFChunk.CreateNew(GetFilePathFor("afile"), 200, 0, 0, true);

            chunk.CompleteScavenge(new[] { new PosMap(0, 0), new PosMap(1, 1) });
            using (var reader = chunk.AcquireReader())
            {
                var buffer = new byte[1024];
                var result = reader.ReadNextDataBytes(1024, buffer);
                Assert.IsTrue(result.IsEOF);
                Assert.AreEqual(0, result.BytesRead); //header 128 + footer 128 + map 16
            }
            chunk.MarkForDeletion();
            chunk.WaitForDestroy(5000);
        }
Exemplo n.º 10
0
        public void a_read_past_end_of_completed_chunk_does_not_include_footer()
        {
            var chunk = TFChunk.CreateNew(GetFilePathFor("file1"), 300, 0, 0, false);

            chunk.Complete(); // chunk has 0 bytes of actual data
            using (var reader = chunk.AcquireReader())
            {
                var buffer = new byte[1024];
                var result = reader.ReadNextDataBytes(1024, buffer);
                Assert.IsTrue(result.IsEOF);
                Assert.AreEqual(0, result.BytesRead);
            }
            chunk.MarkForDeletion();
            chunk.WaitForDestroy(5000);
        }
Exemplo n.º 11
0
        public void a_read_past_eof_doesnt_return_eof_if_chunk_is_not_yet_completed()
        {
            var chunk = TFChunk.CreateNew(GetFilePathFor("file1"), 300, 0, 0, false);
            var rec   = LogRecord.Commit(0, Guid.NewGuid(), 0, 0);

            Assert.IsTrue(chunk.TryAppend(rec).Success, "Record wasn't appended");
            using (var reader = chunk.AcquireReader())
            {
                var buffer = new byte[1024];
                var result = reader.ReadNextDataBytes(1024, buffer);
                Assert.IsFalse(result.IsEOF, "EOF was returned.");
                //does not include header and footer space
                Assert.AreEqual(rec.GetSizeWithLengthPrefixAndSuffix(), result.BytesRead, "Read wrong number of bytes.");
            }
            chunk.MarkForDeletion();
            chunk.WaitForDestroy(5000);
        }
Exemplo n.º 12
0
        public void Setup()
        {
            _prepare1 = new PrepareLogRecord(0, _corrId, _eventId, 0, "test", 1, new DateTime(2000, 1, 1, 12, 0, 0),
                                             PrepareFlags.None, "Foo", new byte[12], new byte[15]);
            _prepare2 = new PrepareLogRecord(0, _corrId, _eventId, 0, "test2", 2, new DateTime(2000, 1, 1, 12, 0, 0),
                                             PrepareFlags.None, "Foo2", new byte[12], new byte[15]);

            _chunk = TFChunk.CreateNew(_filename, 4096, 0, 0);
            var r1 = _chunk.TryAppend(_prepare1);

            _written1  = r1.Success;
            _position1 = r1.OldPosition;
            var r2 = _chunk.TryAppend(_prepare2);

            _written2  = r2.Success;
            _position2 = r2.OldPosition;
            _chunk.Flush();
        }
Exemplo n.º 13
0
        public void if_asked_for_more_than_buffer_size_will_only_read_buffer_size()
        {
            var chunk = TFChunk.CreateNew(GetFilePathFor("file1"), 3000, 0, 0, false);

            var rec = LogRecord.Prepare(0, Guid.NewGuid(), Guid.NewGuid(), 0, 0, "ES", -1, PrepareFlags.None, "ET", new byte[2000], null);

            Assert.IsTrue(chunk.TryAppend(rec).Success, "Record wasn't appended");

            using (var reader = chunk.AcquireReader())
            {
                var buffer = new byte[1024];
                var result = reader.ReadNextDataBytes(3000, buffer);
                Assert.IsFalse(result.IsEOF);
                Assert.AreEqual(1024, result.BytesRead);
            }
            chunk.MarkForDeletion();
            chunk.WaitForDestroy(5000);
        }
Exemplo n.º 14
0
        public override void TestFixtureSetUp()
        {
            base.TestFixtureSetUp();
            _chunk = TFChunk.CreateNew(Filename, 4096, 0, 0, false);

            _prepare1 = new PrepareLogRecord(0, _corrId, _eventId, 0, 0, "test", 1, new DateTime(2000, 1, 1, 12, 0, 0),
                                             PrepareFlags.None, "Foo", new byte[12], new byte[15]);
            var r1 = _chunk.TryAppend(_prepare1);

            _written1  = r1.Success;
            _position1 = r1.OldPosition;

            _prepare2 = new PrepareLogRecord(r1.NewPosition, _corrId, _eventId, 0, 0, "test2", 2, new DateTime(2000, 1, 1, 12, 0, 0),
                                             PrepareFlags.None, "Foo2", new byte[12], new byte[15]);
            var r2 = _chunk.TryAppend(_prepare2);

            _written2  = r2.Success;
            _position2 = r2.OldPosition;
            _chunk.Flush();
        }
        private TFChunk CreateChunk(int chunkNumber, bool scavenged, out List <PosMap> posmap)
        {
            var map   = new List <PosMap>();
            var chunk = TFChunk.CreateNew(GetFilePathFor("chunk-" + chunkNumber + "-" + Guid.NewGuid()), 1024 * 1024,
                                          chunkNumber, chunkNumber, scavenged, false, false, false,
                                          Constants.TFChunkInitialReaderCountDefault,
                                          Constants.TFChunkMaxReaderCountDefault,
                                          false);
            long offset = chunkNumber * 1024 * 1024;
            long logPos = 0 + offset;

            for (int i = 0, n = ChunkFooter.Size / PosMap.FullSize + 1; i < n; ++i)
            {
                if (scavenged)
                {
                    map.Add(new PosMap(logPos, (int)logPos));
                }

                var res = chunk.TryAppend(LogRecord.Commit(logPos, Guid.NewGuid(), logPos, 0));
                Assert.IsTrue(res.Success);
                logPos = res.NewPosition + offset;
            }

            if (scavenged)
            {
                posmap = map;
                chunk.CompleteScavenge(map);
            }
            else
            {
                posmap = null;
                chunk.Complete();
            }

            return(chunk);
        }
 public void Setup()
 {
     _chunk = TFChunk.CreateNew(_filename, 1000, 0, 0);
     _chunk.MarkForDeletion();
 }
 public void Setup()
 {
     _chunk = TFChunk.CreateNew(_filename, 4096, 0, 0);
     _chunk.Complete();
     _testChunk = TFChunk.FromCompletedFile(_filename, verifyHash: true);
 }
 private static TFChunk CreateNewChunk(string fileName, int chunkSize = 4096, bool isScavenged = false)
 {
     return(TFChunk.CreateNew(fileName, chunkSize, 0, 0,
                              isScavenged: isScavenged, inMem: false, unbuffered: false,
                              writethrough: false, initialReaderCount: TestConstants.TFChunkInitialReaderCountDefault, TestConstants.TFChunkMaxReaderCountDefault, reduceFileCachePressure: false));
 }
 public void setup()
 {
     _chunk  = TFChunk.CreateNew(_filename, 1000, 0, 0);
     _reader = _chunk.AcquireReader();
     _chunk.MarkForDeletion();
 }
 public void Setup()
 {
     _chunk = TFChunk.CreateNew(Filename, 1024, 0, 0);
 }
Exemplo n.º 21
0
 public override void TestFixtureSetUp()
 {
     base.TestFixtureSetUp();
     _chunk = TFChunk.CreateNew(Filename, 4096, 0, 0, isScavenged: true);
     _chunk.CompleteScavenge(new PosMap[0]);
 }
Exemplo n.º 22
0
 public static TFChunk CreateNewChunk(string fileName, int chunkSize = 4096, bool isScavenged = false)
 {
     return(TFChunk.CreateNew(fileName, chunkSize, 0, 0,
                              isScavenged: isScavenged, inMem: false, unbuffered: false,
                              writethrough: false, initialReaderCount: 5, reduceFileCachePressure: false));
 }
 public void Setup()
 {
     _chunk = TFChunk.CreateNew(filename, 4096, 0, 0);
     _chunk.Complete();
     _testChunk = TFChunk.FromCompletedFile(filename);
 }
Exemplo n.º 24
0
 public override void SetUp()
 {
     base.SetUp();
     _chunk = TFChunk.CreateNew(Filename, 1000, 0, 0, false);
     _chunk.MarkForDeletion();
 }
 public override void SetUp()
 {
     base.SetUp();
     _chunk = TFChunk.CreateNew(Filename, 1000, 0, 0, isScavenged: false, inMem: false, unbuffered: false, writethrough: false);
     _chunk.MarkForDeletion();
 }
Exemplo n.º 26
0
 public override void SetUp()
 {
     base.SetUp();
     _chunk = TFChunk.CreateNew(Filename, 1024, 0, 0, false);
 }
Exemplo n.º 27
0
 public override void TestFixtureSetUp()
 {
     base.TestFixtureSetUp();
     _chunk = TFChunk.CreateNew(Filename, 4096, 0, 0, isScavenged: true, inMem: false, unbuffered: false, writethrough: false);
     _chunk.CompleteScavenge(new PosMap[0]);
 }