示例#1
0
        public void CanPinBufferMultipleTimesAndUnpinMultipleTimes()
        {
            _poolStrategy  = new LRUBufferPoolStrategy(_logManager, _fileManager, 3);
            _bufferManager = new BufferManager(_fileManager, _logManager, _poolStrategy, null, null);

            var filename      = RandomFilename;
            var pageFormatter = new BasePageFormatter();

            var buffer1 = _bufferManager.PinNew(filename, pageFormatter);

            Assert.IsTrue(buffer1.IsPinned);
            Assert.AreEqual(2, _bufferManager.Available);

            var buffer2 = _bufferManager.Pin(buffer1.Block);

            Assert.IsTrue(buffer2.IsPinned);
            Assert.AreEqual(2, _bufferManager.Available);

            _bufferManager.Unpin(buffer1);

            Assert.IsTrue(buffer1.IsPinned);
            Assert.AreEqual(2, _bufferManager.Available);

            _bufferManager.Unpin(buffer2);

            Assert.IsFalse(buffer2.IsPinned);
            Assert.AreEqual(3, _bufferManager.Available);
        }
示例#2
0
        public void Unpin(Block block)
        {
            if (_buffers.TryGetValue(block, out var buffer))
            {
                _bufferManager.Unpin(buffer);
                _pins.Remove(block);

                // Don't think that would need this check.
                // Anyway, let it be for now, code coverage would show who is right
                if (!_pins.Contains(block))
                {
                    _buffers.Remove(block);
                }
            }
        }
示例#3
0
        public void CanPinBufferWriteAndFlush()
        {
            _poolStrategy  = new LRUBufferPoolStrategy(_logManager, _fileManager, 3);
            _bufferManager = new BufferManager(_fileManager, _logManager, _poolStrategy, null, null);

            var filename      = RandomFilename;
            var pageFormatter = new BasePageFormatter();

            var buffer1 = _bufferManager.PinNew(filename, pageFormatter);

            buffer1.SetInt(0, 123, 1, 1);
            _bufferManager.FlushAll(1);
            _bufferManager.Unpin(buffer1);

            var page    = _fileManager.ResolvePage();
            var canRead = page.Read(new Block(filename, 0));

            var canGetValue = page.GetInt(0, out var value);

            Assert.IsFalse(buffer1.IsPinned);
            Assert.IsTrue(canRead);
            Assert.IsTrue(canGetValue);
            Assert.AreEqual(123, value);
        }
示例#4
0
        public void CanRecover()
        {
            _recoveryManager = new RecoveryManager(_bufferManager, _logManager, 6);
            var block = new Block(RandomFilename, 0);

            var buffer = _bufferManager.Pin(block);

            _recoveryManager.Recover();

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

            var page = _fileManager.ResolvePage();

            _ = page.Read(new Block(_name, 0));

            var enumerator = _logManager.GetEnumerator();

            var record           = enumerator.Current;
            var checkpointRecord = new CheckpointRecord(_logManager, _bufferManager, record);

            Assert.AreEqual(LogRecordType.Checkpoint, checkpointRecord.Type);
            Assert.AreEqual(1, checkpointRecord.Transactions.Length);
            Assert.AreEqual(6, checkpointRecord.Transactions[0]);
        }