public void CanReadLogEntriesWithOneValue() { var filename = RandomFilename; _logManager = new LogManager(_fileManager, filename); var canAppend = _logManager.Append(new object[] { 123 }, out var lsn); var canAppend2 = _logManager.Append(new object[] { 12 }, out var lsn2); _enumerator = _logManager.GetEnumerator(); var entry = _enumerator.Current; var canReadLogEntry = entry.NextInt(out var result1); var canMove1 = _enumerator.MoveNext(); var entry2 = _enumerator.Current; var canReadLogEntry2 = entry2.NextInt(out var result2); var canMove2 = _enumerator.MoveNext(); _enumerator.Dispose(); Assert.IsTrue(canAppend); Assert.IsTrue(canAppend2); Assert.IsTrue(canReadLogEntry); Assert.IsTrue(canReadLogEntry2); Assert.AreEqual(0, lsn); Assert.AreEqual(1, lsn2); Assert.IsTrue(canMove1); Assert.IsFalse(canMove2); Assert.AreEqual(12, result1); Assert.AreEqual(123, result2); }
public void CanAddMultipleRecordsInDifferentBlocks() { var filename = RandomFilename; _logManager = new LogManager(_fileManager, filename); var record = new object[] { 10, 12, "123123", true, (byte)(123), new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 } }; var canAppend1 = _logManager.Append(record, out var lsn1); var canAppend2 = _logManager.Append(record, out var lsn2); var canAppend3 = _logManager.Append(record, out var lsn3); Assert.IsTrue(canAppend1); Assert.AreEqual(0, lsn1); Assert.IsTrue(canAppend2); Assert.AreEqual(1, lsn2); Assert.IsTrue(canAppend3); Assert.AreEqual(2, lsn3); }
public void CanReadLogEntriesWithMultipleValues() { var filename = RandomFilename; _logManager = new LogManager(_fileManager, filename); var canAppend = _logManager.Append(new object[] { 1, 2, 3, "abc" }, out var lsn); var canAppend2 = _logManager.Append(new object[] { 4, 5, 6, "def" }, out var lsn2); _enumerator = _logManager.GetEnumerator(); var entry = _enumerator.Current; var canReadLogEntry1_1 = entry.NextInt(out var result1_1); var canReadLogEntry1_2 = entry.NextInt(out var result1_2); var canReadLogEntry1_3 = entry.NextInt(out var result1_3); var canReadLogEntry1_4 = entry.NextString(out var result1_4); var canMove1 = _enumerator.MoveNext(); var entry2 = _enumerator.Current; var canReadLogEntry2_1 = entry2.NextInt(out var result2_1); var canReadLogEntry2_2 = entry2.NextInt(out var result2_2); var canReadLogEntry2_3 = entry2.NextInt(out var result2_3); var canReadLogEntry2_4 = entry2.NextString(out var result2_4); var canMove2 = _enumerator.MoveNext(); _enumerator.Dispose(); Assert.IsTrue(canAppend); Assert.IsTrue(canAppend2); Assert.IsTrue(canReadLogEntry1_1); Assert.IsTrue(canReadLogEntry1_2); Assert.IsTrue(canReadLogEntry1_3); Assert.IsTrue(canReadLogEntry1_4); Assert.IsTrue(canReadLogEntry2_1); Assert.IsTrue(canReadLogEntry2_2); Assert.IsTrue(canReadLogEntry2_3); Assert.IsTrue(canReadLogEntry2_4); Assert.AreEqual(0, lsn); Assert.AreEqual(1, lsn2); Assert.IsTrue(canMove1); Assert.IsFalse(canMove2); Assert.AreEqual(4, result1_1); Assert.AreEqual(5, result1_2); Assert.AreEqual(6, result1_3); Assert.AreEqual("def", result1_4); Assert.AreEqual(1, result2_1); Assert.AreEqual(2, result2_2); Assert.AreEqual(3, result2_3); Assert.AreEqual("abc", result2_4); }
public void WouldNotWriteUnexpectedEntity() { var filename = RandomFilename; _logManager = new LogManager(_fileManager, filename); var canAppend = _logManager.Append(new object[] { new object() }, out var lsn); Assert.IsFalse(canAppend); Assert.AreEqual(default(int), lsn); }
public void CannotInsertRecordLongerThanALogRecord() { var filename = RandomFilename; _logManager = new LogManager(_fileManager, filename); var objects = new object[101]; for (int i = 0; i < 101; ++i) { objects[i] = true; } var canAppend = _logManager.Append(objects, out var lsn); Assert.IsFalse(canAppend); Assert.AreEqual(default(int), lsn); }
public void CanAppendBoolToLog() { var filename = RandomFilename; _logManager = new LogManager(_fileManager, filename); var canAppend = _logManager.Append(new object[] { true }, out var lsn); _logManager.Flush(lsn); var page = _fileManager.ResolvePage(); var canReadPage = page.Read(new Block(filename, lsn)); var canGetTotal = page.GetInt(0, out var totalBytes); var canReadValue = page.GetBool(4, out var value); Assert.True(canAppend); Assert.True(canReadPage); Assert.True(canGetTotal); Assert.True(canReadValue); Assert.AreEqual(sizeof(int) + sizeof(bool), totalBytes); Assert.AreEqual(true, value); }
public void CanAppendDateToLog() { var filename = RandomFilename; _logManager = new LogManager(_fileManager, filename); var date = new DateTime(2020, 1, 1); var canAppend = _logManager.Append(new object[] { date }, out var lsn); _logManager.Flush(lsn); var page = _fileManager.ResolvePage(); var canReadPage = page.Read(new Block(filename, lsn)); var canGetTotal = page.GetInt(0, out var totalBytes); var canReadValue = page.GetDate(4, out var value); Assert.True(canAppend); Assert.True(canReadPage); Assert.True(canGetTotal); Assert.True(canReadValue); Assert.AreEqual(sizeof(int) + sizeof(long), totalBytes); Assert.AreEqual(date, value); }
public void CanAppendStringToLog() { var filename = RandomFilename; _logManager = new LogManager(_fileManager, filename); var str = "123123"; var canAppend = _logManager.Append(new object[] { str }, out var lsn); _logManager.Flush(lsn); var page = _fileManager.ResolvePage(); var canReadPage = page.Read(new Block(filename, lsn)); var canGetTotal = page.GetInt(0, out var totalBytes); var canReadValue = page.GetString(4, out var value); Assert.True(canAppend); Assert.True(canReadPage); Assert.True(canGetTotal); Assert.True(canReadValue); Assert.AreEqual(sizeof(int) + sizeof(int) + str.Length, totalBytes); Assert.AreEqual(str, value); }
public void CanAppendBlobToLog() { var filename = RandomFilename; _logManager = new LogManager(_fileManager, filename); var arr = new byte[] { 1, 2, 3 }; var canAppend = _logManager.Append(new object[] { arr }, out var lsn); _logManager.Flush(lsn); var page = _fileManager.ResolvePage(); var canReadPage = page.Read(new Block(filename, lsn)); var canGetTotal = page.GetInt(0, out var totalBytes); var canReadValue = page.GetBlob(4, out var value); Assert.True(canAppend); Assert.True(canReadPage); Assert.True(canGetTotal); Assert.True(canReadValue); Assert.AreEqual(sizeof(int) + sizeof(int) + arr.Length, totalBytes); Assert.AreEqual(arr, value); }
public void CanStoreLogRecordsOnMultipleMemoryPages() { var storageString = "London is the capital of GB"; var filename = RandomFilename; _logManager = new LogManager(_fileManager, filename); var canAppend = _logManager.Append(new object[] { 1, 2, storageString }, out var lsn); var canAppend2 = _logManager.Append(new object[] { 3, 4, storageString }, out var lsn2); var canAppend3 = _logManager.Append(new object[] { 5, 6, storageString }, out var lsn3); _enumerator = _logManager.GetEnumerator(); var entry = _enumerator.Current; var canReadLogEntry1_1 = entry.NextInt(out var result1_1); var canReadLogEntry1_2 = entry.NextInt(out var result1_2); var canReadLogEntry1_3 = entry.NextString(out var result1_3); var canMove1 = _enumerator.MoveNext(); var entry2 = _enumerator.Current; var canReadLogEntry2_1 = entry2.NextInt(out var result2_1); var canReadLogEntry2_2 = entry2.NextInt(out var result2_2); var canReadLogEntry2_3 = entry2.NextString(out var result2_3); var canMove2 = _enumerator.MoveNext(); var entry3 = _enumerator.Current; var canReadLogEntry3_1 = entry3.NextInt(out var result3_1); var canReadLogEntry3_2 = entry3.NextInt(out var result3_2); var canReadLogEntry3_3 = entry3.NextString(out var result3_3); var canMove3 = _enumerator.MoveNext(); _enumerator.Dispose(); Assert.IsTrue(canAppend); Assert.IsTrue(canAppend2); Assert.IsTrue(canAppend3); Assert.IsTrue(canReadLogEntry1_1); Assert.IsTrue(canReadLogEntry1_2); Assert.IsTrue(canReadLogEntry1_3); Assert.IsTrue(canReadLogEntry2_1); Assert.IsTrue(canReadLogEntry2_2); Assert.IsTrue(canReadLogEntry2_3); Assert.IsTrue(canReadLogEntry3_1); Assert.IsTrue(canReadLogEntry3_2); Assert.IsTrue(canReadLogEntry3_3); Assert.AreEqual(0, lsn); Assert.AreEqual(1, lsn2); Assert.AreEqual(2, lsn3); Assert.IsTrue(canMove1); Assert.IsTrue(canMove2); Assert.IsFalse(canMove3); Assert.AreEqual(5, result1_1); Assert.AreEqual(6, result1_2); Assert.AreEqual(storageString, result1_3); Assert.AreEqual(3, result2_1); Assert.AreEqual(4, result2_2); Assert.AreEqual(storageString, result2_3); Assert.AreEqual(1, result3_1); Assert.AreEqual(2, result3_2); Assert.AreEqual(storageString, result3_3); }