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_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_Commit() { 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", "1"); writer.Write(r); writer.Commit(); Assert.AreEqual(1, Directory.GetFiles(folder, "*.log").Length); r = new AppLogRecord(); r.Add("Index", "2"); writer.Write(r); writer.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_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); }