public void GenericAppendOnlyFileSmokeTest() { var stream = new MemoryStream(); var data = new StreamAccessor(stream); var file = new LowLevelAppendOnlyFile(data); var serializer = new ProtoBufSerializationEngine(); var sut = new GenericAppendOnlyFile <TestClass>(file, serializer); sut.Append(new TestClass { Name = "Marcel", Address = "Kennesaw, GA" }); sut.Append(new TestClass { Name = "Gigi Meseriasu", Address = "Washington, DC" }); var r1 = sut.Read(0); Assert.AreEqual("Marcel", r1.Name); Assert.AreEqual("Kennesaw, GA", r1.Address); var rs = sut.ReadFrom(0).ToList(); var r2 = rs[1]; Assert.AreEqual("Gigi Meseriasu", r2.Name); Assert.AreEqual("Washington, DC", r2.Address); Assert.AreEqual(2, sut.Index.Length); Assert.AreEqual(0, sut.Index[0]); }
private static void Main() { var serializer = new ProtoBufSerializationEngine(); // the protobuf serializer might not be thread-safe var safeSerializer = new ConcurrentSerializationEngine(serializer); var list = new List <TestClass>(); for (var i = 0; i < COUNT; i++) { var c = new TestClass { Name = "N" + i, Address = "A" + i }; list.Add(c); } ShowTimeWithoutOpsPerSec("Overall - 1", () => { Run($"Sequentially writing and reading {COUNT} records", () => Generate1(@"d:\temp\1.tmp", safeSerializer, list, SeqForLoop)); Verify1(@"d:\temp\1.tmp", safeSerializer, list); Run($"Multi-threaded writing and reading {COUNT} records", () => Generate1(@"d:\temp\2.tmp", safeSerializer, list, ParForLoop)); Verify1(@"d:\temp\2.tmp", safeSerializer, list); }); ShowTimeWithoutOpsPerSec("Overall - 2", () => { Run($"Sequentially writing and reading {COUNT} records", () => Generate2(@"d:\temp\1.tmp", safeSerializer, list, SeqForLoop)); Verify2(@"d:\temp\1.tmp", safeSerializer, list); Run($"Multi-threaded writing and reading {COUNT} records", () => Generate2(@"d:\temp\2.tmp", safeSerializer, list, ParForLoop)); Verify2(@"d:\temp\2.tmp", safeSerializer, list); }); }
private static void Main(string[] args) { var serializer = new ProtoBufSerializationEngine(); var list = new List <TestClass>(); for (var i = 0; i < COUNT; i++) { var c = new TestClass { Name = GenerateRandomString(20), Address = GenerateRandomString(40) }; list.Add(c); } var tempFile = Path.GetTempFileName(); Console.WriteLine("Using {0} - sequentially writing and reading {1} records", tempFile, COUNT); Generate(tempFile, serializer, list, SeqForLoop); // verify the data using (var stream = new FileStream(tempFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) { var data = new StreamAccessor(stream); var lFile = new LowLevelAppendOnlyFile(data); var file = new GenericAppendOnlyFile <TestClass>(lFile, serializer); var records = file.ReadFrom(0).ToList(); // verify that the index is built correctly for (var i = 0; i < COUNT; i++) { var r = records[i]; Debug.Assert(r.Name == list[i].Name); Debug.Assert(r.Address == list[i].Address); } } // multi-threaded test tempFile = Path.GetTempFileName(); Console.WriteLine("Using {0} - multi-threaded writing and reading {1} records", tempFile, COUNT); Generate(tempFile, serializer, list, ParForLoop); }
private static void Main(string[] args) { var serializer = new ProtoBufSerializationEngine(); var list = new List<TestClass>(); for (var i = 0; i < COUNT; i++) { var c = new TestClass {Name = GenerateRandomString(20), Address = GenerateRandomString(40)}; list.Add(c); } var tempFile = Path.GetTempFileName(); Console.WriteLine("Using {0} - sequentially writing and reading {1} records", tempFile, COUNT); Generate(tempFile, serializer, list, SeqForLoop); // verify the data using (var stream = new FileStream(tempFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) { var data = new StreamAccessor(stream); var lFile = new LowLevelAppendOnlyFile(data); var file = new GenericAppendOnlyFile<TestClass>(lFile, serializer); var records = file.ReadFrom(0).ToList(); // verify that the index is built correctly for (var i = 0; i < COUNT; i++) { var r = records[i]; Debug.Assert(r.Name == list[i].Name); Debug.Assert(r.Address == list[i].Address); } } // multi-threaded test tempFile = Path.GetTempFileName(); Console.WriteLine("Using {0} - multi-threaded writing and reading {1} records", tempFile, COUNT); Generate(tempFile, serializer, list, ParForLoop); }
public void GenericAppendOnlyFileSmokeTest() { var stream = new MemoryStream(); var data = new StreamAccessor(stream); var file = new LowLevelAppendOnlyFile(data); var serializer = new ProtoBufSerializationEngine(); var sut = new GenericAppendOnlyFile<TestClass>(file, serializer); sut.Append(new TestClass {Name = "Marcel", Address = "Kennesaw, GA"}); sut.Append(new TestClass {Name = "Gigi Meseriasu", Address = "Washington, DC"}); var r1 = sut.Read(0); Assert.AreEqual("Marcel", r1.Name); Assert.AreEqual("Kennesaw, GA", r1.Address); var rs = sut.ReadFrom(0).ToList(); var r2 = rs[1]; Assert.AreEqual("Gigi Meseriasu", r2.Name); Assert.AreEqual("Washington, DC", r2.Address); Assert.AreEqual(2, sut.Index.Length); Assert.AreEqual(0, sut.Index[0]); }