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 void CanReadSetIntRecord() { var block = new Block(RandomFilename, 0); var rec = new SetIntRecord(_logManager, _bufferManager, 5, block, 0, 123); var lsn = rec.WriteToLog(); _logManager.Flush(lsn); _enumerator = new LogRecordEnumerator(_logManager, _bufferManager); var record = _enumerator.Current as SetIntRecord; Assert.AreEqual(LogRecordType.SetInt, record.Type); Assert.AreEqual(5, record.TransactionNumber); Assert.AreEqual(block, record.Block); Assert.AreEqual(0, record.Offset); Assert.AreEqual(123, record.Value); }
public void CanWriteSetIntRecordMultipleTimesToLog() { _logRecord = new SetIntRecord( _logManager, _bufferManager, 1, _putToBlock, 0, 123); var logRecord2 = new SetIntRecord( _logManager, _bufferManager, 1, _putToBlock, 0, 321); _ = _logRecord.WriteToLog(); var lsn2 = logRecord2.WriteToLog(); _logManager.Flush(lsn2); var enumerator = _logManager.GetEnumerator(); var record = enumerator.Current; var currentRecord2 = new SetIntRecord(_logManager, _bufferManager, record); enumerator.MoveNext(); record = enumerator.Current; var currentRecord1 = new SetIntRecord(_logManager, _bufferManager, record); Assert.IsNotNull(currentRecord2); Assert.AreEqual(LogRecordType.SetInt, currentRecord2.Type); Assert.AreEqual(1, currentRecord1.TransactionNumber); Assert.AreEqual(321, currentRecord2.Value); Assert.AreEqual(_putToBlock, currentRecord2.Block); Assert.AreEqual(0, currentRecord2.Offset); Assert.IsNotNull(currentRecord1); Assert.AreEqual(LogRecordType.SetInt, currentRecord1.Type); Assert.AreEqual(1, currentRecord1.TransactionNumber); Assert.AreEqual(123, currentRecord1.Value); Assert.AreEqual(_putToBlock, currentRecord1.Block); Assert.AreEqual(0, currentRecord1.Offset); }
public void CannotReadDamagedRecord() { var block = new Block(RandomFilename, 0); var rec = new SetIntRecord(_logManager, _bufferManager, 5, block, 0, 123); var lsn = rec.WriteToLog(); _logManager.Flush(lsn); var page = _fileManager.ResolvePage(new Block(_logName, 0)); page.Read(new Block(_logName, 0)); // This is not a valid log record type page.SetInt(4, int.MaxValue); page.Write(new Block(_logName, 0)); var lm = new LogManager(_fileManager, _logName); _enumerator = new LogRecordEnumerator(lm, _bufferManager); var record = _enumerator.Current; Assert.IsNull(record); }
public void CanWriteSetIntRecordToLog() { _logRecord = new SetIntRecord( _logManager, _bufferManager, 3, _putToBlock, 4, 123); var lsn = _logRecord.WriteToLog(); _logManager.Flush(lsn); var enumerator = _logManager.GetEnumerator(); var record = enumerator.Current; var currentRecord = new SetIntRecord(_logManager, _bufferManager, record); Assert.IsNotNull(currentRecord); Assert.AreEqual(LogRecordType.SetInt, currentRecord.Type); Assert.AreEqual(3, currentRecord.TransactionNumber); Assert.AreEqual(123, currentRecord.Value); Assert.AreEqual(_putToBlock, currentRecord.Block); Assert.AreEqual(4, currentRecord.Offset); }