Browse Source

Actor => Grain

pull/195/head
Sebastian Stehle 8 years ago
parent
commit
168262f61a
  1. 8
      src/Squidex.Infrastructure/CQRS/Events/Grains/EventConsumerGrain.cs
  2. 12
      src/Squidex.Infrastructure/CQRS/Events/Grains/EventConsumerGrainManager.cs
  3. 2
      src/Squidex.Infrastructure/CQRS/Events/Grains/EventConsumerState.cs
  4. 2
      src/Squidex.Infrastructure/CQRS/Events/Grains/Messages/GetStatesRequest.cs
  5. 2
      src/Squidex.Infrastructure/CQRS/Events/Grains/Messages/GetStatesResponse.cs
  6. 2
      src/Squidex.Infrastructure/CQRS/Events/Grains/Messages/ResetConsumerMessage.cs
  7. 2
      src/Squidex.Infrastructure/CQRS/Events/Grains/Messages/StartConsumerMessage.cs
  8. 2
      src/Squidex.Infrastructure/CQRS/Events/Grains/Messages/StopConsumerMessage.cs
  9. 2
      src/Squidex/Areas/Api/Controllers/EventConsumers/EventConsumersController.cs
  10. 6
      src/Squidex/Config/Domain/ReadServices.cs
  11. 10
      tests/Benchmarks/Tests/HandleEvents.cs
  12. 10
      tests/Benchmarks/Tests/HandleEventsWithManyWriters.cs
  13. 16
      tests/Squidex.Infrastructure.Tests/CQRS/Events/Actors/EventConsumerGrainTests.cs
  14. 16
      tests/Squidex.Infrastructure.Tests/CQRS/Events/Actors/EventConsumerManagerTests.cs
  15. 2
      tests/Squidex.Infrastructure.Tests/CQRS/Events/RetrySubscriptionTests.cs

8
src/Squidex.Infrastructure/CQRS/Events/Actors/EventConsumerActor.cs → src/Squidex.Infrastructure/CQRS/Events/Grains/EventConsumerGrain.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// EventConsumerActor.cs // EventConsumerGrain.cs
// Squidex Headless CMS // Squidex Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) Squidex Group // Copyright (c) Squidex Group
@ -12,9 +12,9 @@ using Squidex.Infrastructure.Log;
using Squidex.Infrastructure.States; using Squidex.Infrastructure.States;
using Squidex.Infrastructure.Tasks; using Squidex.Infrastructure.Tasks;
namespace Squidex.Infrastructure.CQRS.Events.Actors namespace Squidex.Infrastructure.CQRS.Events.Grains
{ {
public class EventConsumerActor : StatefulObject<EventConsumerState>, IEventSubscriber public class EventConsumerGrain : StatefulObject<EventConsumerState>, IEventSubscriber
{ {
private readonly EventDataFormatter formatter; private readonly EventDataFormatter formatter;
private readonly IEventStore eventStore; private readonly IEventStore eventStore;
@ -23,7 +23,7 @@ namespace Squidex.Infrastructure.CQRS.Events.Actors
private IEventSubscription currentSubscription; private IEventSubscription currentSubscription;
private IEventConsumer eventConsumer; private IEventConsumer eventConsumer;
public EventConsumerActor( public EventConsumerGrain(
EventDataFormatter formatter, EventDataFormatter formatter,
IEventStore eventStore, IEventStore eventStore,
ISemanticLog log) ISemanticLog log)

12
src/Squidex.Infrastructure/CQRS/Events/Actors/EventConsumerActorManager.cs → src/Squidex.Infrastructure/CQRS/Events/Grains/EventConsumerGrainManager.cs

@ -10,19 +10,19 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Squidex.Infrastructure.CQRS.Events.Actors.Messages; using Squidex.Infrastructure.CQRS.Events.Grains.Messages;
using Squidex.Infrastructure.States; using Squidex.Infrastructure.States;
namespace Squidex.Infrastructure.CQRS.Events.Actors namespace Squidex.Infrastructure.CQRS.Events.Grains
{ {
public sealed class EventConsumerActorManager : DisposableObjectBase, IExternalSystem public sealed class EventConsumerGrainManager : DisposableObjectBase, IExternalSystem
{ {
private readonly IStateFactory factory; private readonly IStateFactory factory;
private readonly IPubSub pubSub; private readonly IPubSub pubSub;
private readonly List<IEventConsumer> consumers; private readonly List<IEventConsumer> consumers;
private readonly List<IDisposable> subscriptions = new List<IDisposable>(); private readonly List<IDisposable> subscriptions = new List<IDisposable>();
public EventConsumerActorManager(IEnumerable<IEventConsumer> consumers, IPubSub pubSub, IStateFactory factory) public EventConsumerGrainManager(IEnumerable<IEventConsumer> consumers, IPubSub pubSub, IStateFactory factory)
{ {
Guard.NotNull(pubSub, nameof(pubSub)); Guard.NotNull(pubSub, nameof(pubSub));
Guard.NotNull(factory, nameof(factory)); Guard.NotNull(factory, nameof(factory));
@ -35,11 +35,11 @@ namespace Squidex.Infrastructure.CQRS.Events.Actors
public void Connect() public void Connect()
{ {
var actors = new Dictionary<string, EventConsumerActor>(); var actors = new Dictionary<string, EventConsumerGrain>();
foreach (var consumer in consumers) foreach (var consumer in consumers)
{ {
var actor = factory.GetDetachedAsync<EventConsumerActor, EventConsumerState>(consumer.Name).Result; var actor = factory.GetDetachedAsync<EventConsumerGrain, EventConsumerState>(consumer.Name).Result;
actors[consumer.Name] = actor; actors[consumer.Name] = actor;
actor.Activate(consumer); actor.Activate(consumer);

2
src/Squidex.Infrastructure/CQRS/Events/Actors/EventConsumerState.cs → src/Squidex.Infrastructure/CQRS/Events/Grains/EventConsumerState.cs

@ -9,7 +9,7 @@
using System; using System;
using Squidex.Infrastructure.Reflection; using Squidex.Infrastructure.Reflection;
namespace Squidex.Infrastructure.CQRS.Events.Actors namespace Squidex.Infrastructure.CQRS.Events.Grains
{ {
public sealed class EventConsumerState public sealed class EventConsumerState
{ {

2
src/Squidex.Infrastructure/CQRS/Events/Actors/Messages/GetStatesRequest.cs → src/Squidex.Infrastructure/CQRS/Events/Grains/Messages/GetStatesRequest.cs

@ -6,7 +6,7 @@
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
namespace Squidex.Infrastructure.CQRS.Events.Actors.Messages namespace Squidex.Infrastructure.CQRS.Events.Grains.Messages
{ {
public sealed class GetStatesRequest public sealed class GetStatesRequest
{ {

2
src/Squidex.Infrastructure/CQRS/Events/Actors/Messages/GetStatesResponse.cs → src/Squidex.Infrastructure/CQRS/Events/Grains/Messages/GetStatesResponse.cs

@ -6,7 +6,7 @@
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
namespace Squidex.Infrastructure.CQRS.Events.Actors.Messages namespace Squidex.Infrastructure.CQRS.Events.Grains.Messages
{ {
public sealed class GetStatesResponse public sealed class GetStatesResponse
{ {

2
src/Squidex.Infrastructure/CQRS/Events/Actors/Messages/ResetConsumerMessage.cs → src/Squidex.Infrastructure/CQRS/Events/Grains/Messages/ResetConsumerMessage.cs

@ -6,7 +6,7 @@
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
namespace Squidex.Infrastructure.CQRS.Events.Actors.Messages namespace Squidex.Infrastructure.CQRS.Events.Grains.Messages
{ {
public sealed class ResetConsumerMessage public sealed class ResetConsumerMessage
{ {

2
src/Squidex.Infrastructure/CQRS/Events/Actors/Messages/StartConsumerMessage.cs → src/Squidex.Infrastructure/CQRS/Events/Grains/Messages/StartConsumerMessage.cs

@ -6,7 +6,7 @@
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
namespace Squidex.Infrastructure.CQRS.Events.Actors.Messages namespace Squidex.Infrastructure.CQRS.Events.Grains.Messages
{ {
public sealed class StartConsumerMessage public sealed class StartConsumerMessage
{ {

2
src/Squidex.Infrastructure/CQRS/Events/Actors/Messages/StopConsumerMessage.cs → src/Squidex.Infrastructure/CQRS/Events/Grains/Messages/StopConsumerMessage.cs

@ -6,7 +6,7 @@
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
namespace Squidex.Infrastructure.CQRS.Events.Actors.Messages namespace Squidex.Infrastructure.CQRS.Events.Grains.Messages
{ {
public sealed class StopConsumerMessage public sealed class StopConsumerMessage
{ {

2
src/Squidex/Areas/Api/Controllers/EventConsumers/EventConsumersController.cs

@ -14,7 +14,7 @@ using NSwag.Annotations;
using Squidex.Areas.Api.Controllers.EventConsumers.Models; using Squidex.Areas.Api.Controllers.EventConsumers.Models;
using Squidex.Infrastructure; using Squidex.Infrastructure;
using Squidex.Infrastructure.CQRS.Commands; using Squidex.Infrastructure.CQRS.Commands;
using Squidex.Infrastructure.CQRS.Events.Actors.Messages; using Squidex.Infrastructure.CQRS.Events.Grains.Messages;
using Squidex.Infrastructure.Reflection; using Squidex.Infrastructure.Reflection;
using Squidex.Pipeline; using Squidex.Pipeline;

6
src/Squidex/Config/Domain/ReadServices.cs

@ -30,7 +30,7 @@ using Squidex.Domain.Users;
using Squidex.Infrastructure; using Squidex.Infrastructure;
using Squidex.Infrastructure.Assets; using Squidex.Infrastructure.Assets;
using Squidex.Infrastructure.CQRS.Events; using Squidex.Infrastructure.CQRS.Events;
using Squidex.Infrastructure.CQRS.Events.Actors; using Squidex.Infrastructure.CQRS.Events.Grains;
using Squidex.Infrastructure.States; using Squidex.Infrastructure.States;
using Squidex.Pipeline; using Squidex.Pipeline;
@ -44,9 +44,9 @@ namespace Squidex.Config.Domain
if (consumeEvents) if (consumeEvents)
{ {
services.AddTransient<EventConsumerActor>(); services.AddTransient<EventConsumerGrain>();
services.AddSingletonAs<EventConsumerActorManager>() services.AddSingletonAs<EventConsumerGrainManager>()
.As<IExternalSystem>(); .As<IExternalSystem>();
services.AddSingletonAs<RuleDequeuer>() services.AddSingletonAs<RuleDequeuer>()
.As<IExternalSystem>(); .As<IExternalSystem>();

10
tests/Benchmarks/Tests/HandleEvents.cs

@ -10,7 +10,7 @@ using System;
using Benchmarks.Tests.TestData; using Benchmarks.Tests.TestData;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Squidex.Infrastructure.CQRS.Events; using Squidex.Infrastructure.CQRS.Events;
using Squidex.Infrastructure.CQRS.Events.Actors; using Squidex.Infrastructure.CQRS.Events.Grains;
using Squidex.Infrastructure.States; using Squidex.Infrastructure.States;
namespace Benchmarks.Tests namespace Benchmarks.Tests
@ -20,7 +20,7 @@ namespace Benchmarks.Tests
private const int NumEvents = 5000; private const int NumEvents = 5000;
private IServiceProvider services; private IServiceProvider services;
private IEventStore eventStore; private IEventStore eventStore;
private EventConsumerActor eventConsumerActor; private EventConsumerGrain eventConsumerGrain;
private EventDataFormatter eventDataFormatter; private EventDataFormatter eventDataFormatter;
private MyEventConsumer eventConsumer; private MyEventConsumer eventConsumer;
@ -33,10 +33,10 @@ namespace Benchmarks.Tests
eventStore = services.GetRequiredService<IEventStore>(); eventStore = services.GetRequiredService<IEventStore>();
eventDataFormatter = services.GetRequiredService<EventDataFormatter>(); eventDataFormatter = services.GetRequiredService<EventDataFormatter>();
eventConsumerActor = services.GetRequiredService<EventConsumerActor>(); eventConsumerGrain = services.GetRequiredService<EventConsumerGrain>();
eventConsumerActor.ActivateAsync(services.GetRequiredService<StateHolder<EventConsumerState>>()).Wait(); eventConsumerGrain.ActivateAsync(services.GetRequiredService<StateHolder<EventConsumerState>>()).Wait();
eventConsumerActor.Activate(eventConsumer); eventConsumerGrain.Activate(eventConsumer);
} }
public override long Run() public override long Run()

10
tests/Benchmarks/Tests/HandleEventsWithManyWriters.cs

@ -11,7 +11,7 @@ using System.Threading.Tasks;
using Benchmarks.Tests.TestData; using Benchmarks.Tests.TestData;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Squidex.Infrastructure.CQRS.Events; using Squidex.Infrastructure.CQRS.Events;
using Squidex.Infrastructure.CQRS.Events.Actors; using Squidex.Infrastructure.CQRS.Events.Grains;
using Squidex.Infrastructure.States; using Squidex.Infrastructure.States;
namespace Benchmarks.Tests namespace Benchmarks.Tests
@ -22,7 +22,7 @@ namespace Benchmarks.Tests
private const int NumStreams = 10; private const int NumStreams = 10;
private IServiceProvider services; private IServiceProvider services;
private IEventStore eventStore; private IEventStore eventStore;
private EventConsumerActor eventConsumerActor; private EventConsumerGrain eventConsumerGrain;
private EventDataFormatter eventDataFormatter; private EventDataFormatter eventDataFormatter;
private MyEventConsumer eventConsumer; private MyEventConsumer eventConsumer;
@ -35,10 +35,10 @@ namespace Benchmarks.Tests
eventStore = services.GetRequiredService<IEventStore>(); eventStore = services.GetRequiredService<IEventStore>();
eventDataFormatter = services.GetRequiredService<EventDataFormatter>(); eventDataFormatter = services.GetRequiredService<EventDataFormatter>();
eventConsumerActor = services.GetRequiredService<EventConsumerActor>(); eventConsumerGrain = services.GetRequiredService<EventConsumerGrain>();
eventConsumerActor.ActivateAsync(services.GetRequiredService<StateHolder<EventConsumerState>>()).Wait(); eventConsumerGrain.ActivateAsync(services.GetRequiredService<StateHolder<EventConsumerState>>()).Wait();
eventConsumerActor.Activate(eventConsumer); eventConsumerGrain.Activate(eventConsumer);
} }
public override long Run() public override long Run()

16
tests/Squidex.Infrastructure.Tests/CQRS/Events/Actors/EventConsumerActorTests.cs → tests/Squidex.Infrastructure.Tests/CQRS/Events/Actors/EventConsumerGrainTests.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// EventConsumerActorTests.cs // EventConsumerGrainTests.cs
// Squidex Headless CMS // Squidex Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) Squidex Group // Copyright (c) Squidex Group
@ -14,17 +14,17 @@ using Squidex.Infrastructure.Log;
using Squidex.Infrastructure.States; using Squidex.Infrastructure.States;
using Xunit; using Xunit;
namespace Squidex.Infrastructure.CQRS.Events.Actors namespace Squidex.Infrastructure.CQRS.Events.Grains
{ {
public class EventConsumerActorTests public class EventConsumerGrainTests
{ {
public sealed class MyEvent : IEvent public sealed class MyEvent : IEvent
{ {
} }
public sealed class MyEventConsumerActor : EventConsumerActor public sealed class MyEventConsumerGrain : EventConsumerGrain
{ {
public MyEventConsumerActor(EventDataFormatter formatter, IEventStore eventStore, ISemanticLog log) public MyEventConsumerGrain(EventDataFormatter formatter, IEventStore eventStore, ISemanticLog log)
: base(formatter, eventStore, log) : base(formatter, eventStore, log)
{ {
} }
@ -44,12 +44,12 @@ namespace Squidex.Infrastructure.CQRS.Events.Actors
private readonly EventDataFormatter formatter = A.Fake<EventDataFormatter>(); private readonly EventDataFormatter formatter = A.Fake<EventDataFormatter>();
private readonly EventData eventData = new EventData(); private readonly EventData eventData = new EventData();
private readonly Envelope<IEvent> envelope = new Envelope<IEvent>(new MyEvent()); private readonly Envelope<IEvent> envelope = new Envelope<IEvent>(new MyEvent());
private readonly EventConsumerActor sut; private readonly EventConsumerGrain sut;
private readonly string consumerName; private readonly string consumerName;
private readonly string initialPosition = Guid.NewGuid().ToString(); private readonly string initialPosition = Guid.NewGuid().ToString();
private EventConsumerState state = new EventConsumerState(); private EventConsumerState state = new EventConsumerState();
public EventConsumerActorTests() public EventConsumerGrainTests()
{ {
state.Position = initialPosition; state.Position = initialPosition;
@ -69,7 +69,7 @@ namespace Squidex.Infrastructure.CQRS.Events.Actors
A.CallTo(() => formatter.Parse(eventData, true)).Returns(envelope); A.CallTo(() => formatter.Parse(eventData, true)).Returns(envelope);
sut = new MyEventConsumerActor(formatter, eventStore, log); sut = new MyEventConsumerGrain(formatter, eventStore, log);
sutSubscriber = sut; sutSubscriber = sut;
sut.ActivateAsync(stateHolder).Wait(); sut.ActivateAsync(stateHolder).Wait();

16
tests/Squidex.Infrastructure.Tests/CQRS/Events/Actors/EventConsumerManagerTests.cs

@ -10,33 +10,33 @@ using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using FakeItEasy; using FakeItEasy;
using FluentAssertions; using FluentAssertions;
using Squidex.Infrastructure.CQRS.Events.Actors.Messages; using Squidex.Infrastructure.CQRS.Events.Grains.Messages;
using Squidex.Infrastructure.States; using Squidex.Infrastructure.States;
using Xunit; using Xunit;
namespace Squidex.Infrastructure.CQRS.Events.Actors namespace Squidex.Infrastructure.CQRS.Events.Grains
{ {
public class EventConsumerManagerTests public class EventConsumerManagerTests
{ {
private readonly EventConsumerActor actor1 = A.Fake<EventConsumerActor>(); private readonly EventConsumerGrain actor1 = A.Fake<EventConsumerGrain>();
private readonly EventConsumerActor actor2 = A.Fake<EventConsumerActor>(); private readonly EventConsumerGrain actor2 = A.Fake<EventConsumerGrain>();
private readonly IStateFactory factory = A.Fake<IStateFactory>(); private readonly IStateFactory factory = A.Fake<IStateFactory>();
private readonly IEventConsumer consumer1 = A.Fake<IEventConsumer>(); private readonly IEventConsumer consumer1 = A.Fake<IEventConsumer>();
private readonly IEventConsumer consumer2 = A.Fake<IEventConsumer>(); private readonly IEventConsumer consumer2 = A.Fake<IEventConsumer>();
private readonly IPubSub pubSub = new InMemoryPubSub(); private readonly IPubSub pubSub = new InMemoryPubSub();
private readonly string consumerName1 = "Consumer1"; private readonly string consumerName1 = "Consumer1";
private readonly string consumerName2 = "Consumer2"; private readonly string consumerName2 = "Consumer2";
private readonly EventConsumerActorManager sut; private readonly EventConsumerGrainManager sut;
public EventConsumerManagerTests() public EventConsumerManagerTests()
{ {
A.CallTo(() => consumer1.Name).Returns(consumerName1); A.CallTo(() => consumer1.Name).Returns(consumerName1);
A.CallTo(() => consumer2.Name).Returns(consumerName2); A.CallTo(() => consumer2.Name).Returns(consumerName2);
A.CallTo(() => factory.GetDetachedAsync<EventConsumerActor, EventConsumerState>(consumerName1)).Returns(actor1); A.CallTo(() => factory.GetDetachedAsync<EventConsumerGrain, EventConsumerState>(consumerName1)).Returns(actor1);
A.CallTo(() => factory.GetDetachedAsync<EventConsumerActor, EventConsumerState>(consumerName2)).Returns(actor2); A.CallTo(() => factory.GetDetachedAsync<EventConsumerGrain, EventConsumerState>(consumerName2)).Returns(actor2);
sut = new EventConsumerActorManager(new IEventConsumer[] { consumer1, consumer2 }, pubSub, factory); sut = new EventConsumerGrainManager(new IEventConsumer[] { consumer1, consumer2 }, pubSub, factory);
} }
[Fact] [Fact]

2
tests/Squidex.Infrastructure.Tests/CQRS/Events/RetrySubscriptionTests.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// EventConsumerActorTests.cs // RetrySubscriptionTests.cs
// Squidex Headless CMS // Squidex Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) Squidex Group // Copyright (c) Squidex Group

Loading…
Cancel
Save