예제 #1
0
        public void all_records_could_be_read_doing_forward_backward_pass()
        {
            var seqReader = new TFChunkSequentialReader(_db, _db.Config.WriterCheckpoint, 0);

            SeqReadResult res;
            int           count1 = 0;

            while ((res = seqReader.TryReadNext()).Success)
            {
                var rec = _records[count1];
                Assert.AreEqual(rec, res.LogRecord);
                Assert.AreEqual(rec.Position, res.RecordPrePosition);
                Assert.AreEqual(rec.Position + rec.GetSizeWithLengthPrefixAndSuffix(), res.RecordPostPosition);

                ++count1;
            }
            Assert.AreEqual(RecordsCount, count1);

            int count2 = 0;

            while ((res = seqReader.TryReadPrev()).Success)
            {
                var rec = _records[RecordsCount - count2 - 1];
                Assert.AreEqual(rec, res.LogRecord);
                Assert.AreEqual(rec.Position, res.RecordPrePosition);
                Assert.AreEqual(rec.Position + rec.GetSizeWithLengthPrefixAndSuffix(), res.RecordPostPosition);

                ++count2;
            }
            Assert.AreEqual(RecordsCount, count2);
        }
예제 #2
0
        public void try_read_does_not_cache_anything_and_returns_record_once_it_is_written_later()
        {
            var writerchk = new InMemoryCheckpoint(0);
            var db        = new TFChunkDb(new TFChunkDbConfig(PathName,
                                                              new VersionedPatternFileNamingStrategy(PathName, "chunk-"),
                                                              10000,
                                                              0,
                                                              writerchk,
                                                              new InMemoryCheckpoint()));

            db.OpenVerifyAndClean();

            var writer = new TFChunkWriter(db);

            writer.Open();

            var reader = new TFChunkSequentialReader(db, writerchk, 0);

            LogRecord record;

            Assert.IsFalse(reader.TryReadNext(out record));

            var  rec = LogRecord.SingleWrite(0, Guid.NewGuid(), Guid.NewGuid(), "ES", -1, "ET", new byte[] { 7 }, null);
            long tmp;

            Assert.IsTrue(writer.Write(rec, out tmp));
            writer.Flush();
            writer.Close();

            Assert.IsTrue(reader.TryReadNext(out record));
            Assert.AreEqual(rec, record);

            reader.Close();
            db.Close();
        }
예제 #3
0
        public void all_records_could_be_read_with_forward_pass()
        {
            var seqReader = new TFChunkSequentialReader(_db, _db.Config.WriterCheckpoint, 0);

            SeqReadResult res;
            int           count = 0;

            while ((res = seqReader.TryReadNext()).Success)
            {
                var rec = _keptRecords[count];
                Assert.AreEqual(rec, res.LogRecord);

                ++count;
            }
            Assert.AreEqual(_keptRecords.Length, count);
        }
예제 #4
0
        public void all_records_could_be_read_with_backward_pass()
        {
            var seqReader = new TFChunkSequentialReader(_db, _db.Config.WriterCheckpoint, _db.Config.WriterCheckpoint.Read());

            SeqReadResult res;
            int           count = 0;

            while ((res = seqReader.TryReadPrev()).Success)
            {
                var rec = _keptRecords[_keptRecords.Length - count - 1];
                Assert.AreEqual(rec, res.LogRecord);
                Assert.AreEqual(rec.Position, res.RecordPrePosition);
                Assert.AreEqual(rec.Position + rec.GetSizeWithLengthPrefixAndSuffix(), res.RecordPostPosition);

                ++count;
            }
            Assert.AreEqual(_keptRecords.Length, count);
        }
예제 #5
0
        public void records_can_be_read_forward_starting_from_any_position()
        {
            for (int i = 0; i < RecordsCount; ++i)
            {
                var seqReader = new TFChunkSequentialReader(_db, _db.Config.WriterCheckpoint, _records[i].Position);

                SeqReadResult res;
                int           count = 0;
                while ((res = seqReader.TryReadNext()).Success)
                {
                    var rec = _keptRecords[(i + 1) / 2 + count];
                    Assert.AreEqual(rec, res.LogRecord);
                    //Assert.AreEqual(rec.Position + rec.GetSizeWithLengthPrefixAndSuffix(), seqReader.Position);

                    ++count;
                }
                Assert.AreEqual(_keptRecords.Length - (i + 1) / 2, count);
            }
        }
예제 #6
0
        public void try_read_returns_false_when_writer_checksum_is_zero()
        {
            var writerchk = new InMemoryCheckpoint(0);
            var db        = new TFChunkDb(new TFChunkDbConfig(PathName,
                                                              new VersionedPatternFileNamingStrategy(PathName, "chunk-"),
                                                              10000,
                                                              0,
                                                              writerchk,
                                                              new InMemoryCheckpoint()));

            db.OpenVerifyAndClean();

            var       reader = new TFChunkSequentialReader(db, writerchk, 0);
            LogRecord record;

            Assert.IsFalse(reader.TryReadNext(out record));

            db.Close();
        }
예제 #7
0
        public void records_can_be_read_backward_starting_from_any_position()
        {
            for (int i = 0; i < RecordsCount; ++i)
            {
                var seqReader = new TFChunkSequentialReader(_db, _db.Config.WriterCheckpoint, _records[i].Position);

                SeqReadResult res;
                int           count = 0;
                while ((res = seqReader.TryReadPrev()).Success)
                {
                    var rec = _records[i - count - 1];
                    Assert.AreEqual(rec, res.LogRecord);
                    Assert.AreEqual(rec.Position, res.RecordPrePosition);
                    Assert.AreEqual(rec.Position + rec.GetSizeWithLengthPrefixAndSuffix(), res.RecordPostPosition);

                    ++count;
                }
                Assert.AreEqual(i, count);
            }
        }