public void Dulicate_message_is_detected()
        {
            var builder = new CqrsEngineBuilder();

            builder.Memory(m =>
            {
                m.AddMemorySender("in", s => s.IdGenerator(() => "same"));
                m.AddMemoryRouter("in", c => "memory:null");
            });
            var observer = new ImmediateEventsObserver();

            builder.Advanced.RegisterObserver(observer);

            using (var token = new CancellationTokenSource())
                using (var build = builder.Build())
                {
                    var sender = build.Resolve <IMessageSender>();
                    sender.SendOne(new Message());
                    sender.SendOne(new Message());

                    observer.Event += @event =>
                    {
                        var e = @event as EnvelopeDuplicateDiscarded;

                        if (e != null)
                        {
                            token.Cancel();
                        }
                    };
                    build.Start(token.Token);
                    token.Token.WaitHandle.WaitOne(10000);
                    Assert.IsTrue(token.IsCancellationRequested);
                }
        }
        // ReSharper disable InconsistentNaming

        protected override void CurrentConfig(CqrsEngineBuilder config)
        {
            config.Memory(m =>
            {
                m.AddMemoryProcess("do", x => x.DispatchAsCommandBatch());
                m.AddMemorySender("do", cb => cb.IdGeneratorForTests());
            });
        }
Пример #3
0
 protected override void EngineConfig(CqrsEngineBuilder config)
 {
     config.Memory(m =>
     {
         m.AddMemoryProcess("do");
         m.AddMemorySender("do", cb => cb.IdGeneratorForTests());
     });
 }
 protected override void Configure(CqrsEngineBuilder b)
 {
     b.Memory(m =>
     {
         m.AddMemoryProcess("in");
         m.AddMemorySender("in");
     });
     EnlistMessage(new Do());
 }
 protected override void EngineConfig(CqrsEngineBuilder b)
 {
     b.Storage(m => m.AtomicIsInFiles(_path, DefaultWithCustomConfig));
     b.Memory(m =>
     {
         m.AddMemoryProcess("azure-dev");
         m.AddMemorySender("azure-dev", x => x.IdGeneratorForTests());
     });
 }
Пример #6
0
        public void Test()
        {
            var builder = new CqrsEngineBuilder();

            builder.Domain(mdm =>
            {
                mdm.HandlerSample <IConsume <object> >(c => c.Consume(null));
                mdm.WhereMessages(t => typeof(IBaseMessage1).IsAssignableFrom(t) || typeof(IBaseMessage2).IsAssignableFrom(t));
                mdm.InAssemblyOf(this);
            });

            builder.Memory(m =>
            {
                m.AddMemoryProcess("in");
                m.AddMemorySender("in");
            });

            var subj = new Subject <ISystemEvent>();

            builder.Advanced.Observers.Clear();
            builder.Advanced.Observers.Add(subj);



            using (var engine = builder.Build())
                using (var source = new CancellationTokenSource())
                {
                    int counter = 0;
                    subj.Where(t => t is EnvelopeAcked).Subscribe(e =>
                    {
                        if (++counter == 2)
                        {
                            source.Cancel();
                        }
                    });

                    engine.Start(source.Token);
                    var sender = engine.Resolve <IMessageSender>();
                    sender.SendOne(new Message1());
                    sender.SendOne(new Message2());

                    if (!source.Token.WaitHandle.WaitOne(3000))
                    {
                        Assert.Fail("This should've been canceled by now");
                    }
                }
        }
Пример #7
0
        // ReSharper disable InconsistentNaming


        static CqrsEngineHost BuildHost()
        {
            var builder = new CqrsEngineBuilder();

            builder.Azure(x => x.AddAzureProcess(AzureStorage.CreateConfigurationForDev(), "process-vip"));
            builder.Memory(x =>
            {
                x.AddMemoryProcess("process-all");
                x.AddMemoryRouter("inbox", e =>
                {
                    var isVip = e.Items.Any(i => i.MappedType == typeof(VipMessage));
                    return(isVip ? "azure-dev:process-vip" : "memory:process-all");
                });
                x.AddMemorySender("inbox", cm => cm.IdGeneratorForTests());
            });


            return(builder.Build());
        }
        public void Run_in_test()
        {
            var builder = new CqrsEngineBuilder();

            builder.Memory(m =>
            {
                m.AddMemorySender("work");
                m.AddMemoryProcess("work");
            });
            builder.Storage(m => m.AtomicIsInMemory());

            using (var engine = builder.Build())
            {
                //engine.Resolve<IMessageSender>().SendOne(new CreateCustomer()
                //{
                //    CustomerId = 1,
                //    CustomerName = "Rinat Abdullin"
                //});
                engine.RunForever();
            }
        }
Пример #9
0
        public void Test()
        {
            var builder = new CqrsEngineBuilder();

            builder.Domain(m =>
            {
                m.HandlerSample <Definitions.Define.Consumer <Definitions.Define.ICommand> >(c => c.Consume(null));
                m.ContextFactory((e, x) => new Definitions.Define.MyContext(e.GetAttribute("EntityId", "")));
            });
            builder.Storage(m => m.AtomicIsInMemory());
            builder.Memory(m =>
            {
                m.AddMemorySender("in", c => c.IdGeneratorForTests());
                m.AddMemoryProcess("in");
            });

            builder.Advanced.ConfigureContainer(cb =>
            {
                cb.Register(c => new InMemoryEventStreamer <IAccountEvent>(c.Resolve <IMessageSender>())).
                SingleInstance();

                cb.RegisterType <InMemoryEventStreamer <IAccountEvent> >().SingleInstance();
                cb.RegisterType <AccountAggregateRepository>().SingleInstance();
            });

            using (var source = new CancellationTokenSource())
                using (var engine = builder.Build())
                {
                    engine.Start(source.Token);

                    var sender = engine.Resolve <IMessageSender>();
                    sender.SendOne(new CreateAccount("Sample User"), cb => cb.AddString("EntityId", "1"));
                    sender.SendOne(new AddLogin("login", "pass"), cb => cb.AddString("EntityId", "1"));

                    source.Token.WaitHandle.WaitOne(5000);
                    source.Cancel();
                }
        }