diff --git a/test/KEFCore.Test.InMemory/KEFCore.Test.InMemory.csproj b/test/KEFCore.Test.InMemory/KEFCore.Test.InMemory.csproj deleted file mode 100644 index eada7b8a..00000000 --- a/test/KEFCore.Test.InMemory/KEFCore.Test.InMemory.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - - Exe - MASES.EntityFrameworkCore.KNet.Test.InMemory - MASES.EntityFrameworkCore.KNet.Test.InMemory - EntityFrameworkCore InMemory Test - EntityFrameworkCore InMemory Test - MASES.EntityFrameworkCore.KNet.Test.InMemory - ..\..\bin\ - - - - - - - - - - diff --git a/test/KEFCore.Test.InMemory/ProgramConfig.cs b/test/KEFCore.Test.InMemory/ProgramConfig.cs deleted file mode 100644 index 429dcef3..00000000 --- a/test/KEFCore.Test.InMemory/ProgramConfig.cs +++ /dev/null @@ -1,35 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2022 MASES s.r.l. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -namespace MASES.EntityFrameworkCore.KNet.Test -{ - partial class Program - { - public static bool UseInMemoryProvider = true; - public static bool UseModelBuilder = false; - public static bool UseCompactedReplicator = false; - public static string DatabaseName = null; - static bool deleteApplication = false; - } -} diff --git a/test/KEFCore.Test.Replicator/KEFCore.Test.Replicator.csproj b/test/KEFCore.Test.Replicator/KEFCore.Test.Replicator.csproj deleted file mode 100644 index ea21d142..00000000 --- a/test/KEFCore.Test.Replicator/KEFCore.Test.Replicator.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - - Exe - MASES.EntityFrameworkCore.KNet.Test.Replicator - MASES.EntityFrameworkCore.KNet.Test.Replicator - EntityFrameworkCore Replicator Test - EntityFrameworkCore Replicator Test - MASES.EntityFrameworkCore.KNet.Test.Replicator - ..\..\bin\ - - - - - - - - - - diff --git a/test/KEFCore.Test.Replicator/ProgramConfig.cs b/test/KEFCore.Test.Replicator/ProgramConfig.cs deleted file mode 100644 index 8b687633..00000000 --- a/test/KEFCore.Test.Replicator/ProgramConfig.cs +++ /dev/null @@ -1,35 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2022 MASES s.r.l. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -namespace MASES.EntityFrameworkCore.KNet.Test -{ - partial class Program - { - public static bool UseInMemoryProvider = false; - public static bool UseModelBuilder = false; - public static bool UseCompactedReplicator = true; - public static string DatabaseName = null; - static bool deleteApplication = false; - } -} diff --git a/test/KEFCore.Test.sln b/test/KEFCore.Test.sln index 43a08ec0..a6a95ddf 100644 --- a/test/KEFCore.Test.sln +++ b/test/KEFCore.Test.sln @@ -7,14 +7,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KEFCore.Test", "KEFCore.Tes EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KEFCore", "..\src\net\KEFCore\KEFCore.csproj", "{BB85D638-A032-41F5-9118-3264F6F6D14C}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KEFCore.Test.InMemory", "KEFCore.Test.InMemory\KEFCore.Test.InMemory.csproj", "{B32C7AB4-6B7D-4CDF-B18E-467B9757D231}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{B35B16BB-890F-4385-AB20-7AA4DD6E9C01}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{4A0AD520-9BC4-4F92-893B-6F92BBC35BFA}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KEFCore.Test.Replicator", "KEFCore.Test.Replicator\KEFCore.Test.Replicator.csproj", "{6FE8F586-4EA6-496E-AC8D-53F5C25E5388}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -29,14 +25,6 @@ Global {BB85D638-A032-41F5-9118-3264F6F6D14C}.Debug|Any CPU.Build.0 = Debug|Any CPU {BB85D638-A032-41F5-9118-3264F6F6D14C}.Release|Any CPU.ActiveCfg = Release|Any CPU {BB85D638-A032-41F5-9118-3264F6F6D14C}.Release|Any CPU.Build.0 = Release|Any CPU - {B32C7AB4-6B7D-4CDF-B18E-467B9757D231}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B32C7AB4-6B7D-4CDF-B18E-467B9757D231}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B32C7AB4-6B7D-4CDF-B18E-467B9757D231}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B32C7AB4-6B7D-4CDF-B18E-467B9757D231}.Release|Any CPU.Build.0 = Release|Any CPU - {6FE8F586-4EA6-496E-AC8D-53F5C25E5388}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6FE8F586-4EA6-496E-AC8D-53F5C25E5388}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6FE8F586-4EA6-496E-AC8D-53F5C25E5388}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6FE8F586-4EA6-496E-AC8D-53F5C25E5388}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -44,8 +32,6 @@ Global GlobalSection(NestedProjects) = preSolution {6999B7F3-6887-41CE-B1E9-2CE6BB881FDA} = {4A0AD520-9BC4-4F92-893B-6F92BBC35BFA} {BB85D638-A032-41F5-9118-3264F6F6D14C} = {B35B16BB-890F-4385-AB20-7AA4DD6E9C01} - {B32C7AB4-6B7D-4CDF-B18E-467B9757D231} = {4A0AD520-9BC4-4F92-893B-6F92BBC35BFA} - {6FE8F586-4EA6-496E-AC8D-53F5C25E5388} = {4A0AD520-9BC4-4F92-893B-6F92BBC35BFA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {36C294ED-9ECE-42AA-8273-31E008749AF3} diff --git a/test/KEFCore.Test/InMemoryTest.json b/test/KEFCore.Test/InMemoryTest.json new file mode 100644 index 00000000..f3574821 --- /dev/null +++ b/test/KEFCore.Test/InMemoryTest.json @@ -0,0 +1,3 @@ +{ + "UseInMemoryProvider": true +} diff --git a/test/KEFCore.Test/KEFCore.Test.csproj b/test/KEFCore.Test/KEFCore.Test.csproj index be26f56e..fe28413b 100644 --- a/test/KEFCore.Test/KEFCore.Test.csproj +++ b/test/KEFCore.Test/KEFCore.Test.csproj @@ -14,4 +14,16 @@ + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + diff --git a/test/KEFCore.Test/KNetReplicatorTest.json b/test/KEFCore.Test/KNetReplicatorTest.json new file mode 100644 index 00000000..064ce140 --- /dev/null +++ b/test/KEFCore.Test/KNetReplicatorTest.json @@ -0,0 +1,4 @@ +{ + "UseCompactedReplicator": true, + "BootstrapServers": "192.168.1.103:9092" +} diff --git a/test/KEFCore.Test/KafkaStreamsTest.json b/test/KEFCore.Test/KafkaStreamsTest.json new file mode 100644 index 00000000..243bea6a --- /dev/null +++ b/test/KEFCore.Test/KafkaStreamsTest.json @@ -0,0 +1,3 @@ +{ + "BootstrapServers": "192.168.1.103:9092" +} diff --git a/test/KEFCore.Test/Program.cs b/test/KEFCore.Test/Program.cs index 639ef169..438cbfab 100644 --- a/test/KEFCore.Test/Program.cs +++ b/test/KEFCore.Test/Program.cs @@ -25,50 +25,48 @@ using MASES.EntityFrameworkCore.KNet.Infrastructure; using MASES.KNet.Streams; using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Internal; using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; +using System.Text.Json; namespace MASES.EntityFrameworkCore.KNet.Test { partial class Program { - const string theServer = "localhost:9092"; - static string serverToUse = theServer; - static string databaseName = "TestDB"; - static string databaseNameWithModel = "TestDBWithModel"; - static string applicationId = "TestApplication"; + internal static ProgramConfig config = new(); - static void Main(string[] args) + static void ReportString(string message) { - if (!UseInMemoryProvider) + if (Debugger.IsAttached) { - KEFCore.CreateGlobalInstance(); - var appArgs = KEFCore.FilteredArgs; - - if (appArgs.Length > 0) - { - serverToUse = args[0]; - } + ReportString(message); + } + else + { + Console.WriteLine(message); + } + } - if (appArgs.Length > 1) - { - deleteApplication = args[1].ToLowerInvariant() == "true"; - } + static void Main(string[] args) + { + if (args.Length > 0) + { + config = JsonSerializer.Deserialize(File.ReadAllText(args[0])); + } - if (appArgs.Length > 2) - { - applicationId = args[2]; - } + if (!config.UseInMemoryProvider) + { + KEFCore.CreateGlobalInstance(); } - DatabaseName = UseModelBuilder ? databaseNameWithModel : databaseName; + var databaseName = config.UseModelBuilder ? config.DatabaseNameWithModel : config.DatabaseName; var globalWatcher = Stopwatch.StartNew(); StreamsConfigBuilder streamConfig = null; - if (!UseInMemoryProvider) + if (!config.UseInMemoryProvider) { streamConfig = StreamsConfigBuilder.Create(); streamConfig = streamConfig.WithAcceptableRecoveryLag(100); @@ -76,13 +74,13 @@ static void Main(string[] args) var context = new BloggingContext() { - BootstrapServers = serverToUse, - ApplicationId = applicationId, - DbName = DatabaseName, + BootstrapServers = config.BootstrapServers, + ApplicationId = config.ApplicationId, + DbName = databaseName, StreamsConfigBuilder = streamConfig, }; - if (deleteApplication) + if (config.DeleteApplication) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); @@ -90,7 +88,7 @@ static void Main(string[] args) var testWatcher = Stopwatch.StartNew(); Stopwatch watch = Stopwatch.StartNew(); - for (int i = 1; i <= 1000; i++) + for (int i = 0; i < config.NumberOfElements; i++) { context.Add(new Blog { @@ -107,14 +105,14 @@ static void Main(string[] args) }); } watch.Stop(); - Trace.WriteLine($"Elapsed data load {watch.ElapsedMilliseconds} ms"); + ReportString($"Elapsed data load {watch.ElapsedMilliseconds} ms"); watch.Restart(); context.SaveChanges(); watch.Stop(); - Trace.WriteLine($"Elapsed SaveChanges {watch.ElapsedMilliseconds} ms"); + ReportString($"Elapsed SaveChanges {watch.ElapsedMilliseconds} ms"); - if (UseModelBuilder) + if (config.UseModelBuilder) { watch.Restart(); var pageObject = (from op in context.Blogs @@ -122,42 +120,42 @@ join pg in context.Posts on op.BlogId equals pg.BlogId where pg.BlogId == op.BlogId select new { pg, op }).SingleOrDefault(); watch.Stop(); - Trace.WriteLine($"Elapsed UseModelBuilder {watch.ElapsedMilliseconds} ms"); + ReportString($"Elapsed UseModelBuilder {watch.ElapsedMilliseconds} ms"); } watch.Restart(); var post = context.Posts.Single(b => b.BlogId == 2); watch.Stop(); - Trace.WriteLine($"Elapsed context.Posts.Single(b => b.BlogId == 2) {watch.ElapsedMilliseconds} ms. Result is {post}"); + 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(); - Trace.WriteLine($"Elapsed context.Posts.Single(b => b.BlogId == 1) {watch.ElapsedMilliseconds} ms. Result is {post}"); + 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(); - Trace.WriteLine($"Elapsed context.Posts.All((o) => true) {watch.ElapsedMilliseconds} ms. Result is {all}"); + 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(); - Trace.WriteLine($"Elapsed context.Blogs!.Single(b => b.BlogId == 1) {watch.ElapsedMilliseconds} ms. Result is {blog}"); + 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(); - Trace.WriteLine($"Elapsed data remove {watch.ElapsedMilliseconds} ms"); + ReportString($"Elapsed data remove {watch.ElapsedMilliseconds} ms"); watch.Restart(); context.SaveChanges(); watch.Stop(); - Trace.WriteLine($"Elapsed SaveChanges {watch.ElapsedMilliseconds} ms"); + ReportString($"Elapsed SaveChanges {watch.ElapsedMilliseconds} ms"); watch.Restart(); - for (int i = 1000; i < 1100; i++) + for (int i = config.NumberOfElements; i < config.NumberOfElements + config.NumberOfExtraElements; i++) { context.Add(new Blog { @@ -174,17 +172,17 @@ join pg in context.Posts on op.BlogId equals pg.BlogId }); } watch.Stop(); - Trace.WriteLine($"Elapsed data load {watch.ElapsedMilliseconds} ms"); + ReportString($"Elapsed data load {watch.ElapsedMilliseconds} ms"); watch.Restart(); context.SaveChanges(); watch.Stop(); - Trace.WriteLine($"Elapsed SaveChanges {watch.ElapsedMilliseconds} ms"); + ReportString($"Elapsed SaveChanges {watch.ElapsedMilliseconds} ms"); watch.Restart(); post = context.Posts.Single(b => b.BlogId == 1009); watch.Stop(); - Trace.WriteLine($"Elapsed context.Posts.Single(b => b.BlogId == 1009) {watch.ElapsedMilliseconds} ms. Result is {post}"); + ReportString($"Elapsed context.Posts.Single(b => b.BlogId == 1009) {watch.ElapsedMilliseconds} ms. Result is {post}"); var value = context.Blogs.AsQueryable().ToQueryString(); @@ -197,16 +195,16 @@ join pg in context.Posts on op.BlogId equals pg.BlogId public class BloggingContext : KafkaDbContext { - public override bool UseCompactedReplicator { get; set; } = Program.UseCompactedReplicator; + public override bool UseCompactedReplicator { get; set; } = Program.config.UseCompactedReplicator; public DbSet Blogs { get; set; } public DbSet Posts { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - if (Program.UseInMemoryProvider) + if (Program.config.UseInMemoryProvider) { - optionsBuilder.UseInMemoryDatabase(Program.DatabaseName); + optionsBuilder.UseInMemoryDatabase(Program.config.DatabaseName); } else { @@ -220,7 +218,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder) { - if (!Program.UseModelBuilder) return; + if (!Program.config.UseModelBuilder) return; modelBuilder.Entity().HasKey(c => new { c.BlogId, c.Rating }); } diff --git a/test/KEFCore.Test/ProgramConfig.cs b/test/KEFCore.Test/ProgramConfig.cs index c8953176..aa137339 100644 --- a/test/KEFCore.Test/ProgramConfig.cs +++ b/test/KEFCore.Test/ProgramConfig.cs @@ -24,12 +24,17 @@ namespace MASES.EntityFrameworkCore.KNet.Test { - partial class Program + public class ProgramConfig { - public static bool UseInMemoryProvider = false; - public static bool UseModelBuilder = false; - public static bool UseCompactedReplicator = false; - public static string DatabaseName = null; - static bool deleteApplication = true; + public bool UseInMemoryProvider { get; set; } = false; + public bool UseModelBuilder { get; set; } = false; + public bool UseCompactedReplicator { get; set; } = false; + public string DatabaseName { get; set; } = "TestDB"; + public string DatabaseNameWithModel { get; set; } = "TestDBWithModel"; + public string ApplicationId { get; set; } = "TestApplication"; + public bool DeleteApplication { get; set; } = true; + public string BootstrapServers { get; set; } = "localhost:9092"; + public int NumberOfElements { get; set; } = 1000; + public int NumberOfExtraElements { get; set; } = 100; } }