Exemple #1
0
        public void CannotPinMoreNewBlocksThatPoolHave()
        {
            _poolStrategy  = new LRUBufferPoolStrategy(_logManager, _fileManager, 3);
            _bufferManager = new BufferManager(_fileManager, _logManager, _poolStrategy, TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(100));

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

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

            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.PinNew(filename, pageFormatter);
            });

            Assert.AreEqual(0, _bufferManager.Available);
        }
Exemple #2
0
        public void CanUnpinBuffer()
        {
            _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);
            var buffer2       = _bufferManager.PinNew(filename, pageFormatter);

            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(1, buffer2.Block.Id);
            Assert.AreEqual(1, _bufferManager.Available);

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

            _bufferManager.Unpin(buffer2);
            Assert.IsFalse(buffer2.IsPinned);
            Assert.AreEqual(3, _bufferManager.Available);
        }
        public Block PinNew(string filename, IPageFormatter pageFormatter)
        {
            var buffer = _bufferManager.PinNew(filename, pageFormatter);
            var block  = buffer.Block;

            _buffers.TryAdd(block, buffer);
            _pins.Add(block);

            return(block);
        }
Exemple #4
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);
        }