public void AppLogRecord_Equals() { AppLogRecord r1, r2; r1 = new AppLogRecord(); r2 = new AppLogRecord(); Assert.IsTrue(r1.Equals(r2)); r1.Add("foo", "bar"); Assert.IsFalse(r1.Equals(r2)); r2.Add("foo", "bar"); Assert.IsTrue(r1.Equals(r2)); r1.Add("array", new byte[] { 1, 2, 3 }); Assert.IsFalse(r1.Equals(r2)); r2.Add("array", new byte[] { 1, 2, 3 }); r1.Equals(r2); Assert.IsTrue(r1.Equals(r2)); r1.Add("test", "string"); r2.Add("test", new byte[] { 0 }); Assert.IsFalse(r1.Equals(r2)); }
public void AppLogFile_ReadWrite_50() { string folder = TestFolder; AppLogFile logFile = null; AppLogRecord r; Helper.CreateFolderTree(folder); try { logFile = new AppLogFile(); logFile.Create(folder + "\\test.new", AppLog.DefBufferSize, "my schema", new Version("1.2.3.4")); for (int i = 0; i < 50; i++) { r = new AppLogRecord(); r.Add("Index", i.ToString()); r.Add("Foo", "Bar: " + i.ToString()); logFile.Write(r); } Assert.AreEqual(50, logFile.WriteCount); logFile.Close(); logFile = null; logFile = new AppLogFile(); logFile.Open(folder + "\\test.log", AppLog.DefBufferSize); for (int i = 0; i < 50; i++) { r = logFile.Read(); Assert.AreEqual(i, int.Parse((string)r["index"])); Assert.AreEqual("Bar: " + i.ToString(), (string)r["FOO"]); Assert.AreEqual("my schema", r.SchemaName); Assert.AreEqual(new Version("1.2.3.4"), r.SchemaVersion); } Assert.IsNull(logFile.Read()); Assert.IsNull(logFile.Read()); logFile.Close(); logFile = null; } finally { if (logFile != null) { logFile.Close(); } } DeleteFolder(folder); }
public void AppLogFile_ReadWrite_LargeFields() { string folder = TestFolder; AppLogFile logFile = null; AppLogRecord rWrite, rRead; byte[] arr; Helper.CreateFolderTree(folder); try { logFile = new AppLogFile(); logFile.Create(folder + "\\test.new", AppLog.DefBufferSize, "my schema", new Version("1.2.3.4")); arr = new byte[4096]; for (int i = 0; i < arr.Length; i++) { arr[i] = (byte)i; } rWrite = new AppLogRecord(); rWrite.Add("Foo", new string('x', 4096)); rWrite.Add("Bar", arr); logFile.Write(rWrite); Assert.AreEqual(1, logFile.WriteCount); logFile.Close(); logFile = null; logFile = new AppLogFile(); logFile.Open(folder + "\\test.log", AppLog.DefBufferSize); rRead = logFile.Read(); Assert.IsTrue(rWrite.Equals(rRead)); Assert.AreEqual("my schema", rRead.SchemaName); Assert.AreEqual(new Version("1.2.3.4"), rRead.SchemaVersion); Assert.IsNull(logFile.Read()); Assert.IsNull(logFile.Read()); logFile.Close(); logFile = null; } finally { if (logFile != null) { logFile.Close(); } } DeleteFolder(folder); }
public void AppLogFile_Peek_TwoRecords() { string folder = TestFolder; AppLogFile logFile = null; AppLogRecord r; Helper.CreateFolderTree(folder); try { logFile = new AppLogFile(); logFile.Create(folder + "\\test.new", AppLog.DefBufferSize, "my schema", new Version("1.2.3.4")); r = new AppLogRecord(); r.Add("index", "0"); logFile.Write(r); r = new AppLogRecord(); r.Add("index", "1"); logFile.Write(r); logFile.Close(); logFile = null; logFile = new AppLogFile(); logFile.Open(folder + "\\test.log", AppLog.DefBufferSize); r = logFile.Peek(); Assert.AreEqual("0", (string)r["index"]); r = logFile.Peek(); Assert.AreEqual("0", (string)r["index"]); r = logFile.Read(); Assert.AreEqual("0", (string)r["index"]); r = logFile.Peek(); Assert.AreEqual("1", (string)r["index"]); r = logFile.Read(); Assert.AreEqual("1", (string)r["index"]); Assert.IsNull(logFile.Peek()); Assert.IsNull(logFile.Read()); logFile.Close(); logFile = null; } finally { if (logFile != null) { logFile.Close(); } } DeleteFolder(folder); }
public void AppLogFile_ReadDelete() { string folder = TestFolder; AppLogFile logFile = null; AppLogRecord r; Helper.CreateFolderTree(folder); try { logFile = new AppLogFile(); logFile.Create(folder + "\\test.new", AppLog.DefBufferSize, "my schema", new Version("1.2.3.4")); for (int i = 0; i < 2; i++) { r = new AppLogRecord(); r.Add("Index", i.ToString()); logFile.Write(r); } logFile.Close(); logFile = null; logFile = new AppLogFile(); logFile.Open(folder + "\\test.log", AppLog.DefBufferSize); r = logFile.ReadDelete(); Assert.AreEqual(0, int.Parse((string)r["index"])); r = logFile.Read(); Assert.AreEqual(1, int.Parse((string)r["index"])); Assert.IsNull(logFile.Read()); Assert.IsNull(logFile.Read()); logFile.Close(); logFile = null; logFile = new AppLogFile(); logFile.Open(folder + "\\test.log", AppLog.DefBufferSize); r = logFile.Read(); Assert.AreEqual(1, int.Parse((string)r["index"])); logFile.Close(); logFile = null; } finally { if (logFile != null) { logFile.Close(); } } DeleteFolder(folder); }
public void AppLogRecord_ReadWrite() { EnhancedMemoryStream es = new EnhancedMemoryStream(); AppLogRecord r; for (int i = 0; i < 1000; i++) { byte[] arr; arr = new byte[i]; for (int j = 0; j < i; j++) { arr[j] = (byte)j; } r = new AppLogRecord(); r.Add("index", i.ToString()); r.Add("bytes", arr); r.Write(es); } es.Position = 0; for (int i = 0; i < 1000; i++) { byte[] arr; arr = new byte[i]; for (int j = 0; j < i; j++) { arr[j] = (byte)j; } r = new AppLogRecord(); r.Read(es); Assert.AreEqual(i.ToString(), (string)r["index"]); CollectionAssert.AreEqual(arr, (byte[])r["bytes"]); } Assert.IsTrue(es.Eof); }
public void AppLogFile_ReadWrite_ByteArray() { string folder = TestFolder; AppLogFile logFile = null; AppLogRecord rWrite, rRead; Helper.CreateFolderTree(folder); try { logFile = new AppLogFile(); logFile.Create(folder + "\\test.new", AppLog.DefBufferSize, "my schema", new Version("1.2.3.4")); rWrite = new AppLogRecord(); rWrite.Add("Foo", new byte[] { 0, 1, 2, 3 }); rWrite.Add("Bar", new byte[] { 5, 6, 7, 8 }); logFile.Write(rWrite); Assert.AreEqual(1, logFile.WriteCount); logFile.Close(); logFile = null; logFile = new AppLogFile(); logFile.Open(folder + "\\test.log", AppLog.DefBufferSize); rRead = logFile.Read(); Assert.IsTrue(rWrite.Equals(rRead)); Assert.AreEqual("my schema", rRead.SchemaName); Assert.AreEqual(new Version("1.2.3.4"), rRead.SchemaVersion); Assert.IsNull(logFile.Read()); Assert.IsNull(logFile.Read()); logFile.Close(); logFile = null; } finally { if (logFile != null) { logFile.Close(); } } DeleteFolder(folder); }
public void AppLogFile_Peek_OneRecord() { string folder = TestFolder; AppLogFile logFile = null; AppLogRecord rRead, rWrite; Helper.CreateFolderTree(folder); try { logFile = new AppLogFile(); logFile.Create(folder + "\\test.new", AppLog.DefBufferSize, "my schema", new Version("1.2.3.4")); rWrite = new AppLogRecord(); rWrite.Add("index", "0"); logFile.Write(rWrite); logFile.Close(); logFile = null; logFile = new AppLogFile(); logFile.Open(folder + "\\test.log", AppLog.DefBufferSize); rRead = logFile.Peek(); Assert.AreEqual(rWrite, rRead); Assert.AreEqual("my schema", rRead.SchemaName); Assert.AreEqual(new Version("1.2.3.4"), rRead.SchemaVersion); rRead = logFile.Peek(); Assert.AreEqual(rWrite, rRead); Assert.AreEqual("my schema", rRead.SchemaName); Assert.AreEqual(new Version("1.2.3.4"), rRead.SchemaVersion); rRead = logFile.Read(); Assert.AreEqual(rWrite, rRead); Assert.AreEqual("my schema", rRead.SchemaName); Assert.AreEqual(new Version("1.2.3.4"), rRead.SchemaVersion); Assert.IsNull(logFile.Peek()); Assert.IsNull(logFile.Read()); logFile.Close(); logFile = null; } finally { if (logFile != null) { logFile.Close(); } } DeleteFolder(folder); }
public void AppLog_ReadWrite_DefaultLocation() { string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"LillTek\AppLogs\Test"); AppLogWriter writer = null; AppLogReader reader = null; AppLogRecord rWrite, rRead; try { Helper.DeleteFile(folderPath, true); writer = AppLogWriter.Open("Test", "my schema", new Version("1.2.3.4"), 0); rWrite = new AppLogRecord(); rWrite.Add("Foo", "Bar"); writer.Write(rWrite); writer.Close(); writer = null; reader = AppLogReader.Open("Test"); rRead = reader.Read(); Assert.AreEqual(rWrite, rRead); Assert.AreEqual("my schema", rRead.SchemaName); Assert.AreEqual(new Version("1.2.3.4"), rRead.SchemaVersion); Assert.IsNull(reader.Read()); Assert.IsNull(reader.Read()); reader.Close(); reader = null; Assert.IsTrue(Directory.Exists(folderPath)); } finally { Config.SetConfig(null); if (writer != null) { writer.Close(); } if (reader != null) { reader.Close(); } Helper.DeleteFile(folderPath, true); } }
public void AppLogFile_LargeField() { string folder = TestFolder; AppLogFile logFile = null; AppLogRecord rWrite, rRead; byte[] data; data = new byte[2 * 1024 * 1024]; for (int i = 0; i < data.Length; i++) { data[i] = (byte)i; } Helper.CreateFolderTree(folder); try { logFile = new AppLogFile(); logFile.Create(folder + "\\test.new", AppLog.DefBufferSize, "my schema", new Version("1.2.3.4")); rWrite = new AppLogRecord(); rWrite.Add("data", data); logFile.Write(rWrite); Assert.AreEqual(1, logFile.WriteCount); logFile.Close(); logFile = null; logFile = new AppLogFile(); logFile.Open(folder + "\\test.log", AppLog.DefBufferSize); rRead = logFile.Read(); Assert.IsTrue(rWrite.Equals(rRead)); CollectionAssert.AreEqual(data, (byte[])rRead["data"]); Assert.IsNull(logFile.Read()); Assert.IsNull(logFile.Read()); logFile.Close(); logFile = null; } finally { if (logFile != null) { logFile.Close(); } } DeleteFolder(folder); }
public void AppLogFile_ReadWrite_4096Fields() { string folder = TestFolder; AppLogFile logFile = null; AppLogRecord rWrite, rRead; Helper.CreateFolderTree(folder); try { logFile = new AppLogFile(); logFile.Create(folder + "\\test.new", AppLog.DefBufferSize, "my schema", new Version("1.2.3.4")); rWrite = new AppLogRecord(); for (int i = 0; i < 4096; i++) { rWrite.Add(i.ToString(), i.ToString()); } logFile.Write(rWrite); Assert.AreEqual(1, logFile.WriteCount); logFile.Close(); logFile = null; logFile = new AppLogFile(); logFile.Open(folder + "\\test.log", AppLog.DefBufferSize); rRead = logFile.Read(); Assert.IsTrue(rWrite.Equals(rRead)); Assert.AreEqual("my schema", rRead.SchemaName); Assert.AreEqual(new Version("1.2.3.4"), rRead.SchemaVersion); Assert.IsNull(logFile.Read()); Assert.IsNull(logFile.Read()); logFile.Close(); logFile = null; } finally { if (logFile != null) { logFile.Close(); } } DeleteFolder(folder); }
public void AppLogRecord_ReadWrite_LargeString() { EnhancedMemoryStream es = new EnhancedMemoryStream(); AppLogRecord r; string s; s = new String('x', 1000000); r = new AppLogRecord(); r.Add("string", s); r.Write(es); es.Position = 0; r = new AppLogRecord(); r.Read(es); Assert.AreEqual(s, (string)r["string"]); }
public void AppLogFile_CreateDate() { string folder = TestFolder; AppLogFile logFile = null; AppLogRecord r; DateTime now; Helper.CreateFolderTree(folder); try { now = DateTime.UtcNow; logFile = new AppLogFile(); logFile.Create(folder + "\\test.new", AppLog.DefBufferSize, "my schema", new Version("1.2.3.4")); r = new AppLogRecord(); r.Add("Foo", "Bar"); logFile.Write(r); Assert.AreEqual(1, logFile.WriteCount); logFile.Close(); logFile = null; logFile = new AppLogFile(); logFile.Open(folder + "\\test.log", AppLog.DefBufferSize); Assert.IsTrue(now - TimeSpan.FromSeconds(2) <= logFile.CreateDate && logFile.CreateDate <= now + TimeSpan.FromSeconds(2)); logFile.Close(); logFile = null; } finally { if (logFile != null) { logFile.Close(); } } DeleteFolder(folder); }
public void AppLogRecord_ReadWrite_LargeByteArray() { EnhancedMemoryStream es = new EnhancedMemoryStream(); AppLogRecord r; byte[] arr; arr = new byte[1000000]; for (int j = 0; j < arr.Length; j++) { arr[j] = (byte)j; } r = new AppLogRecord(); r.Add("bytes", arr); r.Write(es); es.Position = 0; r = new AppLogRecord(); r.Read(es); CollectionAssert.AreEqual(arr, (byte[])r["bytes"]); }
public void AppLog_PersistReaderPos() { string config = @" §ion LillTek.AppLog RootFolder = {0} MaxFileSize = 4096 BufferSize = 128K IdleCommitInterval = 5m &endsection "; string root = TestFolder; string folder = root + "\\AppLogs"; AppLogWriter writer = null; AppLogReader reader = null; AppLogRecord r; Helper.CreateFolderTree(root); try { Config.SetConfig(string.Format(config, folder).Replace('&', '#')); folder += "\\Test"; writer = AppLogWriter.Open("Test", "my schema", new Version("1.2.3.4"), 0); for (int i = 0; i < 5; i++) { r = new AppLogRecord(); r.Add("index", i.ToString()); writer.Write(r); } writer.Commit(); for (int i = 5; i < 10; i++) { r = new AppLogRecord(); r.Add("index", i.ToString()); writer.Write(r); } writer.Commit(); for (int i = 0; i < 10; i++) { reader = AppLogReader.Open("Test"); r = reader.Read(); Assert.AreEqual(i.ToString(), r["index"]); reader.Close(); reader = null; } r = new AppLogRecord(); r.Add("index", "10"); writer.Write(r); writer.Commit(); reader = AppLogReader.Open("Test"); r = reader.Read(); Assert.AreEqual("10", r["index"]); reader.Close(); reader = null; writer.Close(); writer = null; } finally { Config.SetConfig(null); if (writer != null) { writer.Close(); } if (reader != null) { reader.Close(); } } DeleteFolder(root); }
public void AppLog_RecordAvailableEvent() { string config = @" §ion LillTek.AppLog RootFolder = {0} MaxFileSize = 4096 BufferSize = 128K IdleCommitInterval = 5m &endsection "; string root = TestFolder; string folder = root + "\\AppLogs"; AppLogWriter writer = null; AppLogReader reader = null; AppLogRecord r; Helper.CreateFolderTree(root); try { Config.SetConfig(string.Format(config, folder).Replace('&', '#')); folder += "\\Test"; newRecords = false; writer = AppLogWriter.Open("Test", "my schema", new Version("1.2.3.4"), 0); reader = AppLogReader.Open("Test"); reader.RecordAvailable += new LogRecordAvailableHandler(OnRecordAvailable); Assert.IsNull(reader.Read()); r = new AppLogRecord(); r.Add("foo", "bar"); writer.Write(r); writer.Commit(); Thread.Sleep(4000); // Give the record available event a chance to be raised Assert.IsTrue(newRecords); r = reader.Read(); Assert.AreEqual("bar", r["foo"]); } finally { Config.SetConfig(null); if (writer != null) { writer.Close(); } if (reader != null) { reader.Close(); } } DeleteFolder(root); }
public void AppLogFile_Position() { string folder = TestFolder; AppLogFile logFile = null; string[] positions; AppLogRecord r; Helper.CreateFolderTree(folder); try { logFile = new AppLogFile(); logFile.Create(folder + "\\test.new", AppLog.DefBufferSize, "my schema", new Version("1.2.3.4")); positions = new string[50]; for (int i = 0; i < positions.Length; i++) { r = new AppLogRecord(); r.Add("Index", i.ToString()); logFile.Write(r); } Assert.AreEqual(50, logFile.WriteCount); logFile.Close(); logFile = null; logFile = new AppLogFile(); logFile.Open(folder + "\\test.log", AppLog.DefBufferSize); // Verify that we can seek to all records. for (int i = 0; i < 50; i++) { positions[i] = logFile.Position; r = logFile.Read(); Assert.AreEqual(i, int.Parse((string)r["index"])); } for (int i = 49; i >= 0; i--) { logFile.Position = positions[i]; r = logFile.Read(); Assert.AreEqual(i, int.Parse((string)r["index"])); } // Verify that read after seek to a deleted record // returns the record after the deleted one. logFile.Position = positions[25]; r = logFile.ReadDelete(); Assert.AreEqual(25, int.Parse((string)r["index"])); logFile.Position = positions[25]; r = logFile.ReadDelete(); Assert.AreEqual(26, int.Parse((string)r["index"])); // Verify that seek("END") actually goes to the end logFile.Position = "END"; Assert.IsNull(logFile.Read()); logFile.Close(); logFile = null; } finally { if (logFile != null) { logFile.Close(); } } DeleteFolder(folder); }
public void AppLogFile_Position_Bad() { string folder = TestFolder; AppLogFile logFile = null; string[] positions; AppLogRecord r; Helper.CreateFolderTree(folder); try { logFile = new AppLogFile(); logFile.Create(folder + "\\test.new", AppLog.DefBufferSize, "my schema", new Version("1.2.3.4")); positions = new string[50]; for (int i = 0; i < positions.Length; i++) { r = new AppLogRecord(); r.Add("Index", i.ToString()); logFile.Write(r); } Assert.AreEqual(50, logFile.WriteCount); logFile.Close(); logFile = null; logFile = new AppLogFile(); logFile.Open(folder + "\\test.log", AppLog.DefBufferSize); for (int i = 0; i < 50; i++) { positions[i] = logFile.Position; r = logFile.Read(); Assert.AreEqual(i, int.Parse((string)r["index"])); } for (int i = 49; i >= 0; i--) { logFile.Position = positions[i]; r = logFile.Read(); Assert.AreEqual(i, int.Parse((string)r["index"])); } // Verify that seeking to an invalid position in the // log file throws an exception. try { logFile.Position = (int.Parse(positions[1]) + 1).ToString(); Assert.Fail("Expected a LogException"); } catch (Exception e) { Assert.AreEqual(typeof(ArgumentException).Name, e.GetType().Name); } logFile.Close(); logFile = null; } finally { if (logFile != null) { logFile.Close(); } } DeleteFolder(folder); }
public void AppLogFile_ReadDelete_All() { string folder = TestFolder; AppLogFile logFile = null; AppLogRecord r; Helper.CreateFolderTree(folder); try { logFile = new AppLogFile(); logFile.Create(folder + "\\test.new", AppLog.DefBufferSize, "my schema", new Version("1.2.3.4")); for (int i = 0; i < 2; i++) { r = new AppLogRecord(); r.Add("Index", i.ToString()); logFile.Write(r); } logFile.Close(); logFile = null; logFile = new AppLogFile(); logFile.Open(folder + "\\test.log", AppLog.DefBufferSize); r = logFile.ReadDelete(); Assert.AreEqual(0, int.Parse((string)r["index"])); r = logFile.Read(); Assert.AreEqual(1, int.Parse((string)r["index"])); Assert.IsNull(logFile.Read()); Assert.IsNull(logFile.Read()); logFile.Close(); logFile = null; logFile = new AppLogFile(); logFile.Open(folder + "\\test.log", AppLog.DefBufferSize); r = logFile.ReadDelete(); Assert.AreEqual(1, int.Parse((string)r["index"])); logFile.Close(); logFile = null; // Verify that the log file was deleted when all all // records were marked for deletion. Assert.AreEqual(0, Directory.GetFiles(folder, "*.new").Length); Assert.AreEqual(0, Directory.GetFiles(folder, "*.log").Length); } finally { if (logFile != null) { logFile.Close(); } } DeleteFolder(folder); }
public void AppLog_Peek() { string config = @" §ion LillTek.AppLog RootFolder = {0} MaxFileSize = 4096 BufferSize = 128K IdleCommitInterval = 5m &endsection "; string root = TestFolder; string folder = root + "\\AppLogs"; AppLogWriter writer = null; AppLogReader reader = null; AppLogRecord r; Helper.CreateFolderTree(root); try { Config.SetConfig(string.Format(config, folder).Replace('&', '#')); folder += "\\Test"; writer = AppLogWriter.Open("Test", "my schema", new Version("1.2.3.4"), 0); r = new AppLogRecord(); r.Add("index", "0"); writer.Write(r); r = new AppLogRecord(); r.Add("index", "1"); writer.Write(r); r = new AppLogRecord(); r.Add("index", "2"); writer.Write(r); writer.Close(); writer = null; //----------------------------------------- reader = AppLogReader.Open("Test"); r = reader.Peek(); Assert.AreEqual("0", (string)r["index"]); r = reader.Peek(); Assert.AreEqual("0", (string)r["index"]); r = reader.Read(); Assert.AreEqual("0", (string)r["index"]); r = reader.Peek(); Assert.AreEqual("1", (string)r["index"]); r = reader.Peek(); Assert.AreEqual("1", (string)r["index"]); r = reader.Read(); Assert.AreEqual("1", (string)r["index"]); r = reader.Peek(); Assert.AreEqual("2", (string)r["index"]); r = reader.Peek(); Assert.AreEqual("2", (string)r["index"]); r = reader.Read(); Assert.AreEqual("2", (string)r["index"]); Assert.IsNull(reader.Peek()); Assert.IsNull(reader.Peek()); Assert.IsNull(reader.Read()); Assert.IsNull(reader.Read()); reader.Close(); reader = null; //----------------------------------------- reader = AppLogReader.Open("Test"); reader.Position = "BEGINNING"; r = reader.ReadDelete(); Assert.AreEqual("0", (string)r["index"]); r = reader.Peek(); Assert.AreEqual("1", (string)r["index"]); r = reader.Peek(); Assert.AreEqual("1", (string)r["index"]); r = reader.Read(); Assert.AreEqual("1", (string)r["index"]); r = reader.Peek(); Assert.AreEqual("2", (string)r["index"]); r = reader.Peek(); Assert.AreEqual("2", (string)r["index"]); r = reader.Read(); Assert.AreEqual("2", (string)r["index"]); Assert.IsNull(reader.Peek()); Assert.IsNull(reader.Peek()); Assert.IsNull(reader.Read()); Assert.IsNull(reader.Read()); reader.Close(); reader = null; //----------------------------------------- reader = AppLogReader.Open("Test"); reader.Position = "BEGINNING"; r = reader.Peek(); Assert.AreEqual("1", (string)r["index"]); r = reader.Peek(); Assert.AreEqual("1", (string)r["index"]); r = reader.Read(); Assert.AreEqual("1", (string)r["index"]); r = reader.Peek(); Assert.AreEqual("2", (string)r["index"]); r = reader.Peek(); Assert.AreEqual("2", (string)r["index"]); r = reader.ReadDelete(); Assert.AreEqual("2", (string)r["index"]); Assert.IsNull(reader.Peek()); Assert.IsNull(reader.Peek()); Assert.IsNull(reader.ReadDelete()); Assert.IsNull(reader.ReadDelete()); reader.Close(); reader = null; //----------------------------------------- reader = AppLogReader.Open("Test"); reader.Position = "BEGINNING"; r = reader.Peek(); Assert.AreEqual("1", (string)r["index"]); r = reader.Peek(); Assert.AreEqual("1", (string)r["index"]); r = reader.ReadDelete(); Assert.AreEqual("1", (string)r["index"]); Assert.IsNull(reader.Peek()); Assert.IsNull(reader.Peek()); Assert.IsNull(reader.ReadDelete()); Assert.IsNull(reader.ReadDelete()); reader.Close(); reader = null; //----------------------------------------- reader = AppLogReader.Open("Test"); reader.Position = "BEGINNING"; Assert.IsNull(reader.Peek()); Assert.IsNull(reader.Peek()); Assert.IsNull(reader.Read()); Assert.IsNull(reader.ReadDelete()); reader.Close(); reader = null; } finally { Config.SetConfig(null); if (writer != null) { writer.Close(); } if (reader != null) { reader.Close(); } } DeleteFolder(root); }
public void AppLog_Idle_Commit() { string config = @" §ion LillTek.AppLog RootFolder = {0} MaxFileSize = 4096 BufferSize = 128K IdleCommitInterval = 2s &endsection "; string root = TestFolder; string folder = root + "\\AppLogs"; AppLogWriter writer = null; AppLogReader reader = null; AppLogRecord r; Helper.CreateFolderTree(root); try { Config.SetConfig(string.Format(config, folder).Replace('&', '#')); folder += "\\Test"; writer = AppLogWriter.Open("Test", "my schema", new Version("1.2.3.4"), 0); r = new AppLogRecord(); r.Add("Index", "1"); writer.Write(r); Thread.Sleep(4000); // Long enough for an idle commit Assert.AreEqual(1, Directory.GetFiles(folder, "*.log").Length); r = new AppLogRecord(); r.Add("Index", "2"); writer.Write(r); Thread.Sleep(4000); // Long enough for an idle commit Assert.AreEqual(2, Directory.GetFiles(folder, "*.log").Length); reader = AppLogReader.Open("Test"); r = reader.Read(); Assert.AreEqual("1", r["index"]); r = reader.Read(); Assert.AreEqual("2", r["index"]); Assert.IsNull(reader.Read()); Assert.IsNull(reader.Read()); } finally { Config.SetConfig(null); if (writer != null) { writer.Close(); } if (reader != null) { reader.Close(); } } DeleteFolder(root); }
public void AppLog_Position_END() { string config = @" §ion LillTek.AppLog RootFolder = {0} MaxFileSize = 4096 BufferSize = 128K IdleCommitInterval = 5m &endsection "; string root = TestFolder; string folder = root + "\\AppLogs"; AppLogWriter writer = null; AppLogReader reader = null; AppLogRecord r; byte[] data; string posEnd; data = new byte[2048]; for (int i = 0; i < data.Length; i++) { data[i] = (byte)i; } Helper.CreateFolderTree(root); try { Config.SetConfig(string.Format(config, folder).Replace('&', '#')); folder += "\\Test"; writer = AppLogWriter.Open("Test", "my schema", new Version("1.2.3.4"), 0); for (int i = 0; i < 10; i++) { r = new AppLogRecord(); r.Add("Index", i.ToString()); r.Add("Data", data); writer.Write(r); } writer.Commit(); Assert.AreEqual(5, Directory.GetFiles(folder, "*.log").Length); Assert.AreEqual(1, Directory.GetFiles(folder, "*.new").Length); Assert.IsTrue(File.Exists(folder + "\\Writer.lock")); reader = AppLogReader.Open("Test"); for (int i = 0; i < 10; i++) { r = reader.ReadDelete(); Assert.AreEqual("my schema", r.SchemaName); Assert.AreEqual(new Version("1.2.3.4"), r.SchemaVersion); Assert.AreEqual(i.ToString(), r["index"]); CollectionAssert.AreEqual(data, (byte[])r["data"]); } Assert.IsNull(reader.ReadDelete()); Assert.IsNull(reader.ReadDelete()); posEnd = reader.Position; r = new AppLogRecord(); r.Add("Index", "10"); r.Add("Data", data); writer.Write(r); writer.Commit(); Assert.AreEqual(1, Directory.GetFiles(folder, "*.log").Length); reader.Position = posEnd; r = reader.Read(); Assert.AreEqual("10", r["index"]); CollectionAssert.AreEqual(data, (byte[])r["data"]); } finally { Config.SetConfig(null); if (writer != null) { writer.Close(); } if (reader != null) { reader.Close(); } } DeleteFolder(root); }
public void AppLog_ReadWrite_SpecificLocation() { string config = @" §ion LillTek.AppLog RootFolder = {0} MaxFileSize = 4096 BufferSize = 128K IdleCommitInterval = 5m &endsection "; string root = TestFolder; string folder = root + "\\AppLogs"; AppLogWriter writer = null; AppLogReader reader = null; AppLogRecord rWrite, rRead; Helper.CreateFolderTree(root); try { Config.SetConfig(string.Format(config, folder).Replace('&', '#')); folder += "\\Test"; writer = AppLogWriter.Open("Test", "my schema", new Version("1.2.3.4"), 0); rWrite = new AppLogRecord(); rWrite.Add("Foo", "Bar"); writer.Write(rWrite); writer.Close(); writer = null; reader = AppLogReader.Open("Test"); rRead = reader.Read(); Assert.AreEqual(rWrite, rRead); Assert.AreEqual("my schema", rRead.SchemaName); Assert.AreEqual(new Version("1.2.3.4"), rRead.SchemaVersion); Assert.IsNull(reader.Read()); Assert.IsNull(reader.Read()); reader.Close(); reader = null; } finally { Config.SetConfig(null); if (writer != null) { writer.Close(); } if (reader != null) { reader.Close(); } } DeleteFolder(root); }