예제 #1
0
 public async Task Then_execute_throws_exception_from_aggregate_with_stack_trace()
 {
     var syncCommand     = new AlwaysFaultAsyncCommand(Guid.NewGuid());
     var expectedMessage = Expect.Message <SampleAggregateChangedEvent>(e => e.SourceId, syncCommand.AggregateId);
     await GridNode.Execute(CommandPlan.New(syncCommand, Timeout, expectedMessage))
     .ShouldThrow <SampleAggregateException>(e => e.StackTrace.Contains(typeof(SampleAggregate).Name));
 }
예제 #2
0
        public void PlanExecute_doesnt_throw_exception_after_wait_with_timeout()
        {
            var syncCommand     = new LongOperationCommand(1000, Guid.NewGuid());
            var expectedMessage = Expect.Message <SampleAggregateChangedEvent>(e => e.SourceId, syncCommand.AggregateId);
            var plan            = CommandPlan.New(syncCommand, expectedMessage);

            Assert.False(GridNode.Execute(plan).Wait(100));
        }
예제 #3
0
        public async Task SyncExecute_throws_exception_from_aggregate_on_fault_wait_by_Node()
        {
            var syncCommand     = new AlwaysFaultCommand(Guid.NewGuid());
            var expectedMessage = Expect.Message <SampleAggregateChangedEvent>(e => e.SourceId, syncCommand.AggregateId);

            await GridNode.Execute(CommandPlan.New(syncCommand, Timeout, expectedMessage))
            .ShouldThrow <SampleAggregateException>();
        }
예제 #4
0
        public async Task PlanExecute_by_result_throws_exception_after_default_timeout()
        {
            var syncCommand     = new LongOperationCommand(1000, Guid.NewGuid());
            var expectedMessage = Expect.Message <SampleAggregateChangedEvent>(e => e.SourceId, syncCommand.AggregateId);
            var plan            = CommandPlan.New(syncCommand, TimeSpan.FromMilliseconds(500), expectedMessage);

            await GridNode.Execute(plan)
            .ShouldThrow <TimeoutException>();
        }
예제 #5
0
        public void Given_SyncExecute_until_projection_build_event_wait_by_caller()
        {
            _syncCommand = new LongOperationCommand(1000, Guid.NewGuid());
            var expectedMessage = Expect.Message <AggregateChangedEventNotification>(e => e.AggregateId, _syncCommand.AggregateId);

            _changedEvent = GridNode.Execute(CommandPlan.New(_syncCommand, Timeout, expectedMessage)).Result;

            _aggregate = LoadAggregate <SampleAggregate>(_syncCommand.AggregateId);
        }
예제 #6
0
        public async Task Then_SyncExecute_until_aggregate_event_wait_by_Node()
        {
            var syncCommand = new LongOperationCommand(1000, Guid.NewGuid());
            await GridNode.Execute(CommandPlan.New(syncCommand, TimeSpan.FromDays(1), Expect.Message <SampleAggregateChangedEvent>(nameof(SampleAggregateChangedEvent.SourceId), syncCommand.AggregateId)));

            var aggregate = LoadAggregate <SampleAggregate>(syncCommand.AggregateId);

            Assert.AreEqual(syncCommand.Parameter.ToString(), aggregate.Value);
        }
        public async Task SWhen_execute_waiting_without_timeout_default_timeout_is_used()
        {
            var syncCommand     = new LongOperationCommand(100, Guid.NewGuid());
            var expectedMessage = Expect.Message <AggregateChangedEventNotification>(e => e.AggregateId, syncCommand.AggregateId);

            var plan = new CommandPlan(syncCommand, TimeSpan.FromMilliseconds(50), expectedMessage);

            await GridNode.Execute(plan)
            .ShouldThrow <TimeoutException>();
        }
        public async Task When_async_method_finished_produced_events_has_sagaId_from_command()
        {
            var externalCallCommand = new AsyncMethodCommand(43, Guid.NewGuid(), Guid.NewGuid());
            var domainEvent         = await GridNode.Execute(CommandPlan.New(externalCallCommand,
                                                                             TimeSpan.FromDays(1),
                                                                             Expect.Message <SampleAggregateChangedEvent>(e => e.SourceId,
                                                                                                                          externalCallCommand.AggregateId)));

            Assert.AreEqual(externalCallCommand.SagaId, domainEvent.SagaId);
        }
예제 #9
0
        public async Task FutureDomainEvent_envelops_has_unique_id()
        {
            _aggregateId = Guid.NewGuid();
            var testCommandA = new ScheduleEventInFutureCommand(DateTime.Now.AddSeconds(1), _aggregateId, "test value A");
            var testCommandB = new ScheduleEventInFutureCommand(DateTime.Now.AddSeconds(2), _aggregateId, "test value B");

            _eventA = await GridNode.Execute(CommandPlan.New(testCommandA, Timeout, Expect.Message <FutureEventOccuredEvent>(e => e.SourceId, testCommandA.AggregateId)));

            _eventB = await GridNode.Execute(CommandPlan.New(testCommandB, Timeout, Expect.Message <FutureEventOccuredEvent>(e => e.SourceId, testCommandB.AggregateId)));
        }
예제 #10
0
        public async Task After_wait_end_aggregate_event_is_applied()
        {
            var syncCommand = new AsyncMethodCommand(42, Guid.NewGuid());
            await GridNode.Execute(CommandPlan.New(syncCommand,
                                                   Timeout,
                                                   Expect.Message <SampleAggregateChangedEvent>(e => e.SourceId, syncCommand.AggregateId)));

            var aggregate = LoadAggregate <SampleAggregate>(syncCommand.AggregateId);

            Assert.AreEqual(syncCommand.Parameter.ToString(), aggregate.Value);
        }
예제 #11
0
        public async Task After_wait_aggregate_should_be_changed()
        {
            var syncCommand     = new AsyncMethodCommand(42, Guid.NewGuid());
            var expectedMessage = Expect.Message <AggregateChangedEventNotification>(e => e.AggregateId,
                                                                                     syncCommand.AggregateId);

            await GridNode.Execute(CommandPlan.New(syncCommand, Timeout, expectedMessage));

            var aggregate = LoadAggregate <SampleAggregate>(syncCommand.AggregateId);

            Assert.AreEqual(syncCommand.Parameter.ToString(), aggregate.Value);
        }
        public async Task SyncExecute_with_projection_fault_with_expectation_in_plan_deliver_exception_to_caller()
        {
            var syncCommand   = new LongOperationCommand(100, Guid.NewGuid());
            var expectedFault = Expect.Fault <SampleAggregateChangedEvent>(e => e.SourceId, syncCommand.AggregateId,
                                                                           typeof(OddFaultyMessageHandler));
            var expectedMessage = Expect.Message <AggregateChangedEventNotification>(e => e.AggregateId,
                                                                                     syncCommand.AggregateId);

            var plan = new CommandPlan <AggregateChangedEventNotification>(syncCommand, expectedMessage, expectedFault);

            await GridNode.Execute(plan)
            .ShouldThrow <MessageHandleException>();
        }
예제 #13
0
        public async Task <T> Execute <T>(CommandPlan <T> plan)
        {
            var res = await Execute((CommandPlan)plan).ConfigureAwait(false);

            var envelop = res as IMessageMetadataEnvelop;

            if (envelop != null && !(typeof(IMessageMetadataEnvelop).IsAssignableFrom(typeof(T))))
            {
                return((T)envelop.Message);
            }

            return((T)res);
        }
        public async Task SyncExecute_with_projection_success_with_expectation_in_plan_deliver_message_to_caller()
        {
            var syncCommand   = new LongOperationCommand(101, Guid.NewGuid());
            var expectedFault = Expect.Fault <SampleAggregateChangedEvent>(e => e.SourceId, syncCommand.AggregateId,
                                                                           typeof(OddFaultyMessageHandler));
            var expectedMessage = Expect.Message <AggregateChangedEventNotification>(e => e.AggregateId,
                                                                                     syncCommand.AggregateId);
            var plan = new CommandPlan <AggregateChangedEventNotification>(syncCommand, expectedMessage, expectedFault);

            var evt = await GridNode.Execute(plan);

            Assert.AreEqual(syncCommand.AggregateId, evt.AggregateId);
        }
예제 #15
0
        public async Task SyncExecute_will_finish()
        {
            var syncCommand = new LongOperationCommand(1000, Guid.NewGuid());

            var changeExpect = Expect.Message <SampleAggregateChangedEvent>(e => e.SourceId, syncCommand.AggregateId);
            // var createExpect = Expect.Message<SampleAggregateCreatedEvent>(e => e.SourceId, syncCommand.AggregateId);

            await GridNode.Execute(CommandPlan.New(syncCommand, Timeout, changeExpect));

            var aggregate = LoadAggregate <SampleAggregate>(syncCommand.AggregateId);

            Assert.AreEqual(syncCommand.Parameter.ToString(), aggregate.Value);
        }
        public void Raising_several_future_events_for_different_aggregates()
        {
            _commandA = new ScheduleEventInFutureCommand(DateTime.Now.AddSeconds(0.5), Guid.NewGuid(), "test value A");
            var expectedMessageA = Expect.Message <FutureEventOccuredEvent>(e => e.SourceId, _commandA.AggregateId);
            var planA            = CommandPlan.New(_commandA, expectedMessageA);

            _commandB = new ScheduleEventInFutureCommand(DateTime.Now.AddSeconds(0.5), Guid.NewGuid(), "test value B");
            var expectedMessageB = Expect.Message <FutureEventOccuredEvent>(e => e.SourceId, _commandB.AggregateId);
            var planB            = CommandPlan.New(_commandB, expectedMessageB);

            var taskA = GridNode.Execute <FutureEventOccuredEvent>(planA).ContinueWith(r => _eventA = r.Result);
            var taskB = GridNode.Execute <FutureEventOccuredEvent>(planB).ContinueWith(r => _eventB = r.Result);

            Task.WaitAll(taskA, taskB);
        }
예제 #17
0
        public async Task SyncExecute_will_wait_for_all_of_expected_message_by_Node_with_message_base_class()
        {
            var syncCommand = new LongOperationCommand(1000, Guid.NewGuid());

            var changeExpect = Expect.Message <SampleAggregateChangedEvent>(e => e.SourceId, syncCommand.AggregateId);
            var createExpect = Expect.Message <SampleAggregateCreatedEvent>(e => e.SourceId, syncCommand.AggregateId);

            var commandPlan = new CommandPlan <object>(syncCommand,
                                                       TimeSpan.FromSeconds(1),
                                                       changeExpect,
                                                       createExpect);

            await GridNode.Execute(commandPlan)
            .ShouldThrow <TimeoutException>();
        }
        public void Then_events_are_applied_to_aggregate_after_wait_finish()
        {
            var syncCommand     = new AsyncMethodCommand(42, Guid.NewGuid());
            var expectedMessage = Expect.Message <SampleAggregateChangedEvent>(e => e.SourceId,
                                                                               syncCommand.AggregateId);
            var task = GridNode.Execute(CommandPlan.New(syncCommand, expectedMessage));

            if (!task.Wait(Timeout))
            {
                throw new TimeoutException();
            }

            //to finish persistence
            var aggregate = LoadAggregate <SampleAggregate>(syncCommand.AggregateId);

            Assert.AreEqual(syncCommand.Parameter.ToString(), aggregate.Value);
        }
예제 #19
0
        public async Task When_async_method_is_called_other_commands_can_be_executed_before_async_results()
        {
            var aggregateId  = Guid.NewGuid();
            var asyncCommand = new AsyncMethodCommand(43, Guid.NewGuid(), Guid.NewGuid(), TimeSpan.FromSeconds(3));
            var syncCommand  = new ChangeSampleAggregateCommand(42, aggregateId);

            var asyncCommandTask = GridNode.PrepareCommand(asyncCommand)
                                   .Expect <SampleAggregateChangedEvent>()
                                   .Execute();

            await GridNode.Execute(CommandPlan.New(syncCommand,
                                                   TimeSpan.FromSeconds(1),
                                                   Expect.Message <SampleAggregateChangedEvent>(e => e.SourceId,
                                                                                                syncCommand.AggregateId)));

            var sampleAggregate = LoadAggregate <SampleAggregate>(syncCommand.AggregateId);

            Assert.AreEqual(syncCommand.Parameter.ToString(), sampleAggregate.Value);
            var waitResults = await asyncCommandTask;

            Assert.AreEqual(asyncCommand.Parameter.ToString(), waitResults.Message <SampleAggregateChangedEvent>().Value);
        }
예제 #20
0
        public async Task <object> Execute(CommandPlan plan)
        {
            var waiter = new AkkaCommandLocalWaiter(this, _system, _transport, plan.Timeout, true);

            var expectBuilder = waiter.ExpectBuilder;

            //All expected messages should be received
            foreach (var expectedMessage in plan.ExpectedMessages.Where(e => !typeof(IFault).IsAssignableFrom(e.MessageType)))
            {
                expectBuilder.And(MessageMetadataEnvelop.GenericForType(expectedMessage.MessageType),
                                  o => expectedMessage.Match((o as IMessageMetadataEnvelop)?.Message));
            }


            //All expected faults should end waiting
            foreach (var expectedMessage in plan.ExpectedMessages.Where(e => typeof(IFault).IsAssignableFrom(e.MessageType)))
            {
                expectBuilder.Or(MessageMetadataEnvelop.GenericForType(expectedMessage.MessageType),
                                 o => expectedMessage.Match((o as IMessageMetadataEnvelop)?.Message) &&
                                 (!expectedMessage.Sources.Any() ||
                                  expectedMessage.Sources.Contains(((o as IMessageMetadataEnvelop)?.Message as IFault)?.Processor)));
            }

            //Command fault should always end waiting
            var commandFaultType = typeof(IFault <>).MakeGenericType(plan.Command.GetType());

            expectBuilder.Or(MessageMetadataEnvelop.GenericForType(commandFaultType),
                             o => (((o as IMessageMetadataEnvelop)?.Message as IFault)?.Message as ICommand)?.Id == plan.Command.Id);


            var res = await expectBuilder.Create(plan.Timeout)
                      .Execute(plan.Command)
                      .ConfigureAwait(false);

            return(res.All.Count > 1 ? res.All.ToArray() : res.All.FirstOrDefault());
        }
예제 #21
0
 public async Task <object> Execute(CommandPlan plan)
 {
     return(await _commandExecutor.Execute(plan));
 }
예제 #22
0
 public Task <object> Execute(CommandPlan plan)
 {
     return(_commandExecutor.Execute(plan));
 }
예제 #23
0
 public Task <T> Execute <T>(CommandPlan <T> plan)
 {
     return(_commandExecutor.Execute(plan));
 }
예제 #24
0
 public async Task <T> Execute <T>(CommandPlan <T> plan)
 {
     return(await _commandExecutor.Execute(plan));
 }