Esempio n. 1
0
        public Buffer Pin(Block block)
        {
            //try
            //{
            long   timestamp = DateTime.UtcNow.Ticks;
            Buffer buffer    = null;

            lock (_bufferGatheringLock)
            {
                buffer = _poolStrategy.Pin(block);
            }

            while (buffer == null && !WaitingForTooLong(timestamp))
            {
                Thread.Sleep(_tickWaitingTime);

                lock (_bufferGatheringLock)
                {
                    buffer = _poolStrategy.Pin(block);
                }
            }

            if (buffer == null)
            {
                throw new BufferBusyException();
            }

            return(buffer);
            //}
            //catch(ThreadAbortException)
            //{
            //    throw new BufferBusyException();
            //}
        }
Esempio n. 2
0
            public void CannotPinMoreBuffersThatIsOnPool()
            {
                _poolStrategy = new LRUBufferPoolStrategy(_logManager, _fileManager, 3);

                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 = _poolStrategy.Pin(block1);
                var buffer2 = _poolStrategy.Pin(block2);
                var buffer3 = _poolStrategy.Pin(block3);
                var buffer4 = _poolStrategy.Pin(block4);

                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.IsNull(buffer4);
                Assert.AreEqual(0, _poolStrategy.Available);
            }
Esempio n. 3
0
            public void CanPinBufferMultipleTimesAndUnpinMultipleTimes()
            {
                _poolStrategy = new LRUBufferPoolStrategy(_logManager, _fileManager, 3);

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

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

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

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

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

                _poolStrategy.Unpin(buffer1);

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

                _poolStrategy.Unpin(buffer2);

                Assert.IsFalse(buffer2.IsPinned);
                Assert.AreEqual(3, _poolStrategy.Available);
            }
Esempio n. 4
0
            public void CanPinSameBufferMultipleTimes()
            {
                _poolStrategy = new LRUBufferPoolStrategy(_logManager, _fileManager, 3);

                var filename = RandomFilename;

                var block   = new Block(filename, 0);
                var buffer1 = _poolStrategy.Pin(block);
                var buffer2 = _poolStrategy.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, _poolStrategy.Available);
            }
Esempio n. 5
0
        public void CanPinBuffer()
        {
            _poolStrategy = new NaiveBufferPoolStrategy(_logManager, _fileManager, 3);

            var filename = RandomFilename;

            var block  = new Block(filename, 0);
            var buffer = _poolStrategy.Pin(block);

            Assert.IsTrue(buffer.IsPinned);
            Assert.AreEqual(filename, buffer.Block.Filename);
            Assert.AreEqual(0, buffer.Block.Id);
            Assert.AreEqual(2, _poolStrategy.Available);
        }
Esempio n. 6
0
        public void CanPinAllBuffers()
        {
            _poolStrategy = new NaiveBufferPoolStrategy(_logManager, _fileManager, 3);

            var filename = RandomFilename;

            var block1  = new Block(filename, 0);
            var block2  = new Block(filename, 1);
            var block3  = new Block(filename, 2);
            var buffer1 = _poolStrategy.Pin(block1);
            var buffer2 = _poolStrategy.Pin(block2);
            var buffer3 = _poolStrategy.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, _poolStrategy.Available);
        }