コード例 #1
0
ファイル: EventSequenceTest.cs プロジェクト: ulswww/enode
        public void sequence_domain_event_process_test()
        {
            var processor = ObjectContainer.Resolve<IMessageProcessor<ProcessingDomainEventStreamMessage, DomainEventStreamMessage, bool>>();

            var note = new TestAggregate(ObjectId.GenerateNewStringId(), "initial title");
            var aggregate = note as IAggregateRoot;
            var message1 = CreateMessage(aggregate);

            aggregate.AcceptChanges(1);
            note.ChangeTitle("title1");
            var message2 = CreateMessage(aggregate);

            aggregate.AcceptChanges(2);
            note.ChangeTitle("title2");
            var message3 = CreateMessage(aggregate);

            processor.Process(new ProcessingDomainEventStreamMessage(message1, new DomainEventStreamProcessContext(message1)));
            processor.Process(new ProcessingDomainEventStreamMessage(message3, new DomainEventStreamProcessContext(message3)));
            processor.Process(new ProcessingDomainEventStreamMessage(message2, new DomainEventStreamProcessContext(message2)));

            _waitHandle.WaitOne();

            for (var i = 0; i < 3; i++)
            {
                Assert.AreEqual(i + 1, _versionList[i]);
            }
        }
コード例 #2
0
        public void sequence_domain_event_process_test()
        {
            var processor = ObjectContainer.Resolve <IMessageProcessor <ProcessingDomainEventStreamMessage, DomainEventStreamMessage> >();

            var note      = new TestAggregate(ObjectId.GenerateNewStringId(), "initial title");
            var aggregate = note as IAggregateRoot;
            var message1  = CreateMessage(aggregate);

            aggregate.AcceptChanges(1);
            note.ChangeTitle("title1");
            var message2 = CreateMessage(aggregate);

            aggregate.AcceptChanges(2);
            note.ChangeTitle("title2");
            var message3 = CreateMessage(aggregate);

            var waitHandle  = new ManualResetEvent(false);
            var versionList = new List <int>();

            processor.Process(new ProcessingDomainEventStreamMessage(message1, new DomainEventStreamProcessContext(message1, waitHandle, versionList)));
            processor.Process(new ProcessingDomainEventStreamMessage(message3, new DomainEventStreamProcessContext(message3, waitHandle, versionList)));
            processor.Process(new ProcessingDomainEventStreamMessage(message2, new DomainEventStreamProcessContext(message2, waitHandle, versionList)));

            waitHandle.WaitOne();

            for (var i = 0; i < 3; i++)
            {
                Assert.AreEqual(i + 1, versionList[i]);
            }
        }
コード例 #3
0
        public void sequence_domain_event_process_test2()
        {
            var processor = ObjectContainer.Resolve <IProcessingEventProcessor>();

            var note      = new TestAggregate(ObjectId.GenerateNewStringId(), "initial title");
            var aggregate = note as IAggregateRoot;
            var message1  = CreateMessage(aggregate);

            aggregate.AcceptChanges();
            note.ChangeTitle("title1");
            var message2 = CreateMessage(aggregate);

            aggregate.AcceptChanges();
            note.ChangeTitle("title2");
            var message3 = CreateMessage(aggregate);

            var waitHandle  = new ManualResetEvent(false);
            var versionList = new List <int>();

            //模拟从publishedVersionStore中取到的publishedVersion不是最新的场景
            processor.Process(new ProcessingEvent(message1, new DomainEventStreamProcessContext(message1, waitHandle, versionList)));
            processor.Process(new ProcessingEvent(message3, new DomainEventStreamProcessContext(message3, waitHandle, versionList)));

            //等待5秒后更新publishedVersion为2
            Thread.Sleep(5000);
            var publishedVersionStore = ObjectContainer.Resolve <IPublishedVersionStore>();

            publishedVersionStore.UpdatePublishedVersionAsync(processor.Name, typeof(TestAggregate).FullName, aggregate.UniqueId, 2).Wait();

            //等待ENode内部自动检测到最新的publishedVersion,并继续处理mailbox waitingList中的version=3的事件
            waitHandle.WaitOne();

            Assert.AreEqual(1, versionList[0]);
            Assert.AreEqual(3, versionList[1]);

            //再等待3秒,等待ENode内部异步打印Removed problem aggregate的日志
            Thread.Sleep(3000);
        }