public Process_actor_should_execute_async_processes_with_block(ITestOutputHelper output) { var logger = new XUnitAutoTestLoggerConfiguration(output).CreateLogger(); var creator = new AsyncLongRunningProcessManagerFactory(); _localAkkaEventBusTransport = Sys.InitLocalTransportExtension().Transport; var blackHole = Sys.ActorOf(BlackHoleActor.Props); var messageProcessActor = Sys.ActorOf(Props.Create(() => new HandlersPipeActor(new HandlersDefaultProcessor(), blackHole))); _processId = Guid.NewGuid().ToString(); var container = new ContainerBuilder(); container.Register <ProcessStateActor <TestState> >(c => new ProcessStateActor <TestState>(CommandAggregateHandler.New <ProcessStateAggregate <TestState> >(), new EachMessageSnapshotsPersistencePolicy(), AggregateFactory.Default, AggregateFactory.Default, messageProcessActor)); Sys.AddDependencyResolver(new AutoFacDependencyResolver(container.Build(), Sys)); Sys.AttachSerilogLogging(logger); //for process state retrival var processStateActor = Sys.ActorOf(Props.Create(() => new ProcessStateHubActor <TestState>(new DefaultRecycleConfiguration())), typeof(TestState).BeautyName() + "_Hub"); var name = EntityActorName.New <ProcessStateAggregate <TestState> >(_processId).Name; _processActor = ActorOfAsTestActorRef(() => new ProcessActor <TestState>(new AsyncLongRunningProcess(), creator), name); }
public async Task Save <T>(T aggr) where T : Aggregate { var persistId = EntityActorName.New <T>(aggr.Id).ToString(); await _eventRepository.Save(persistId, ((IAggregate)aggr).GetUncommittedEvents().ToArray()); aggr.ClearUncommitedEvents(); }
public static async Task <T> LoadAggregateByActor <T>(this TestKit kit, string id) where T : Aggregate { var name = EntityActorName.New <T>(id).ToString(); var actor = await kit.LoadActor <AggregateActor <T> >(name); return(actor.State); }
public virtual void Setup(BenchmarkContext context) { _counter = context.GetCounter(TotalCommandsExecutedCounter); var aggregateId = Guid.NewGuid().ToString(); _commands = CreateAggregatePlan(100, aggregateId).ToArray(); _actorSystem = ActorSystem.Create("test", _actorSystemConfig); _actorSystem.InitLocalTransportExtension(); _actorSystem.InitDomainEventsSerialization(new EventsAdaptersCatalog()); var log = new XUnitAutoTestLoggerConfiguration(_testOutputHelper, LogEventLevel.Warning, GetType().Name).CreateLogger(); _actorSystem.AttachSerilogLogging(log); var dummy = _actorSystem.ActorOf <CustomHandlersActorDummy>(); _aggregateActor = _actorSystem.ActorOf(Props.Create( () => new AggregateActor <Balloon>(new BalloonCommandHandler(), new EachMessageSnapshotsPersistencePolicy(), AggregateFactory.Default, AggregateFactory.Default, dummy)), EntityActorName.New <Balloon>(aggregateId).ToString()); }
public static async Task <IActorRef> LookupAggregateActor <T>(this GridDomainNode node, string id, TimeSpan?timeout = null) where T : IAggregate { var name = EntityActorName.New <T>(id).Name; return(await node.ResolveActor($"{typeof(T).Name}_Hub/{name}", timeout)); }
public static async Task <IActorRef> LookupProcessActor <TProcess, TData>(this GridDomainNode node, string id, TimeSpan?timeout = null) where TData : IProcessState { var name = EntityActorName.New <TProcess>(id).Name; var type = typeof(TProcess).BeautyName(); return(await node.ResolveActor($"{type}_Hub/{name}", timeout)); }
public void Instance_process_actor_can_be_created() { var actorType = typeof(ProcessActor <SoftwareProgrammingState>); var props = Node.System.DI().Props(actorType); var name = EntityActorName.New <ProcessStateAggregate <SoftwareProgrammingState> >(Guid.NewGuid().ToString()).ToString(); var actor = Node.System.ActorOf(props, name); actor.Tell(new CheckHealth()); ExpectMsg <HealthStatus>(); }
public async Task <T> LoadAggregate <T>(string id, IConstructAggregates factory = null) where T : IAggregate { var agr = (factory ?? DefaultFactory).BuildEmpty <T>(id); var persistId = EntityActorName.New <T>(id).ToString(); var events = await _eventRepository.Load(persistId); foreach (var e in events.SelectMany(e => _eventsAdaptersCatalog.Update(e).Cast <DomainEvent>())) { agr.Apply(e); } return(agr); }
public async Task Add<T>(T aggregate) where T : class, IAggregate { using (var repo = new RawSnapshotsRepository(option)) { var snapshot = _snapshotsConstructor.GetSnapshot(aggregate); var item = new SnapshotItem { Manifest = snapshot.GetType().AssemblyQualifiedShortName(), PersistenceId = EntityActorName.New<T>(aggregate.Id).Name, Snapshot = new DomainSerializer().ToBinary(snapshot), Timestamp = BusinessDateTime.UtcNow }; await repo.Save(item.PersistenceId, item); } }
public async Task<Version<T>[]> Load<T>(string id) where T : class, IAggregate { var snapshotType = _snapshotsConstructor.GetSnapshot(_aggregatesConstructor.BuildEmpty<T>()) .GetType(); var serializer = new DomainSerializer(); using (var snapshotItemsRepo = new RawSnapshotsRepository(option)) { return (await snapshotItemsRepo.Load(EntityActorName.New<T>(id). Name)).Select(s => { var memento = (IMemento) serializer.FromBinary(s.Snapshot, snapshotType); var aggregate = (T) _aggregatesConstructor.Build(typeof(T), id, memento); return new Version<T>(aggregate, s.Timestamp); }). ToArray(); } }
public void Aggregate_actor_produce_fault_with_processId_from_command() { var command = new GoSleepCommand(null, null).CloneForProcess(Guid.NewGuid().ToString()); var transport = Sys.InitLocalTransportExtension().Transport; transport.Subscribe <MessageMetadataEnvelop <Fault <GoSleepCommand> > >(TestActor); var handlersActor = Sys.ActorOf(Props.Create(() => new HandlersPipeActor(new HandlersDefaultProcessor(), TestActor))); var actor = Sys.ActorOf(Props.Create(() => new AggregateActor <ProgrammerAggregate>(CommandAggregateHandler.New <ProgrammerAggregate>(null), new SnapshotsPersistencePolicy(1, null, 5, null), AggregateFactory.Default, AggregateFactory.Default, handlersActor)), EntityActorName.New <ProgrammerAggregate>(command.Id).Name); actor.Tell(new MessageMetadataEnvelop <ICommand>(command, MessageMetadata.New(command.Id, null, null))); var fault = FishForMessage <MessageMetadataEnvelop>(m => m.Message is Fault <GoSleepCommand>).Message as IFault; Assert.Equal(command.ProcessId, fault.ProcessId); }
public async Task Given_only_aggregate_events_persisted_it_can_be_loaded(IRepository <DomainEvent> eventRepo, AggregateRepository aggrRepo) { try { _sourceId = Guid.NewGuid().ToString(); _created = new BalloonCreated("initial value", _sourceId); _changed = new BalloonTitleChanged("changed value", _sourceId); var persistenceId = EntityActorName.New <Balloon>(_sourceId).ToString(); await eventRepo.Save(persistenceId, _created, _changed); _aggregate = await aggrRepo.LoadAggregate <Balloon>(_sourceId); Assert.Equal(_sourceId, _aggregate.Id); Assert.Equal(_changed.Value, _aggregate.Title); } finally { eventRepo.Dispose(); aggrRepo.Dispose(); } }
internal override string GetChildActorName(string childId) { return(EntityActorName.New <TAggregate>(childId).ToString()); }
public static async Task KillProcessManager <TProcess, TState>(this GridDomainNode node, string id, TimeSpan?timeout = null) where TState : IProcessState { var hub = await node.LookupProcessHubActor <TProcess>(timeout); IActorRef processActor; try { processActor = await node.LookupProcessActor <TProcess, TState>(id, timeout); } catch { return; } await ShutDownHubActor(node, id, processActor, hub, timeout); var processStateHubActor = await node.ResolveActor($"{typeof(TState).Name}_Hub", timeout); var processStateActor = await node.ResolveActor($"{typeof(TState).Name}_Hub/" + EntityActorName.New <ProcessStateAggregate <TState> >(id), timeout); await ShutDownHubActor(node, id, processStateActor, processStateHubActor, timeout); }
public static async Task SaveToJournal <TAggregate>(this GridDomainNode node, string id, params DomainEvent[] messages) where TAggregate : Aggregate { var name = EntityActorName.New <TAggregate>(id).Name; await node.SaveToJournal(name, messages); }