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); }
public void CanUnpinBuffer() { _poolStrategy = new NaiveBufferPoolStrategy(_logManager, _fileManager, 3); var filename = RandomFilename; var pageFormatter = new BasePageFormatter(); var buffer1 = _poolStrategy.PinNew(filename, pageFormatter); var buffer2 = _poolStrategy.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, _poolStrategy.Available); _poolStrategy.Unpin(buffer1); Assert.IsFalse(buffer1.IsPinned); Assert.AreEqual(2, _poolStrategy.Available); _poolStrategy.Unpin(buffer2); Assert.IsFalse(buffer2.IsPinned); Assert.AreEqual(3, _poolStrategy.Available); }
public void Unpin(Buffer buffer) { // Maybe Monitor.PulseAll is not a good think, but at lease it would wake up threads. lock (_bufferGatheringLock) { _poolStrategy.Unpin(buffer); if (!buffer.IsPinned) { Monitor.PulseAll(_bufferGatheringLock); } } }
public void CanPinBufferWriteAndFlush() { _poolStrategy = new LRUBufferPoolStrategy(_logManager, _fileManager, 3); var filename = RandomFilename; var pageFormatter = new BasePageFormatter(); var buffer1 = _poolStrategy.PinNew(filename, pageFormatter); buffer1.SetInt(0, 123, 1, 1); _poolStrategy.FlushAll(1); _poolStrategy.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); }