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

            var filename = RandomFilename;

            var block1  = new Block(filename, 0);
            var block2  = new Block(filename, 1);
            var block3  = new Block(filename, 2);
            var buffer1 = _bufferManager.Pin(block1);
            var buffer2 = _bufferManager.Pin(block2);
            var buffer3 = _bufferManager.Pin(block3);

            Assert.IsTrue(buffer1.IsPinned);
            Assert.IsTrue(buffer2.IsPinned);
            Assert.IsTrue(buffer3.IsPinned);
            Assert.AreEqual(filename, buffer1.Block.Filename);
            Assert.AreEqual(0, buffer1.Block.Id);
            Assert.AreEqual(filename, buffer2.Block.Filename);
            Assert.AreEqual(1, buffer2.Block.Id);
            Assert.AreEqual(filename, buffer3.Block.Filename);
            Assert.AreEqual(2, buffer3.Block.Id);
            Assert.AreEqual(0, _bufferManager.Available);
        }
Exemple #2
0
        public void CannotPinMoreBuffersThatIsOnPool()
        {
            _poolStrategy  = new LRUBufferPoolStrategy(_logManager, _fileManager, 3);
            _bufferManager = new BufferManager(_fileManager, _logManager, _poolStrategy, TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(100));

            var filename = RandomFilename;

            var block1  = new Block(filename, 0);
            var block2  = new Block(filename, 1);
            var block3  = new Block(filename, 2);
            var block4  = new Block(filename, 3);
            var buffer1 = _bufferManager.Pin(block1);
            var buffer2 = _bufferManager.Pin(block2);
            var buffer3 = _bufferManager.Pin(block3);


            Assert.IsTrue(buffer1.IsPinned);
            Assert.IsTrue(buffer2.IsPinned);
            Assert.IsTrue(buffer3.IsPinned);
            Assert.AreEqual(filename, buffer1.Block.Filename);
            Assert.AreEqual(0, buffer1.Block.Id);
            Assert.AreEqual(filename, buffer2.Block.Filename);
            Assert.AreEqual(1, buffer2.Block.Id);
            Assert.AreEqual(filename, buffer3.Block.Filename);
            Assert.AreEqual(2, buffer3.Block.Id);
            Assert.Throws <BufferBusyException>(() =>
            {
                var buffer4 = _bufferManager.Pin(block4);
            });

            Assert.AreEqual(0, _bufferManager.Available);
        }
Exemple #3
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);
        }
        public void Pin(Block block)
        {
            var buffer = _bufferManager.Pin(block);

            _buffers.TryAdd(block, buffer);
            _pins.Add(block);
        }
Exemple #5
0
        public void CanPinSameBufferMultipleTimes()
        {
            _poolStrategy  = new LRUBufferPoolStrategy(_logManager, _fileManager, 3);
            _bufferManager = new BufferManager(_fileManager, _logManager, _poolStrategy, null, null);

            var filename = RandomFilename;

            var block   = new Block(filename, 0);
            var buffer1 = _bufferManager.Pin(block);
            var buffer2 = _bufferManager.Pin(block);

            Assert.IsTrue(buffer1.IsPinned);
            Assert.IsTrue(buffer2.IsPinned);
            Assert.AreEqual(filename, buffer1.Block.Filename);
            Assert.AreEqual(0, buffer1.Block.Id);
            Assert.AreEqual(filename, buffer2.Block.Filename);
            Assert.AreEqual(0, buffer2.Block.Id);
            Assert.AreEqual(2, _bufferManager.Available);
        }
Exemple #6
0
        public void CanPinBuffer()
        {
            _buffersList = new TransactionBuffersList(_bufferManager);

            _ = _fileManager.Append(RandomFilename, out var block);

            Assert.DoesNotThrow(() =>
            {
                _bufferManager.Pin(block);
            });
        }
Exemple #7
0
        public void CanCreateAndDisposeLogEnumerator()
        {
            _recoveryManager = new RecoveryManager(_bufferManager, _logManager, 5);
            var block  = new Block(RandomFilename, 0);
            var buffer = _bufferManager.Pin(block);

            _recoveryManager.SetInt(buffer, 12, 12);
            _recoveryManager.Commit();

            Assert.DoesNotThrow(() =>
            {
                _enumerator = new LogRecordEnumerator(_logManager, _bufferManager);
                _enumerator.Dispose();
            });
        }
Exemple #8
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]);
        }