Skip to content

Commit

Permalink
major: Release v9.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mynkow committed Aug 22, 2023
2 parents 87d8c0b + 5f8aceb commit 372cd94
Show file tree
Hide file tree
Showing 215 changed files with 3,145 additions and 2,531 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions src/Elders.Cronus.Performance/Elders.Cronus.Performance.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.7" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Elders.Cronus\Elders.Cronus.csproj" />
</ItemGroup>

</Project>
67 changes: 67 additions & 0 deletions src/Elders.Cronus.Performance/LoggingBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using Microsoft.Extensions.Logging;

//BenchmarkRunner.Run<LoggingBench>();

[MemoryDiagnoser]
public class LoggingBench
{
private readonly ILogger _logger;
private string _name = "Batman";
private int _age = 82;

public LoggingBench()
{
_logger = LoggerFactory.Create(builder =>
{
builder.ClearProviders();
builder.AddProvider(new MyLoggerProvider());
}).CreateLogger(typeof(LoggingBench));
}

[Benchmark(Baseline = true)]
public void Default() => Log.Log0(_logger, _name, _age);

[Benchmark]
public void SkipEnabledCheck() => Log.Log1(_logger, _name, _age);

private static class Log
{
static LogDefineOptions logOptions = new LogDefineOptions()
{
SkipEnabledCheck = true
};

private static readonly Action<ILogger, string, int, Exception?> s_log0 = LoggerMessage.Define<string, int>(
LogLevel.Information,
new EventId(1001),
"Name {Name} is {Age} years old");

private static readonly Action<ILogger, string, int, Exception?> s_log1 = LoggerMessage.Define<string, int>(
LogLevel.Information,
new EventId(1001),
"Name {Name} is {Age} years old",
logOptions);

public static void Log0(ILogger logger, string name, int age) => s_log0(logger, name, age, null);
public static void Log1(ILogger logger, string name, int age) => s_log1(logger, name, age, null);
}
}

public class MyLogger : ILogger
{
public IDisposable BeginScope<TState>(TState state) => throw new NotImplementedException();
public bool IsEnabled(LogLevel logLevel) => false;
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
=> LogCore(formatter(state, exception));

[MethodImpl(MethodImplOptions.NoInlining)]
private static void LogCore(string _) { }
}

public class MyLoggerProvider : ILoggerProvider
{
public ILogger CreateLogger(string categoryName) => new MyLogger();
public void Dispose() { }
}
19 changes: 19 additions & 0 deletions src/Elders.Cronus.Performance/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//using BenchmarkDotNet.Attributes;
//using Elders.Cronus.Performance;

//LoggingBenchmark lb = new LoggingBenchmark();
//lb.LogInterpolation();

//BenchmarkDotNet.Running.BenchmarkRunner.Run<TestRunner>();

//[MemoryDiagnoser]
//public class TestRunner
//{
// LoggingBenchmark lb = new LoggingBenchmark();

// [Benchmark]
// public void LogInterpolation()
// {

// }
//}
24 changes: 24 additions & 0 deletions src/Elders.Cronus.Performance/UrnInit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using Elders.Cronus;

BenchmarkRunner.Run<UrnInitBench>();

[MemoryDiagnoser]
public class UrnInitBench
{
string urnString = "urn:elders:user:8eef39fd-b4fa-4323-b062-85e756960862";

[Benchmark]
public void Constructor()
{
var urn = new Urn(urnString);
}

[Benchmark]
public void Parse()
{
var urn = new Urn(urnString);
}
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Elders.Cronus.Cluster.Job;
using Elders.Cronus.Cluster.Job.InMemory;
using Elders.Cronus.EventStore.Index;
using Machine.Specifications;
using Microsoft.Extensions.Configuration;
using System;
Expand Down
6 changes: 3 additions & 3 deletions src/Elders.Cronus.Tests/Elders.Cronus.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<RootNamespace>Elders.Cronus</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Cronus.DomainModeling" Version="8.1.0" />
<PackageReference Include="Machine.Specifications" Version="1.0.0" />
<PackageReference Include="Cronus.DomainModeling" Version="9.0.0" />
<PackageReference Include="Machine.Specifications" Version="1.1.1" />
<PackageReference Include="Machine.Specifications.Runner.VisualStudio" Version="2.10.2" />
<PackageReference Include="Machine.Specifications.Should" Version="1.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Elders.Cronus\Elders.Cronus.csproj" />
Expand Down
6 changes: 3 additions & 3 deletions src/Elders.Cronus.Tests/EventStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class When_build_aggregate_root_from_events
id = new TestAggregateId();
var commits = new List<AggregateCommit>();
commits.Add(new AggregateCommit(id as IBlobId, 1, new List<IEvent>() { new TestCreateEvent(id) }));
commits.Add(new AggregateCommit(id as IBlobId, 2, new List<IEvent>() { new TestUpdateEvent(id, "When_build_aggregate_root_from_events") }));
commits.Add(new AggregateCommit(id, 1, new List<IEvent>() { new TestCreateEvent(id) }, new List<IPublicEvent>(), DateTimeOffset.Now.ToFileTime()));
commits.Add(new AggregateCommit(id, 2, new List<IEvent>() { new TestUpdateEvent(id, "When_build_aggregate_root_from_events") }, new List<IPublicEvent>(), DateTimeOffset.Now.ToFileTime()));
eventStream = new EventStream(commits);
};
Expand All @@ -37,7 +37,7 @@ public class When_build_aggregate_root_from_history_without_the_initial_event
{
id = new TestAggregateId();
var commits = new List<AggregateCommit>();
commits.Add(new AggregateCommit(id as IBlobId, 2, new List<IEvent>() { new TestUpdateEvent(id, "When_build_aggregate_root_from_history_without_the_initial_event") }));
commits.Add(new AggregateCommit(id, 2, new List<IEvent>() { new TestUpdateEvent(id, "When_build_aggregate_root_from_history_without_the_initial_event") }, new List<IPublicEvent>(), DateTimeOffset.Now.ToFileTime()));
eventStream = new EventStream(commits);
};

Expand Down
21 changes: 18 additions & 3 deletions src/Elders.Cronus.Tests/InMemory/InMemoryEventStorePersister.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Elders.Cronus.EventStore.Index;
using System;
using System.Threading.Tasks;

namespace Elders.Cronus.EventStore.InMemory
{

public class InMemoryEventStore : IEventStore
{
private InMemoryEventStoreStorage eventStoreStorage;
Expand All @@ -21,7 +22,7 @@ public InMemoryEventStore(InMemoryEventStoreStorage eventStoreStorage)
/// </summary>
/// <param name="aggregateId">The aggregate identifier.</param>
/// <returns></returns>
public Task<EventStream> LoadAsync(IAggregateRootId aggregateId)
public Task<EventStream> LoadAsync(IBlobId aggregateId)
{
return Task.FromResult(new EventStream(eventStoreStorage.Seek(aggregateId)));
}
Expand All @@ -37,9 +38,23 @@ public Task AppendAsync(AggregateCommit aggregateCommit)
return Task.CompletedTask;
}

public Task AppendAsync(AggregateCommitRaw aggregateCommitRaw)
public Task AppendAsync(AggregateEventRaw aggregateCommitRaw)
{
return Task.FromException(new System.NotImplementedException());
}

public Task<bool> DeleteAsync(AggregateEventRaw eventRaw)
{
throw new System.NotImplementedException();
}
public Task<LoadAggregateRawEventsWithPagingResult> LoadWithPagingDescendingAsync(IBlobId aggregateId, PagingOptions pagingOptions)
{
throw new System.NotImplementedException();
}

public Task<AggregateEventRaw> LoadAggregateEventRaw(IndexRecord indexRecord)
{
throw new NotImplementedException();
}
}
}
25 changes: 4 additions & 21 deletions src/Elders.Cronus.Tests/InMemory/InMemoryEventStorePlayer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Elders.Cronus.EventStore.InMemory
Expand All @@ -14,31 +13,15 @@ public InMemoryEventStorePlayer(InMemoryEventStoreStorage eventStoreStorage)
this.eventStoreStorage = eventStoreStorage;
}

public async IAsyncEnumerable<AggregateCommit> LoadAggregateCommitsAsync(int batchSize = 5000)
{
foreach (var @event in eventStoreStorage.GetOrderedEvents())
yield return @event;
}

public Task<LoadAggregateCommitsResult> LoadAggregateCommitsAsync(ReplayOptions replayOptions)
{
throw new NotImplementedException();
}

public IAsyncEnumerable<AggregateCommitRaw> LoadAggregateCommitsRawAsync(int batchSize = 5000)
public Task EnumerateEventStore(PlayerOperator @operator, PlayerOptions replayOptions)
{
throw new NotImplementedException();
}

Task<LoadAggregateCommitsResult> IEventStorePlayer.LoadAggregateCommitsAsync(string paginationToken, int batchSize)
public async IAsyncEnumerable<AggregateCommit> LoadAggregateCommitsAsync(int batchSize = 5000)
{
LoadAggregateCommitsResult aggregateCommit = new LoadAggregateCommitsResult
{
Commits = eventStoreStorage.GetOrderedEvents().ToList(),
PaginationToken = paginationToken
};

return Task.FromResult(aggregateCommit);
foreach (var @event in eventStoreStorage.GetOrderedEvents())
yield return @event;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ internal protected void Flush(AggregateCommit aggregateCommit)
eventsForReplay.Enqueue(aggregateCommit);
}

internal protected List<AggregateCommit> Seek(IAggregateRootId aggregateId)
internal protected List<AggregateCommit> Seek(IBlobId aggregateId)
{
var idHash = Convert.ToBase64String(aggregateId.RawId);
ConcurrentQueue<AggregateCommit> commits;
Expand Down
97 changes: 0 additions & 97 deletions src/Elders.Cronus.Tests/InMemory/ScopedQueues.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public class When_loading_aggregate_root_from_event_store
versionService = new InMemoryAggregateRootAtomicAction();
eventStoreStorage = new InMemoryEventStoreStorage();
eventStore = new InMemoryEventStore(eventStoreStorage);
eventStoreFactory = new EventStoreFactory(eventStore, new NoAggregateCommitTransformer(), null);
eventStoreFactory = new EventStoreFactory(eventStore, null);
eventStorePlayer = new InMemoryEventStorePlayer(eventStoreStorage);
integrityPpolicy = new EventStreamIntegrityPolicy();
aggregateRepository = new AggregateRepository(eventStoreFactory, versionService, integrityPpolicy);
aggregateRepository = new AggregateRepository(eventStoreFactory, versionService, integrityPpolicy, new EmptyAggregateTransformer());
id = new TestAggregateId();
aggregateRoot = new TestAggregateRoot(id);
await aggregateRepository.SaveAsync<TestAggregateRoot>(aggregateRoot);
Expand Down

0 comments on commit 372cd94

Please sign in to comment.