From da6198dd9276cd54e5326571f0b2440c14f36dc7 Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Sun, 3 Dec 2017 22:49:40 +0100 Subject: [PATCH] Compiler errors fixed. --- .../MongoAssetRepository_EventHandling.cs | 2 +- ...MongoAssetStatsRepository_EventHandling.cs | 2 +- .../MongoContentRepository_EventHandling.cs | 2 +- .../Apps/AppHistoryEventsCreator.cs | 2 +- .../State/AppProvider.cs | 14 +++++------ .../State/AppStateEventConsumer.cs | 6 ++--- .../State/Grains/AppStateGrain.cs | 14 +++-------- .../State/Grains/AppStateGrainState.cs | 2 +- .../State/Grains/AppUserGrain.cs | 5 ++-- .../Apps/AppDomainObject.cs | 4 +-- .../Assets/AssetDomainObject.cs | 4 +-- .../Contents/ContentDomainObject.cs | 4 +-- .../Contents/ContentVersionLoader.cs | 5 ++-- .../Rules/RuleDomainObject.cs | 4 +-- .../Schemas/SchemaDomainObject.cs | 4 +-- .../EventSourcing/Events/GetEventStore.cs | 3 ++- .../EventSourcing/MongoEventStore.cs | 2 +- .../EventSourcing/IEventStore.cs | 2 +- .../States/StateFactory.cs | 8 +++--- tests/Benchmarks/Services.cs | 9 +++++-- tests/Benchmarks/Tests/HandleEvents.cs | 6 ++--- .../Tests/HandleEventsWithManyWriters.cs | 6 ++--- tests/Benchmarks/Tests/ReadSchemaState.cs | 2 +- tests/Benchmarks/Tests/TestData/MyAppState.cs | 25 +++++++++++++++++-- .../Apps/AppDomainObjectTests.cs | 2 +- .../Assets/AssetDomainObjectTests.cs | 2 +- .../Contents/ContentDomainObjectTests.cs | 2 +- .../Contents/ContentVersionLoaderTests.cs | 15 +++++------ .../Rules/RuleDomainObjectTests.cs | 2 +- .../Schemas/SchemaDomainObjectTests.cs | 2 +- .../TestHelpers/HandlerTestBase.cs | 1 - .../States/StateSnapshotTests.cs | 2 +- 32 files changed, 93 insertions(+), 72 deletions(-) diff --git a/src/Squidex.Domain.Apps.Read.MongoDb/Assets/MongoAssetRepository_EventHandling.cs b/src/Squidex.Domain.Apps.Read.MongoDb/Assets/MongoAssetRepository_EventHandling.cs index e8b95832e..b05fe5d41 100644 --- a/src/Squidex.Domain.Apps.Read.MongoDb/Assets/MongoAssetRepository_EventHandling.cs +++ b/src/Squidex.Domain.Apps.Read.MongoDb/Assets/MongoAssetRepository_EventHandling.cs @@ -9,8 +9,8 @@ using System.Threading.Tasks; using MongoDB.Driver; using Squidex.Domain.Apps.Events.Assets; -using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.Dispatching; +using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.Reflection; namespace Squidex.Domain.Apps.Read.MongoDb.Assets diff --git a/src/Squidex.Domain.Apps.Read.MongoDb/Assets/MongoAssetStatsRepository_EventHandling.cs b/src/Squidex.Domain.Apps.Read.MongoDb/Assets/MongoAssetStatsRepository_EventHandling.cs index 73b3440b7..b46374dd7 100644 --- a/src/Squidex.Domain.Apps.Read.MongoDb/Assets/MongoAssetStatsRepository_EventHandling.cs +++ b/src/Squidex.Domain.Apps.Read.MongoDb/Assets/MongoAssetStatsRepository_EventHandling.cs @@ -10,8 +10,8 @@ using System; using System.Threading.Tasks; using MongoDB.Driver; using Squidex.Domain.Apps.Events.Assets; -using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.Dispatching; +using Squidex.Infrastructure.EventSourcing; namespace Squidex.Domain.Apps.Read.MongoDb.Assets { diff --git a/src/Squidex.Domain.Apps.Read.MongoDb/Contents/MongoContentRepository_EventHandling.cs b/src/Squidex.Domain.Apps.Read.MongoDb/Contents/MongoContentRepository_EventHandling.cs index 21b6be2c6..85acec317 100644 --- a/src/Squidex.Domain.Apps.Read.MongoDb/Contents/MongoContentRepository_EventHandling.cs +++ b/src/Squidex.Domain.Apps.Read.MongoDb/Contents/MongoContentRepository_EventHandling.cs @@ -13,8 +13,8 @@ using Squidex.Domain.Apps.Core.ConvertContent; using Squidex.Domain.Apps.Events.Apps; using Squidex.Domain.Apps.Events.Assets; using Squidex.Domain.Apps.Events.Contents; -using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.Dispatching; +using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.Reflection; namespace Squidex.Domain.Apps.Read.MongoDb.Contents diff --git a/src/Squidex.Domain.Apps.Read/Apps/AppHistoryEventsCreator.cs b/src/Squidex.Domain.Apps.Read/Apps/AppHistoryEventsCreator.cs index b374525cf..2e677ba59 100644 --- a/src/Squidex.Domain.Apps.Read/Apps/AppHistoryEventsCreator.cs +++ b/src/Squidex.Domain.Apps.Read/Apps/AppHistoryEventsCreator.cs @@ -10,8 +10,8 @@ using System.Threading.Tasks; using Squidex.Domain.Apps.Events.Apps; using Squidex.Domain.Apps.Read.History; using Squidex.Infrastructure; -using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.Dispatching; +using Squidex.Infrastructure.EventSourcing; namespace Squidex.Domain.Apps.Read.Apps { diff --git a/src/Squidex.Domain.Apps.Read/State/AppProvider.cs b/src/Squidex.Domain.Apps.Read/State/AppProvider.cs index 75e6754ff..9a4a155d1 100644 --- a/src/Squidex.Domain.Apps.Read/State/AppProvider.cs +++ b/src/Squidex.Domain.Apps.Read/State/AppProvider.cs @@ -32,49 +32,49 @@ namespace Squidex.Domain.Apps.Read.State public async Task GetAppAsync(string appName) { - var app = await factory.GetAsync(appName); + var app = await factory.GetSynchronizedAsync(appName); return await app.GetAppAsync(); } public async Task<(IAppEntity, ISchemaEntity)> GetAppWithSchemaAsync(string appName, Guid id) { - var app = await factory.GetAsync(appName); + var app = await factory.GetSynchronizedAsync(appName); return await app.GetAppWithSchemaAsync(id); } public async Task> GetRulesAsync(string appName) { - var app = await factory.GetAsync(appName); + var app = await factory.GetSynchronizedAsync(appName); return await app.GetRulesAsync(); } public async Task GetSchemaAsync(string appName, Guid id, bool provideDeleted = false) { - var app = await factory.GetAsync(appName); + var app = await factory.GetSynchronizedAsync(appName); return await app.GetSchemaAsync(id, provideDeleted); } public async Task GetSchemaAsync(string appName, string name, bool provideDeleted = false) { - var app = await factory.GetAsync(appName); + var app = await factory.GetSynchronizedAsync(appName); return await app.GetSchemaAsync(name, provideDeleted); } public async Task> GetSchemasAsync(string appName) { - var app = await factory.GetAsync(appName); + var app = await factory.GetSynchronizedAsync(appName); return await app.GetSchemasAsync(); } public async Task> GetUserApps(string userId) { - var appUser = await factory.GetAsync(userId); + var appUser = await factory.GetSynchronizedAsync(userId); var appNames = await appUser.GetAppNamesAsync(); var tasks = appNames.Select(x => GetAppAsync(x)); diff --git a/src/Squidex.Domain.Apps.Read/State/AppStateEventConsumer.cs b/src/Squidex.Domain.Apps.Read/State/AppStateEventConsumer.cs index d36b0ca08..fd142607b 100644 --- a/src/Squidex.Domain.Apps.Read/State/AppStateEventConsumer.cs +++ b/src/Squidex.Domain.Apps.Read/State/AppStateEventConsumer.cs @@ -47,21 +47,21 @@ namespace Squidex.Domain.Apps.Read.State { if (@event.Payload is AppEvent appEvent) { - var appGrain = await factory.GetAsync(appEvent.AppId.Name); + var appGrain = await factory.GetSynchronizedAsync(appEvent.AppId.Name); await appGrain.HandleAsync(@event); } if (@event.Payload is AppContributorAssigned contributorAssigned) { - var userGrain = await factory.GetAsync(contributorAssigned.ContributorId); + var userGrain = await factory.GetSynchronizedAsync(contributorAssigned.ContributorId); await userGrain.AddAppAsync(contributorAssigned.AppId.Name); } if (@event.Payload is AppContributorRemoved contributorRemoved) { - var userGrain = await factory.GetAsync(contributorRemoved.ContributorId); + var userGrain = await factory.GetSynchronizedAsync(contributorRemoved.ContributorId); await userGrain.RemoveAppAsync(contributorRemoved.AppId.Name); } diff --git a/src/Squidex.Domain.Apps.Read/State/Grains/AppStateGrain.cs b/src/Squidex.Domain.Apps.Read/State/Grains/AppStateGrain.cs index d7cfcfdad..d707d1d52 100644 --- a/src/Squidex.Domain.Apps.Read/State/Grains/AppStateGrain.cs +++ b/src/Squidex.Domain.Apps.Read/State/Grains/AppStateGrain.cs @@ -25,7 +25,6 @@ namespace Squidex.Domain.Apps.Read.State.Grains { private readonly FieldRegistry fieldRegistry; private IPersistence persistence; - private Task readTask; private Exception exception; private AppStateGrainState state; @@ -36,15 +35,10 @@ namespace Squidex.Domain.Apps.Read.State.Grains this.fieldRegistry = fieldRegistry; } - public Task ActivateAsync(string key, IStore store) + public async Task ActivateAsync(string key, IStore store) { persistence = store.WithSnapshots(key, s => state = s); - return readTask ?? (readTask = ReadInitialAsync()); - } - - private async Task ReadInitialAsync() - { try { await persistence.ReadAsync(); @@ -121,15 +115,15 @@ namespace Squidex.Domain.Apps.Read.State.Grains { state = state.Apply(message); - await persistence.WriteSnapShotAsync(state); + await persistence.WriteSnapshotAsync(state); } catch (InconsistentStateException) { - await persistence.ReadAsync(true); + await persistence.ReadAsync(); state = state.Apply(message); - await persistence.WriteSnapShotAsync(state); + await persistence.WriteSnapshotAsync(state); } } } diff --git a/src/Squidex.Domain.Apps.Read/State/Grains/AppStateGrainState.cs b/src/Squidex.Domain.Apps.Read/State/Grains/AppStateGrainState.cs index 397e89e6f..70803d76a 100644 --- a/src/Squidex.Domain.Apps.Read/State/Grains/AppStateGrainState.cs +++ b/src/Squidex.Domain.Apps.Read/State/Grains/AppStateGrainState.cs @@ -16,8 +16,8 @@ using Squidex.Domain.Apps.Read.Apps; using Squidex.Domain.Apps.Read.Rules; using Squidex.Domain.Apps.Read.Schemas; using Squidex.Infrastructure; -using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.Dispatching; +using Squidex.Infrastructure.EventSourcing; namespace Squidex.Domain.Apps.Read.State.Grains { diff --git a/src/Squidex.Domain.Apps.Read/State/Grains/AppUserGrain.cs b/src/Squidex.Domain.Apps.Read/State/Grains/AppUserGrain.cs index 2addfe70b..86dda46d6 100644 --- a/src/Squidex.Domain.Apps.Read/State/Grains/AppUserGrain.cs +++ b/src/Squidex.Domain.Apps.Read/State/Grains/AppUserGrain.cs @@ -17,7 +17,6 @@ namespace Squidex.Domain.Apps.Read.State.Grains public sealed class AppUserGrain : IStatefulObject { private IPersistence persistence; - private Task readTask; private AppUserGrainState state; public Task ActivateAsync(string key, IStore store) @@ -38,14 +37,14 @@ namespace Squidex.Domain.Apps.Read.State.Grains { state = state.AddApp(appName); - return persistence.WriteSnapShotAsync(state); + return persistence.WriteSnapshotAsync(state); } public Task RemoveAppAsync(string appName) { state = state.RemoveApp(appName); - return persistence.WriteSnapShotAsync(state); + return persistence.WriteSnapshotAsync(state); } public Task> GetAppNamesAsync() diff --git a/src/Squidex.Domain.Apps.Write/Apps/AppDomainObject.cs b/src/Squidex.Domain.Apps.Write/Apps/AppDomainObject.cs index c500ba716..6c2a7b7bb 100644 --- a/src/Squidex.Domain.Apps.Write/Apps/AppDomainObject.cs +++ b/src/Squidex.Domain.Apps.Write/Apps/AppDomainObject.cs @@ -13,9 +13,9 @@ using Squidex.Domain.Apps.Events.Apps; using Squidex.Domain.Apps.Events.Apps.Utils; using Squidex.Domain.Apps.Write.Apps.Commands; using Squidex.Infrastructure; -using Squidex.Infrastructure.CQRS; -using Squidex.Infrastructure.EventSourcing; +using Squidex.Infrastructure.Commands; using Squidex.Infrastructure.Dispatching; +using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.Reflection; namespace Squidex.Domain.Apps.Write.Apps diff --git a/src/Squidex.Domain.Apps.Write/Assets/AssetDomainObject.cs b/src/Squidex.Domain.Apps.Write/Assets/AssetDomainObject.cs index ea75b8b73..6fa06c5a7 100644 --- a/src/Squidex.Domain.Apps.Write/Assets/AssetDomainObject.cs +++ b/src/Squidex.Domain.Apps.Write/Assets/AssetDomainObject.cs @@ -10,9 +10,9 @@ using System; using Squidex.Domain.Apps.Events.Assets; using Squidex.Domain.Apps.Write.Assets.Commands; using Squidex.Infrastructure; -using Squidex.Infrastructure.CQRS; -using Squidex.Infrastructure.EventSourcing; +using Squidex.Infrastructure.Commands; using Squidex.Infrastructure.Dispatching; +using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.Reflection; namespace Squidex.Domain.Apps.Write.Assets diff --git a/src/Squidex.Domain.Apps.Write/Contents/ContentDomainObject.cs b/src/Squidex.Domain.Apps.Write/Contents/ContentDomainObject.cs index bd3925f50..d4c66bec2 100644 --- a/src/Squidex.Domain.Apps.Write/Contents/ContentDomainObject.cs +++ b/src/Squidex.Domain.Apps.Write/Contents/ContentDomainObject.cs @@ -11,9 +11,9 @@ using Squidex.Domain.Apps.Core.Contents; using Squidex.Domain.Apps.Events.Contents; using Squidex.Domain.Apps.Write.Contents.Commands; using Squidex.Infrastructure; -using Squidex.Infrastructure.CQRS; -using Squidex.Infrastructure.EventSourcing; +using Squidex.Infrastructure.Commands; using Squidex.Infrastructure.Dispatching; +using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.Reflection; namespace Squidex.Domain.Apps.Write.Contents diff --git a/src/Squidex.Domain.Apps.Write/Contents/ContentVersionLoader.cs b/src/Squidex.Domain.Apps.Write/Contents/ContentVersionLoader.cs index acdd5cd84..7e6203d5d 100644 --- a/src/Squidex.Domain.Apps.Write/Contents/ContentVersionLoader.cs +++ b/src/Squidex.Domain.Apps.Write/Contents/ContentVersionLoader.cs @@ -13,6 +13,7 @@ using Squidex.Domain.Apps.Core.Contents; using Squidex.Domain.Apps.Events.Contents; using Squidex.Infrastructure; using Squidex.Infrastructure.EventSourcing; +using Squidex.Infrastructure.States; namespace Squidex.Domain.Apps.Write.Contents { @@ -20,9 +21,9 @@ namespace Squidex.Domain.Apps.Write.Contents { private readonly IStreamNameResolver nameResolver; private readonly IEventStore eventStore; - private readonly EventDataFormatter formatter; + private readonly IEventDataFormatter formatter; - public ContentVersionLoader(IEventStore eventStore, IStreamNameResolver nameResolver, EventDataFormatter formatter) + public ContentVersionLoader(IEventStore eventStore, IStreamNameResolver nameResolver, IEventDataFormatter formatter) { Guard.NotNull(formatter, nameof(formatter)); Guard.NotNull(eventStore, nameof(eventStore)); diff --git a/src/Squidex.Domain.Apps.Write/Rules/RuleDomainObject.cs b/src/Squidex.Domain.Apps.Write/Rules/RuleDomainObject.cs index 030c65b9e..82a679cc8 100644 --- a/src/Squidex.Domain.Apps.Write/Rules/RuleDomainObject.cs +++ b/src/Squidex.Domain.Apps.Write/Rules/RuleDomainObject.cs @@ -12,9 +12,9 @@ using Squidex.Domain.Apps.Events.Rules; using Squidex.Domain.Apps.Events.Rules.Utils; using Squidex.Domain.Apps.Write.Rules.Commands; using Squidex.Infrastructure; -using Squidex.Infrastructure.CQRS; -using Squidex.Infrastructure.EventSourcing; +using Squidex.Infrastructure.Commands; using Squidex.Infrastructure.Dispatching; +using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.Reflection; namespace Squidex.Domain.Apps.Write.Rules diff --git a/src/Squidex.Domain.Apps.Write/Schemas/SchemaDomainObject.cs b/src/Squidex.Domain.Apps.Write/Schemas/SchemaDomainObject.cs index e8cb5de10..3c264b974 100644 --- a/src/Squidex.Domain.Apps.Write/Schemas/SchemaDomainObject.cs +++ b/src/Squidex.Domain.Apps.Write/Schemas/SchemaDomainObject.cs @@ -13,9 +13,9 @@ using Squidex.Domain.Apps.Events.Schemas; using Squidex.Domain.Apps.Events.Schemas.Utils; using Squidex.Domain.Apps.Write.Schemas.Commands; using Squidex.Infrastructure; -using Squidex.Infrastructure.CQRS; -using Squidex.Infrastructure.EventSourcing; +using Squidex.Infrastructure.Commands; using Squidex.Infrastructure.Dispatching; +using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.Reflection; namespace Squidex.Domain.Apps.Write.Schemas diff --git a/src/Squidex.Infrastructure.GetEventStore/EventSourcing/Events/GetEventStore.cs b/src/Squidex.Infrastructure.GetEventStore/EventSourcing/Events/GetEventStore.cs index c69497a62..bc7cda891 100644 --- a/src/Squidex.Infrastructure.GetEventStore/EventSourcing/Events/GetEventStore.cs +++ b/src/Squidex.Infrastructure.GetEventStore/EventSourcing/Events/GetEventStore.cs @@ -12,6 +12,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using EventStore.ClientAPI; +using EventStore.ClientAPI.Exceptions; namespace Squidex.Infrastructure.EventSourcing { @@ -59,7 +60,7 @@ namespace Squidex.Infrastructure.EventSourcing throw new NotSupportedException(); } - public async Task> GetEventsAsync(string streamName, long streamPosition = -1) + public async Task> GetEventsAsync(string streamName, long streamPosition = 0) { var result = new List(); diff --git a/src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore.cs b/src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore.cs index 6704db329..10c8a13e1 100644 --- a/src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore.cs +++ b/src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore.cs @@ -61,7 +61,7 @@ namespace Squidex.Infrastructure.EventSourcing return new PollingSubscription(this, notifier, subscriber, streamFilter, position); } - public async Task> GetEventsAsync(string streamName, long streamPosition = -1) + public async Task> GetEventsAsync(string streamName, long streamPosition = 0) { var commits = await Collection.Find(x => x.EventStreamOffset >= streamPosition).Sort(Sort.Ascending(TimestampField)).ToListAsync(); diff --git a/src/Squidex.Infrastructure/EventSourcing/IEventStore.cs b/src/Squidex.Infrastructure/EventSourcing/IEventStore.cs index e9182f093..c17ccd607 100644 --- a/src/Squidex.Infrastructure/EventSourcing/IEventStore.cs +++ b/src/Squidex.Infrastructure/EventSourcing/IEventStore.cs @@ -15,7 +15,7 @@ namespace Squidex.Infrastructure.EventSourcing { public interface IEventStore { - Task> GetEventsAsync(string streamName, long streamPosition = -1); + Task> GetEventsAsync(string streamName, long streamPosition = 0); Task GetEventsAsync(Func callback, CancellationToken cancellationToken, string streamFilter = null, string position = null); diff --git a/src/Squidex.Infrastructure/States/StateFactory.cs b/src/Squidex.Infrastructure/States/StateFactory.cs index 883f24c4b..a0513c441 100644 --- a/src/Squidex.Infrastructure/States/StateFactory.cs +++ b/src/Squidex.Infrastructure/States/StateFactory.cs @@ -26,7 +26,7 @@ namespace Squidex.Infrastructure.States private readonly IEventStore eventStore; private readonly IEventDataFormatter eventDataFormatter; private readonly object lockObject = new object(); - private IDisposable pubSubscription; + private IDisposable pubSubSubscription; public sealed class ObjectHolder where T : IStatefulObject { @@ -76,7 +76,7 @@ namespace Squidex.Infrastructure.States public void Connect() { - pubSubscription = pubSub.Subscribe(m => + pubSubSubscription = pubSub.Subscribe(m => { lock (lockObject) { @@ -128,9 +128,9 @@ namespace Squidex.Infrastructure.States protected override void DisposeObject(bool disposing) { - if (disposing) + if (disposing && pubSubSubscription != null) { - pubSubscription.Dispose(); + pubSubSubscription.Dispose(); } } } diff --git a/tests/Benchmarks/Services.cs b/tests/Benchmarks/Services.cs index 4530b2f24..1c7a770d0 100644 --- a/tests/Benchmarks/Services.cs +++ b/tests/Benchmarks/Services.cs @@ -37,7 +37,6 @@ namespace Benchmarks services.AddSingleton(CreateTypeNameRegistry()); - services.AddSingleton(); services.AddSingleton(); services.AddTransient(); @@ -60,12 +59,18 @@ namespace Benchmarks services.AddSingleton(); - services.AddSingleton(); + + services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(c => JsonSerializer.Create(c.GetRequiredService())); diff --git a/tests/Benchmarks/Tests/HandleEvents.cs b/tests/Benchmarks/Tests/HandleEvents.cs index 9ebddc8ac..d49c37b7b 100644 --- a/tests/Benchmarks/Tests/HandleEvents.cs +++ b/tests/Benchmarks/Tests/HandleEvents.cs @@ -20,8 +20,8 @@ namespace Benchmarks.Tests private const int NumEvents = 5000; private IServiceProvider services; private IEventStore eventStore; + private IEventDataFormatter eventDataFormatter; private EventConsumerGrain eventConsumerGrain; - private EventDataFormatter eventDataFormatter; private MyEventConsumer eventConsumer; public override void RunInitialize() @@ -32,10 +32,10 @@ namespace Benchmarks.Tests eventStore = services.GetRequiredService(); - eventDataFormatter = services.GetRequiredService(); + eventDataFormatter = services.GetRequiredService(); eventConsumerGrain = services.GetRequiredService(); - eventConsumerGrain.ActivateAsync(services.GetRequiredService>()).Wait(); + eventConsumerGrain.ActivateAsync("Test", services.GetRequiredService()).Wait(); eventConsumerGrain.Activate(eventConsumer); } diff --git a/tests/Benchmarks/Tests/HandleEventsWithManyWriters.cs b/tests/Benchmarks/Tests/HandleEventsWithManyWriters.cs index 82de9fe89..c98899c91 100644 --- a/tests/Benchmarks/Tests/HandleEventsWithManyWriters.cs +++ b/tests/Benchmarks/Tests/HandleEventsWithManyWriters.cs @@ -22,8 +22,8 @@ namespace Benchmarks.Tests private const int NumStreams = 10; private IServiceProvider services; private IEventStore eventStore; + private IEventDataFormatter eventDataFormatter; private EventConsumerGrain eventConsumerGrain; - private EventDataFormatter eventDataFormatter; private MyEventConsumer eventConsumer; public override void RunInitialize() @@ -33,11 +33,11 @@ namespace Benchmarks.Tests eventConsumer = new MyEventConsumer(NumStreams * NumCommits); eventStore = services.GetRequiredService(); + eventDataFormatter = services.GetRequiredService(); - eventDataFormatter = services.GetRequiredService(); eventConsumerGrain = services.GetRequiredService(); - eventConsumerGrain.ActivateAsync(services.GetRequiredService>()).Wait(); + eventConsumerGrain.ActivateAsync("Test", services.GetRequiredService()).Wait(); eventConsumerGrain.Activate(eventConsumer); } diff --git a/tests/Benchmarks/Tests/ReadSchemaState.cs b/tests/Benchmarks/Tests/ReadSchemaState.cs index ed3ff13f2..f02f50ae4 100644 --- a/tests/Benchmarks/Tests/ReadSchemaState.cs +++ b/tests/Benchmarks/Tests/ReadSchemaState.cs @@ -31,7 +31,7 @@ namespace Benchmarks.Tests { services = Services.Create(); - grain = services.GetRequiredService().GetAsync("DEFAULT").Result; + grain = services.GetRequiredService().GetSynchronizedAsync("DEFAULT").Result; var state = new AppStateGrainState { diff --git a/tests/Benchmarks/Tests/TestData/MyAppState.cs b/tests/Benchmarks/Tests/TestData/MyAppState.cs index 5f4320cce..1340b9f7d 100644 --- a/tests/Benchmarks/Tests/TestData/MyAppState.cs +++ b/tests/Benchmarks/Tests/TestData/MyAppState.cs @@ -6,16 +6,37 @@ // All rights reserved. // ========================================================================== +using System.Threading.Tasks; using Squidex.Domain.Apps.Read.State.Grains; using Squidex.Infrastructure.States; namespace Benchmarks.Tests.TestData { - public sealed class MyAppState : StatefulObject + public sealed class MyAppState : IStatefulObject { + private IPersistence persistence; + private AppStateGrainState state; + + public Task ActivateAsync(string key, IStore store) + { + persistence = store.WithSnapshots(key, s => state = s); + + return persistence.ReadAsync(); + } + public void SetState(AppStateGrainState state) { - State = state; + this.state = state; + } + + public Task WriteStateAsync() + { + return persistence.WriteSnapshotAsync(state); + } + + public Task ReadStateAsync() + { + return persistence.ReadAsync(); } } } diff --git a/tests/Squidex.Domain.Apps.Write.Tests/Apps/AppDomainObjectTests.cs b/tests/Squidex.Domain.Apps.Write.Tests/Apps/AppDomainObjectTests.cs index 79cdb70b7..c41ae0f9a 100644 --- a/tests/Squidex.Domain.Apps.Write.Tests/Apps/AppDomainObjectTests.cs +++ b/tests/Squidex.Domain.Apps.Write.Tests/Apps/AppDomainObjectTests.cs @@ -14,7 +14,7 @@ using Squidex.Domain.Apps.Events.Apps; using Squidex.Domain.Apps.Write.Apps.Commands; using Squidex.Domain.Apps.Write.TestHelpers; using Squidex.Infrastructure; -using Squidex.Infrastructure.CQRS; +using Squidex.Infrastructure.Commands; using Xunit; namespace Squidex.Domain.Apps.Write.Apps diff --git a/tests/Squidex.Domain.Apps.Write.Tests/Assets/AssetDomainObjectTests.cs b/tests/Squidex.Domain.Apps.Write.Tests/Assets/AssetDomainObjectTests.cs index cc2858533..cbca77d3b 100644 --- a/tests/Squidex.Domain.Apps.Write.Tests/Assets/AssetDomainObjectTests.cs +++ b/tests/Squidex.Domain.Apps.Write.Tests/Assets/AssetDomainObjectTests.cs @@ -13,7 +13,7 @@ using Squidex.Domain.Apps.Write.Assets.Commands; using Squidex.Domain.Apps.Write.TestHelpers; using Squidex.Infrastructure; using Squidex.Infrastructure.Assets; -using Squidex.Infrastructure.CQRS; +using Squidex.Infrastructure.Commands; using Xunit; namespace Squidex.Domain.Apps.Write.Assets diff --git a/tests/Squidex.Domain.Apps.Write.Tests/Contents/ContentDomainObjectTests.cs b/tests/Squidex.Domain.Apps.Write.Tests/Contents/ContentDomainObjectTests.cs index 5a8515c19..8f612faf7 100644 --- a/tests/Squidex.Domain.Apps.Write.Tests/Contents/ContentDomainObjectTests.cs +++ b/tests/Squidex.Domain.Apps.Write.Tests/Contents/ContentDomainObjectTests.cs @@ -13,7 +13,7 @@ using Squidex.Domain.Apps.Events.Contents; using Squidex.Domain.Apps.Write.Contents.Commands; using Squidex.Domain.Apps.Write.TestHelpers; using Squidex.Infrastructure; -using Squidex.Infrastructure.CQRS; +using Squidex.Infrastructure.Commands; using Xunit; namespace Squidex.Domain.Apps.Write.Contents diff --git a/tests/Squidex.Domain.Apps.Write.Tests/Contents/ContentVersionLoaderTests.cs b/tests/Squidex.Domain.Apps.Write.Tests/Contents/ContentVersionLoaderTests.cs index 76892d0fc..30bc8593d 100644 --- a/tests/Squidex.Domain.Apps.Write.Tests/Contents/ContentVersionLoaderTests.cs +++ b/tests/Squidex.Domain.Apps.Write.Tests/Contents/ContentVersionLoaderTests.cs @@ -14,6 +14,7 @@ using Squidex.Domain.Apps.Core.Contents; using Squidex.Domain.Apps.Events.Contents; using Squidex.Infrastructure; using Squidex.Infrastructure.EventSourcing; +using Squidex.Infrastructure.States; using Xunit; namespace Squidex.Domain.Apps.Write.Contents @@ -21,8 +22,8 @@ namespace Squidex.Domain.Apps.Write.Contents public class ContentVersionLoaderTests { private readonly IEventStore eventStore = A.Fake(); + private readonly IEventDataFormatter formatter = A.Fake(); private readonly IStreamNameResolver nameResolver = A.Fake(); - private readonly EventDataFormatter formatter = A.Fake(); private readonly Guid id = Guid.NewGuid(); private readonly Guid appId = Guid.NewGuid(); private readonly string streamName = Guid.NewGuid().ToString(); @@ -30,7 +31,7 @@ namespace Squidex.Domain.Apps.Write.Contents public ContentVersionLoaderTests() { - A.CallTo(() => nameResolver.GetStreamName(typeof(ContentDomainObject), id)) + A.CallTo(() => nameResolver.GetStreamName(typeof(ContentDomainObject), id.ToString())) .Returns(streamName); sut = new ContentVersionLoader(eventStore, nameResolver, formatter); @@ -39,7 +40,7 @@ namespace Squidex.Domain.Apps.Write.Contents [Fact] public async Task Should_throw_exception_when_event_store_returns_no_events() { - A.CallTo(() => eventStore.GetEventsAsync(streamName)) + A.CallTo(() => eventStore.GetEventsAsync(streamName, 0)) .Returns(new List()); await Assert.ThrowsAsync(() => sut.LoadAsync(appId, id, -1)); @@ -48,7 +49,7 @@ namespace Squidex.Domain.Apps.Write.Contents [Fact] public async Task Should_throw_exception_when_version_not_found() { - A.CallTo(() => eventStore.GetEventsAsync(streamName)) + A.CallTo(() => eventStore.GetEventsAsync(streamName, 0)) .Returns(new List()); await Assert.ThrowsAsync(() => sut.LoadAsync(appId, id, 3)); @@ -66,7 +67,7 @@ namespace Squidex.Domain.Apps.Write.Contents new StoredEvent("0", 0, eventData1) }; - A.CallTo(() => eventStore.GetEventsAsync(streamName)) + A.CallTo(() => eventStore.GetEventsAsync(streamName, 0)) .Returns(events); A.CallTo(() => formatter.Parse(eventData1, true)) @@ -90,7 +91,7 @@ namespace Squidex.Domain.Apps.Write.Contents new StoredEvent("1", 1, eventData2) }; - A.CallTo(() => eventStore.GetEventsAsync(streamName)) + A.CallTo(() => eventStore.GetEventsAsync(streamName, 0)) .Returns(events); A.CallTo(() => formatter.Parse(eventData1, true)) @@ -121,7 +122,7 @@ namespace Squidex.Domain.Apps.Write.Contents new StoredEvent("2", 2, eventData3) }; - A.CallTo(() => eventStore.GetEventsAsync(streamName)) + A.CallTo(() => eventStore.GetEventsAsync(streamName, 0)) .Returns(events); A.CallTo(() => formatter.Parse(eventData1, true)) diff --git a/tests/Squidex.Domain.Apps.Write.Tests/Rules/RuleDomainObjectTests.cs b/tests/Squidex.Domain.Apps.Write.Tests/Rules/RuleDomainObjectTests.cs index bcf2147a7..b6029798c 100644 --- a/tests/Squidex.Domain.Apps.Write.Tests/Rules/RuleDomainObjectTests.cs +++ b/tests/Squidex.Domain.Apps.Write.Tests/Rules/RuleDomainObjectTests.cs @@ -15,7 +15,7 @@ using Squidex.Domain.Apps.Events.Rules; using Squidex.Domain.Apps.Write.Rules.Commands; using Squidex.Domain.Apps.Write.TestHelpers; using Squidex.Infrastructure; -using Squidex.Infrastructure.CQRS; +using Squidex.Infrastructure.Commands; using Xunit; namespace Squidex.Domain.Apps.Write.Rules diff --git a/tests/Squidex.Domain.Apps.Write.Tests/Schemas/SchemaDomainObjectTests.cs b/tests/Squidex.Domain.Apps.Write.Tests/Schemas/SchemaDomainObjectTests.cs index 5fe9652a0..69fd68ebd 100644 --- a/tests/Squidex.Domain.Apps.Write.Tests/Schemas/SchemaDomainObjectTests.cs +++ b/tests/Squidex.Domain.Apps.Write.Tests/Schemas/SchemaDomainObjectTests.cs @@ -13,7 +13,7 @@ using Squidex.Domain.Apps.Events.Schemas; using Squidex.Domain.Apps.Write.Schemas.Commands; using Squidex.Domain.Apps.Write.TestHelpers; using Squidex.Infrastructure; -using Squidex.Infrastructure.CQRS; +using Squidex.Infrastructure.Commands; using Xunit; namespace Squidex.Domain.Apps.Write.Schemas diff --git a/tests/Squidex.Domain.Apps.Write.Tests/TestHelpers/HandlerTestBase.cs b/tests/Squidex.Domain.Apps.Write.Tests/TestHelpers/HandlerTestBase.cs index ae2d37688..2425a7e86 100644 --- a/tests/Squidex.Domain.Apps.Write.Tests/TestHelpers/HandlerTestBase.cs +++ b/tests/Squidex.Domain.Apps.Write.Tests/TestHelpers/HandlerTestBase.cs @@ -10,7 +10,6 @@ using System; using System.Threading.Tasks; using Squidex.Domain.Apps.Events; using Squidex.Infrastructure; -using Squidex.Infrastructure.CQRS; using Squidex.Infrastructure.Commands; #pragma warning disable IDE0019 // Use pattern matching diff --git a/tests/Squidex.Infrastructure.Tests/States/StateSnapshotTests.cs b/tests/Squidex.Infrastructure.Tests/States/StateSnapshotTests.cs index 23bfa3743..40b888c17 100644 --- a/tests/Squidex.Infrastructure.Tests/States/StateSnapshotTests.cs +++ b/tests/Squidex.Infrastructure.Tests/States/StateSnapshotTests.cs @@ -191,7 +191,7 @@ namespace Squidex.Infrastructure.States .Returns((123, version)); A.CallTo(() => snapshotStore.WriteAsync(key, 123, version, 2)) - .Throws(new InconsistentStateException(1, 1)); + .Throws(new InconsistentStateException(1, 1, new InvalidOperationException())); var actualObject = await sut.GetSynchronizedAsync(key);