Example #1
0
        public async Task CanMeasureTimeSpentInViewManagers()
        {
            var waitHandle = new ViewManagerWaitHandle();
            var myProfiler = new MyProfiler();
            var view1      = new InMemoryViewManager <SlowView>();
            var view2      = new InMemoryViewManager <QuickView>();

            var commandProcessor = CommandProcessor.With()
                                   .Logging(l => l.UseConsole(minLevel: Logger.Level.Debug))
                                   .EventStore(e => e.UseInMemoryEventStore())
                                   .EventDispatcher(e =>
            {
                e.UseViewManagerEventDispatcher(view1, view2)
                .WithWaitHandle(waitHandle)
                .WithProfiler(myProfiler);
            })
                                   .Create();

            using (commandProcessor)
            {
                var lastResult = Enumerable.Range(0, 10)
                                 .Select(i => commandProcessor.ProcessCommand(new Commando("someId")))
                                 .Last();

                await waitHandle.WaitForAll(lastResult, TimeSpan.FromMinutes(1));
            }

            var accumulatedTimes = myProfiler.GetAccumulatedTimes();

            Assert.That(accumulatedTimes.ContainsKey(view1), "Could not find {0} among the keys!", view1);
            Assert.That(accumulatedTimes.ContainsKey(view2), "Could not find {0} among the keys!", view2);

            Assert.That(accumulatedTimes[view1], Is.GreaterThan(TimeSpan.FromSeconds(1)));
            Assert.That(accumulatedTimes[view2], Is.GreaterThan(TimeSpan.FromSeconds(.1)).And.LessThan(TimeSpan.FromSeconds(0.15)));
        }
        public void CanDoTheThing(int numberOfCommandsToProcess)
        {
            var database = MongoHelper.InitializeTestDatabase();
            var profiler = new MyProfiler();

            using (var timer = new Timer(1000))
            {
                var commandCounter = 0;

                timer.Elapsed += (o, ea) =>
                {
                    var numberOfCommands = Interlocked.Exchange(ref commandCounter, 0);
                    Console.WriteLine("{0} commands/s", numberOfCommands);
                };

                timer.Start();

                //Brett
                var commandProcessor = RegisterForDisposal(base.CreateCommandProcessor(config => config
                                                                                       .Logging(l => l.UseConsole(minLevel: Logger.Level.Warn))
                                                                                       .EventStore(e => e.UseMongoDb(database, "Events"))
                                                                                       .AggregateRootRepository(e => e.EnableInMemorySnapshotCaching(1000)) // try commenting this line in/out
                                                                                       .EventDispatcher(e => e.UseViewManagerEventDispatcher())
                                                                                       .Options(o => { o.AddProfiler(profiler); o.SetMaxRetries(0); })
                                                                                       ));

                //orig
                //var commandProcessor = RegisterForDisposal(
                //    CommandProcessor.With()
                //        .Logging(l => l.UseConsole(minLevel: Logger.Level.Warn))
                //        .EventStore(e => e.UseMongoDb(database, "Events"))

                //        // try commenting this line in/out
                //        .AggregateRootRepository(e => e.EnableInMemorySnapshotCaching(1000))

                //        .EventDispatcher(e => e.UseViewManagerEventDispatcher())
                //        .Options(o =>
                //        {
                //            o.AddProfiler(profiler);
                //            o.SetMaxRetries(0);
                //        })
                //        .Create()
                //    );

                numberOfCommandsToProcess.Times(() =>
                {
                    commandProcessor.ProcessCommand(new MakeStuffHappen("id"));
                    Interlocked.Increment(ref commandCounter);
                });

                var repo         = new DefaultAggregateRootRepository(new MongoDbEventStore(database, "Events"), new JsonDomainEventSerializer(), new DefaultDomainTypeNameMapper());
                var currentState = (Root)repo.Get <Root>("id", new ConsoleOutUnitOfWork(repo));

                Assert.That(currentState.HowManyThingsHaveHappened, Is.EqualTo(numberOfCommandsToProcess));
            }

            Console.WriteLine(profiler);
        }