From f0208d1cc9db8cae51809cc58e09edbccee1aaa3 Mon Sep 17 00:00:00 2001 From: MASES Public Developers Team <94312179+masesdevelopers@users.noreply.github.com> Date: Thu, 5 Oct 2023 20:06:05 +0200 Subject: [PATCH] Aligned to KNet 2.1.1 (#72) --- src/net/KEFCore/KEFCore.csproj | 4 +- test/KEFCore.Test/Program.cs | 209 +++++++++++++++++---------------- 2 files changed, 113 insertions(+), 100 deletions(-) diff --git a/src/net/KEFCore/KEFCore.csproj b/src/net/KEFCore/KEFCore.csproj index ff1d0029..936be2e3 100644 --- a/src/net/KEFCore/KEFCore.csproj +++ b/src/net/KEFCore/KEFCore.csproj @@ -66,11 +66,11 @@ - + All None - + diff --git a/test/KEFCore.Test/Program.cs b/test/KEFCore.Test/Program.cs index c744729c..f9ea5251 100644 --- a/test/KEFCore.Test/Program.cs +++ b/test/KEFCore.Test/Program.cs @@ -52,6 +52,10 @@ static void ReportString(string message) static void Main(string[] args) { + BloggingContext context = null; + var testWatcher = new Stopwatch(); + var globalWatcher = new Stopwatch(); + if (args.Length > 0) { config = JsonSerializer.Deserialize(File.ReadAllText(args[0])); @@ -64,36 +68,38 @@ static void Main(string[] args) var databaseName = config.UseModelBuilder ? config.DatabaseNameWithModel : config.DatabaseName; - var globalWatcher = Stopwatch.StartNew(); - StreamsConfigBuilder streamConfig = null; - if (!config.UseInMemoryProvider) + try { - streamConfig = StreamsConfigBuilder.Create(); - streamConfig = streamConfig.WithAcceptableRecoveryLag(100); - } + globalWatcher.Start(); + StreamsConfigBuilder streamConfig = null; + if (!config.UseInMemoryProvider) + { + streamConfig = StreamsConfigBuilder.Create(); + streamConfig = streamConfig.WithAcceptableRecoveryLag(100); + } - var context = new BloggingContext() - { - BootstrapServers = config.BootstrapServers, - ApplicationId = config.ApplicationId, - DbName = databaseName, - StreamsConfigBuilder = streamConfig, - }; + context = new BloggingContext() + { + BootstrapServers = config.BootstrapServers, + ApplicationId = config.ApplicationId, + DbName = databaseName, + StreamsConfigBuilder = streamConfig, + }; - if (config.DeleteApplication) - { - context.Database.EnsureDeleted(); - context.Database.EnsureCreated(); - } + if (config.DeleteApplication) + { + context.Database.EnsureDeleted(); + context.Database.EnsureCreated(); + } - var testWatcher = Stopwatch.StartNew(); - Stopwatch watch = Stopwatch.StartNew(); - for (int i = 0; i < config.NumberOfElements; i++) - { - context.Add(new Blog + testWatcher.Start(); + Stopwatch watch = Stopwatch.StartNew(); + for (int i = 0; i < config.NumberOfElements; i++) { - Url = "http://blogs.msdn.com/adonet" + i.ToString(), - Posts = new List() + context.Add(new Blog + { + Url = "http://blogs.msdn.com/adonet" + i.ToString(), + Posts = new List() { new Post() { @@ -101,66 +107,66 @@ static void Main(string[] args) Content = i.ToString() } }, - Rating = i, - }); - } - watch.Stop(); - ReportString($"Elapsed data load {watch.ElapsedMilliseconds} ms"); + Rating = i, + }); + } + watch.Stop(); + ReportString($"Elapsed data load {watch.ElapsedMilliseconds} ms"); - watch.Restart(); - context.SaveChanges(); - watch.Stop(); - ReportString($"Elapsed SaveChanges {watch.ElapsedMilliseconds} ms"); + watch.Restart(); + context.SaveChanges(); + watch.Stop(); + ReportString($"Elapsed SaveChanges {watch.ElapsedMilliseconds} ms"); + + if (config.UseModelBuilder) + { + watch.Restart(); + var pageObject = (from op in context.Blogs + join pg in context.Posts on op.BlogId equals pg.BlogId + where pg.BlogId == op.BlogId + select new { pg, op }).SingleOrDefault(); + watch.Stop(); + ReportString($"Elapsed UseModelBuilder {watch.ElapsedMilliseconds} ms"); + } - if (config.UseModelBuilder) - { watch.Restart(); - var pageObject = (from op in context.Blogs - join pg in context.Posts on op.BlogId equals pg.BlogId - where pg.BlogId == op.BlogId - select new { pg, op }).SingleOrDefault(); + var post = context.Posts.Single(b => b.BlogId == 2); watch.Stop(); - ReportString($"Elapsed UseModelBuilder {watch.ElapsedMilliseconds} ms"); - } + ReportString($"Elapsed context.Posts.Single(b => b.BlogId == 2) {watch.ElapsedMilliseconds} ms. Result is {post}"); - watch.Restart(); - var post = context.Posts.Single(b => b.BlogId == 2); - watch.Stop(); - ReportString($"Elapsed context.Posts.Single(b => b.BlogId == 2) {watch.ElapsedMilliseconds} ms. Result is {post}"); - - watch.Restart(); - post = context.Posts.Single(b => b.BlogId == 1); - watch.Stop(); - ReportString($"Elapsed context.Posts.Single(b => b.BlogId == 1) {watch.ElapsedMilliseconds} ms. Result is {post}"); - - watch.Restart(); - var all = context.Posts.All((o) => true); - watch.Stop(); - ReportString($"Elapsed context.Posts.All((o) => true) {watch.ElapsedMilliseconds} ms. Result is {all}"); - - watch.Restart(); - var blog = context.Blogs!.Single(b => b.BlogId == 1); - watch.Stop(); - ReportString($"Elapsed context.Blogs!.Single(b => b.BlogId == 1) {watch.ElapsedMilliseconds} ms. Result is {blog}"); - - watch.Restart(); - context.Remove(post); - context.Remove(blog); - watch.Stop(); - ReportString($"Elapsed data remove {watch.ElapsedMilliseconds} ms"); - - watch.Restart(); - context.SaveChanges(); - watch.Stop(); - ReportString($"Elapsed SaveChanges {watch.ElapsedMilliseconds} ms"); - - watch.Restart(); - for (int i = config.NumberOfElements; i < config.NumberOfElements + config.NumberOfExtraElements; i++) - { - context.Add(new Blog + watch.Restart(); + post = context.Posts.Single(b => b.BlogId == 1); + watch.Stop(); + ReportString($"Elapsed context.Posts.Single(b => b.BlogId == 1) {watch.ElapsedMilliseconds} ms. Result is {post}"); + + watch.Restart(); + var all = context.Posts.All((o) => true); + watch.Stop(); + ReportString($"Elapsed context.Posts.All((o) => true) {watch.ElapsedMilliseconds} ms. Result is {all}"); + + watch.Restart(); + var blog = context.Blogs!.Single(b => b.BlogId == 1); + watch.Stop(); + ReportString($"Elapsed context.Blogs!.Single(b => b.BlogId == 1) {watch.ElapsedMilliseconds} ms. Result is {blog}"); + + watch.Restart(); + context.Remove(post); + context.Remove(blog); + watch.Stop(); + ReportString($"Elapsed data remove {watch.ElapsedMilliseconds} ms"); + + watch.Restart(); + context.SaveChanges(); + watch.Stop(); + ReportString($"Elapsed SaveChanges {watch.ElapsedMilliseconds} ms"); + + watch.Restart(); + for (int i = config.NumberOfElements; i < config.NumberOfElements + config.NumberOfExtraElements; i++) { - Url = "http://blogs.msdn.com/adonet" + i.ToString(), - Posts = new List() + context.Add(new Blog + { + Url = "http://blogs.msdn.com/adonet" + i.ToString(), + Posts = new List() { new Post() { @@ -168,28 +174,35 @@ join pg in context.Posts on op.BlogId equals pg.BlogId Content = i.ToString() } }, - Rating = i, - }); - } - watch.Stop(); - ReportString($"Elapsed data load {watch.ElapsedMilliseconds} ms"); - - watch.Restart(); - context.SaveChanges(); - watch.Stop(); - ReportString($"Elapsed SaveChanges {watch.ElapsedMilliseconds} ms"); + Rating = i, + }); + } + watch.Stop(); + ReportString($"Elapsed data load {watch.ElapsedMilliseconds} ms"); - watch.Restart(); - post = context.Posts.Single(b => b.BlogId == 1009); - watch.Stop(); - ReportString($"Elapsed context.Posts.Single(b => b.BlogId == 1009) {watch.ElapsedMilliseconds} ms. Result is {post}"); + watch.Restart(); + context.SaveChanges(); + watch.Stop(); + ReportString($"Elapsed SaveChanges {watch.ElapsedMilliseconds} ms"); - var value = context.Blogs.AsQueryable().ToQueryString(); + watch.Restart(); + post = context.Posts.Single(b => b.BlogId == 1009); + watch.Stop(); + ReportString($"Elapsed context.Posts.Single(b => b.BlogId == 1009) {watch.ElapsedMilliseconds} ms. Result is {post}"); - context?.Dispose(); - testWatcher.Stop(); - globalWatcher.Stop(); - Console.WriteLine($"Full test completed in {globalWatcher.Elapsed}, only tests completed in {testWatcher.Elapsed}"); + var value = context.Blogs.AsQueryable().ToQueryString(); + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + } + finally + { + context?.Dispose(); + testWatcher.Stop(); + globalWatcher.Stop(); + Console.WriteLine($"Full test completed in {globalWatcher.Elapsed}, only tests completed in {testWatcher.Elapsed}"); + } } }