public void CanSetInt() { var page = _fileManager.ResolvePage(); var block = new Block(RandomFilename, 0); page.Read(block); page.SetInt(0, 222); page.Write(block); _recoveryManager = new RecoveryManager(_bufferManager, _logManager, 6); var buffer = _bufferManager.Pin(block); var lsn = _recoveryManager.SetInt(buffer, 0, 123); _logManager.Flush(lsn); _bufferManager.Unpin(buffer); _bufferManager.FlushAll(6); var enumerator = _logManager.GetEnumerator(); var record = enumerator.Current; var setIntRecord = new SetIntRecord(_logManager, _bufferManager, record); Assert.AreEqual(LogRecordType.SetInt, setIntRecord.Type); Assert.AreEqual(0, setIntRecord.Block.Id); Assert.AreEqual(0, setIntRecord.Offset); Assert.AreEqual(222, setIntRecord.Value); Assert.AreEqual(6, setIntRecord.TransactionNumber); }
public bool SetInt(Block block, int offset, int value) { _concurrencyManager.ExclusiveLock(block); var buffer = _bufferList.GetBuffer(block); int lsn = _recoveryManager.SetInt(buffer, offset, value); return(buffer.SetInt(offset, value, _transactionNumber, lsn)); }
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(); }); }
public void CanSetTempInt() { var page = _fileManager.ResolvePage(); var block = new Block("temp" + RandomFilename, 0); page.Read(block); page.SetInt(0, 222); page.Write(block); _recoveryManager = new RecoveryManager(_bufferManager, _logManager, 6); var buffer = _bufferManager.Pin(block); var lsn = _recoveryManager.SetInt(buffer, 0, 123); Assert.AreEqual(-1, lsn); }
public void CanRecoverFromUncommitedAndCommitedTransactions() { var page = _fileManager.ResolvePage(); var block = new Block(RandomFilename, 0); page.Read(block); page.SetInt(0, 222); page.Write(block); var startRecord = new StartRecord(_logManager, _bufferManager, 1); var lsn = startRecord.WriteToLog(); _logManager.Flush(lsn); var startRecord2 = new StartRecord(_logManager, _bufferManager, 2); var lsn2 = startRecord2.WriteToLog(); _logManager.Flush(lsn2); _recoveryManager = new RecoveryManager(_bufferManager, _logManager, 1); var buffer = _bufferManager.Pin(block); _recoveryManager.SetInt(buffer, 0, 123); _recoveryManager.SetByte(buffer, 0, 1); _recoveryManager.Commit(); var recoveryManager2 = new RecoveryManager(_bufferManager, _logManager, 2); recoveryManager2.SetByte(buffer, 1, 0); Assert.DoesNotThrow(() => { recoveryManager2.Recover(); _bufferManager.Unpin(buffer); }); page.Read(block); _ = page.GetInt(0, out var resultValue); Assert.AreEqual(222, resultValue); }
public void CanRecoverSimpleTransaction() { var startRecord = new StartRecord(_logManager, _bufferManager, 6); var lsn = startRecord.WriteToLog(); _logManager.Flush(lsn); _recoveryManager = new RecoveryManager(_bufferManager, _logManager, 6); var block = new Block(RandomFilename, 0); var buffer = _bufferManager.Pin(block); _recoveryManager.SetInt(buffer, 0, 123); Assert.DoesNotThrow(() => { _recoveryManager.Recover(); _bufferManager.Unpin(buffer); }); }