Skip to content

Commit

Permalink
Aligned to KNet 2.1.1 (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
masesdevelopers authored Oct 5, 2023
1 parent af264fe commit f0208d1
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 100 deletions.
4 changes: 2 additions & 2 deletions src/net/KEFCore/KEFCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MASES.KNet" Version="2.1.0">
<PackageReference Include="MASES.KNet" Version="2.1.1">
<IncludeAssets>All</IncludeAssets>
<PrivateAssets>None</PrivateAssets>
</PackageReference>
<PackageReference Include="MASES.KNet.Serialization.Json" Version="2.1.0" />
<PackageReference Include="MASES.KNet.Serialization.Json" Version="2.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.11" PrivateAssets="none" />
</ItemGroup>
</Project>
209 changes: 111 additions & 98 deletions test/KEFCore.Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProgramConfig>(File.ReadAllText(args[0]));
Expand All @@ -64,132 +68,141 @@ 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<Post>()
context.Add(new Blog
{
Url = "http://blogs.msdn.com/adonet" + i.ToString(),
Posts = new List<Post>()
{
new Post()
{
Title = "title",
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<Post>()
context.Add(new Blog
{
Url = "http://blogs.msdn.com/adonet" + i.ToString(),
Posts = new List<Post>()
{
new Post()
{
Title = "title",
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}");
}
}
}

Expand Down

0 comments on commit f0208d1

Please sign in to comment.