Esempio n. 1
0
        public void CanSetBlob()
        {
            var page = _fileManager.ResolvePage();

            var block = new Block(RandomFilename, 0);

            page.Read(block);
            page.SetBlob(0, new byte[] { 1, 2, 3 });
            page.Write(block);

            _recoveryManager = new RecoveryManager(_bufferManager, _logManager, 6);
            var buffer = _bufferManager.Pin(block);

            var lsn = _recoveryManager.SetBlob(buffer, 0, new byte[] { 3, 2, 1 });

            _logManager.Flush(lsn);

            _bufferManager.Unpin(buffer);
            _bufferManager.FlushAll(6);

            var enumerator = _logManager.GetEnumerator();

            var record        = enumerator.Current;
            var setBoolRecord = new SetBlobRecord(_logManager, _bufferManager, record);

            Assert.AreEqual(LogRecordType.SetBlob, setBoolRecord.Type);
            Assert.AreEqual(0, setBoolRecord.Block.Id);
            Assert.AreEqual(0, setBoolRecord.Offset);
            Assert.AreEqual(new byte[] { 1, 2, 3 }, setBoolRecord.Value);
            Assert.AreEqual(6, setBoolRecord.TransactionNumber);
        }
Esempio n. 2
0
        public void CanWriteSetBlobRecordToLog()
        {
            _logRecord = new SetBlobRecord(
                _logManager,
                _bufferManager,
                3,
                _putToBlock,
                4,
                new byte[] { 1, 2, 3 });
            var lsn = _logRecord.WriteToLog();

            _logManager.Flush(lsn);


            var enumerator    = _logManager.GetEnumerator();
            var record        = enumerator.Current;
            var currentRecord = new SetBlobRecord(_logManager, _bufferManager, record);

            Assert.IsNotNull(currentRecord);
            Assert.AreEqual(LogRecordType.SetBlob, currentRecord.Type);
            Assert.AreEqual(3, currentRecord.TransactionNumber);
            Assert.AreEqual(new byte[] { 1, 2, 3 }, currentRecord.Value);
            Assert.AreEqual(_putToBlock, currentRecord.Block);
            Assert.AreEqual(4, currentRecord.Offset);
        }
Esempio n. 3
0
        public void CanReadSetBlobRecord()
        {
            var block = new Block(RandomFilename, 0);
            var rec   = new SetBlobRecord(_logManager, _bufferManager, 5, block, 0, new byte[] { 1, 2, 3 });
            var lsn   = rec.WriteToLog();

            _logManager.Flush(lsn);


            _enumerator = new LogRecordEnumerator(_logManager, _bufferManager);
            var record = _enumerator.Current as SetBlobRecord;

            Assert.AreEqual(LogRecordType.SetBlob, record.Type);
            Assert.AreEqual(5, record.TransactionNumber);
            Assert.AreEqual(block, record.Block);
            Assert.AreEqual(0, record.Offset);
            Assert.AreEqual(new byte[] { 1, 2, 3 }, record.Value);
        }
Esempio n. 4
0
        public void CanWriteSetBlobRecordMultipleTimesToLog()
        {
            _logRecord = new SetBlobRecord(
                _logManager,
                _bufferManager,
                1,
                _putToBlock,
                0,
                new byte[] { 4, 5, 6 });
            var logRecord2 = new SetBlobRecord(
                _logManager,
                _bufferManager,
                1,
                _putToBlock,
                0,
                new byte[] { 1, 2, 3 });

            _ = _logRecord.WriteToLog();
            var lsn2 = logRecord2.WriteToLog();

            _logManager.Flush(lsn2);

            var enumerator     = _logManager.GetEnumerator();
            var record         = enumerator.Current;
            var currentRecord2 = new SetBlobRecord(_logManager, _bufferManager, record);

            enumerator.MoveNext();
            record = enumerator.Current;
            var currentRecord1 = new SetBlobRecord(_logManager, _bufferManager, record);

            Assert.IsNotNull(currentRecord2);
            Assert.AreEqual(LogRecordType.SetBlob, currentRecord2.Type);
            Assert.AreEqual(1, currentRecord1.TransactionNumber);
            Assert.AreEqual(new byte[] { 1, 2, 3 }, currentRecord2.Value);
            Assert.AreEqual(_putToBlock, currentRecord2.Block);
            Assert.AreEqual(0, currentRecord2.Offset);

            Assert.IsNotNull(currentRecord1);
            Assert.AreEqual(LogRecordType.SetBlob, currentRecord1.Type);
            Assert.AreEqual(1, currentRecord1.TransactionNumber);
            Assert.AreEqual(new byte[] { 4, 5, 6 }, currentRecord1.Value);
            Assert.AreEqual(_putToBlock, currentRecord1.Block);
            Assert.AreEqual(0, currentRecord1.Offset);
        }