public void BeginActivity()
        {
            var es       = new TestEventStream();
            var activity = ActivityFactory.NewActivity <TestActivity>(new EventStreamMediator(es));
            EventHandler <ActivityEventArgs> handler = null;
            AutoResetEvent rst = new AutoResetEvent(false);

            try
            {
                handler = (sender, e) => {
                    Assert.AreEqual(activity.ActivityName, e.Arguments["activityName"], "activityName");
                    Assert.AreEqual(activity.ActivityId, e.Arguments["activityInstance"], "activityInstance");
                    rst.Set();
                };

                es.BeginActivityCalled += handler;

                activity.BeginActivity();

                Assert.IsTrue(rst.WaitOne(1000), "Begin Activity failed to complete");
            }
            finally
            {
                if (handler != null)
                {
                    es.BeginActivityCalled -= handler;
                }
                activity.Dispose();
            }
        }
Пример #2
0
        public void Clear()
        {
            var es = new TestEventStream();

            EventHandler <ActivityEventArgs> handler = null;
            AutoResetEvent rst = new AutoResetEvent(false);

            try
            {
                handler = (sender, e) => {
                    rst.Set();
                };

                es.ClearCalled += handler;

                var mediator = new EventStreamMediator(es);
                mediator.Clear();

                Assert.IsTrue(rst.WaitOne(1000), "Clear() did not complete");
            }
            finally
            {
                if (handler != null)
                {
                    es.ClearCalled -= handler;
                }
            }
        }
        public void EnableContinuationGeneratedId()
        {
            var es         = new TestEventStream();
            var activityId = Guid.NewGuid().ToString();
            var activity   = ActivityFactory.NewActivity <TestActivity>(new EventStreamMediator(es), activityId);
            EventHandler <ActivityEventArgs> handler = null;
            AutoResetEvent rst = new AutoResetEvent(false);

            try
            {
                handler = (sender, e) => {
                    Assert.AreEqual(activity.ActivityName, e.Arguments["activityName"], "activityName");
                    Assert.AreEqual(activity.ActivityId, e.Arguments["activityInstance"], "activityInstance");

                    Assert.AreEqual("CONT_" + activityId, e.Arguments["continuationToken"], "continuationToken");

                    rst.Set();
                };

                es.EnableContinuationCalled += handler;

                activity.EnableContinuation();
                Assert.IsTrue(rst.WaitOne(1000), "End Activity failed to complete");
            }
            finally
            {
                if (handler != null)
                {
                    es.EnableContinuationCalled -= handler;
                }
                activity.Dispose();
            }
        }
        public void CommitActivity()
        {
            var es       = new TestEventStream();
            var activity = ActivityFactory.NewActivity <TestActivity>(new EventStreamMediator(es));
            EventHandler <ActivityEventArgs> handler = null;
            AutoResetEvent rst = new AutoResetEvent(false);

            try
            {
                activity.ActivityCustomDate1     = DateTime.Now;
                activity.ActivityCustomInt1      = TestHelper.Rnd.Next();
                activity.ActivityCustomString1   = Guid.NewGuid().ToString();
                activity.ActivityFieldNameChange = TestHelper.Rnd.Next();
                activity.ActivityValueType       = "foo";

                handler = (sender, e) => {
                    Assert.AreEqual(activity.ActivityName, e.Arguments["activityName"], "activityName");
                    Assert.AreEqual(activity.ActivityId, e.Arguments["activityInstance"], "activityInstance");

                    var data = ((object[])e.Arguments["data"]).BamDataToDictionary();

                    Assert.AreEqual(activity.ActivityCustomDate1, data["ActivityCustomDate1"]);
                    Assert.AreEqual(activity.ActivityCustomInt1, data["ActivityCustomInt1"]);
                    Assert.AreEqual(activity.ActivityCustomString1, data["ActivityCustomString1"]);
                    Assert.AreEqual(activity.ActivityFieldNameChange, data["Renamed Field"]);
                    Assert.AreEqual(null, data["ActivityNullableDate"]);

                    rst.Set();
                };

                es.UpdateActivityCalled += handler;

                activity.CommitActivity();
                Assert.IsTrue(rst.WaitOne(1000), "Commit Activity failed to complete");
            }
            finally
            {
                if (handler != null)
                {
                    es.UpdateActivityCalled -= handler;
                }
                activity.Dispose();
            }
        }
        public void AddCustomReference2()
        {
            var es       = new TestEventStream();
            var activity = ActivityFactory.NewActivity <TestActivity>(new EventStreamMediator(es));
            EventHandler <ActivityEventArgs> handler = null;
            AutoResetEvent rst = new AutoResetEvent(false);

            try
            {
                string referenceType = "foo", referenceName = "bar", referenceData = "blee", longReferenceData = "fnar";

                handler = (sender, e) => {
                    Assert.AreEqual(activity.ActivityName, e.Arguments["activityName"], "activityName");
                    Assert.AreEqual(activity.ActivityId, e.Arguments["activityId"], "activityInstance");

                    Assert.AreEqual(referenceType, e.Arguments["referenceType"], "referenceType");
                    Assert.AreEqual(referenceName, e.Arguments["referenceName"], "referenceName");
                    Assert.AreEqual(referenceData, e.Arguments["referenceData"], "referenceData");
                    Assert.AreEqual(longReferenceData, e.Arguments["longreferenceData"], "longreferenceData");

                    rst.Set();
                };

                es.AddReferenceCalled += handler;

                activity.AddCustomReference(referenceType, referenceName, referenceData, longReferenceData);
                Assert.IsTrue(rst.WaitOne(1000), "Add Reference failed to complete");
            }
            finally
            {
                if (handler != null)
                {
                    es.AddReferenceCalled -= handler;
                }
                activity.Dispose();
            }
        }
Пример #6
0
        static void AddAggregateEventTest()
        {
            ECommonConfiguration
            .Create()
            .UseAutofac()
            .RegisterCommonComponents()
            .UseLog4Net()
            .RegisterUnhandledExceptionHandler()
            .RegisterEStoreComponents()
            .BuildContainer();

            var chunkFileStoreRootPath = @"d:\event-store";
            var eventDataChunkDataSize = 256 * 1024 * 1024;
            var indexChunkDataSize     = 256 * 1024 * 1024;
            var chunkFlushInterval     = 100;
            var chunkCacheMaxCount     = 15;
            var chunkCacheMinCount     = 15;
            var maxDataLogRecordSize   = 5 * 1024 * 1024;
            var maxIndexLogRecordSize  = 5 * 1024 * 1024;
            var chunkWriteBuffer       = 128 * 1024;
            var chunkReadBuffer        = 128 * 1024;
            var syncFlush           = false;
            var flushOption         = FlushOption.FlushToOS;
            var enableCache         = true;
            var preCacheChunkCount  = 10;
            var chunkLocalCacheSize = 300000;

            var eventDataChunkConfig = new ChunkManagerConfig(
                Path.Combine(chunkFileStoreRootPath, "event-data-chunks"),
                new DefaultFileNamingStrategy("event-data-chunk-"),
                eventDataChunkDataSize,
                0,
                0,
                chunkFlushInterval,
                enableCache,
                syncFlush,
                flushOption,
                Environment.ProcessorCount * 8,
                maxDataLogRecordSize,
                chunkWriteBuffer,
                chunkReadBuffer,
                chunkCacheMaxCount,
                chunkCacheMinCount,
                preCacheChunkCount,
                5,
                chunkLocalCacheSize,
                true);
            var eventIndexChunkConfig = new ChunkManagerConfig(
                Path.Combine(chunkFileStoreRootPath, "event-index-chunks"),
                new DefaultFileNamingStrategy("event-index-chunk-"),
                indexChunkDataSize,
                0,
                0,
                chunkFlushInterval,
                enableCache,
                syncFlush,
                flushOption,
                Environment.ProcessorCount * 8,
                maxIndexLogRecordSize,
                chunkWriteBuffer,
                chunkReadBuffer,
                chunkCacheMaxCount,
                chunkCacheMinCount,
                preCacheChunkCount,
                5,
                chunkLocalCacheSize,
                true);
            var commandIndexChunkConfig = new ChunkManagerConfig(
                Path.Combine(chunkFileStoreRootPath, "command-index-chunks"),
                new DefaultFileNamingStrategy("command-index-chunk-"),
                indexChunkDataSize,
                0,
                0,
                chunkFlushInterval,
                enableCache,
                syncFlush,
                flushOption,
                Environment.ProcessorCount * 8,
                maxIndexLogRecordSize,
                chunkWriteBuffer,
                chunkReadBuffer,
                chunkCacheMaxCount,
                chunkCacheMinCount,
                preCacheChunkCount,
                5,
                chunkLocalCacheSize,
                true);

            var eventStore = ObjectContainer.Resolve <IEventStore>() as DefaultEventStore;

            eventStore.Init(eventDataChunkConfig, eventIndexChunkConfig, commandIndexChunkConfig);
            eventStore.Start();

            var eventStream = new TestEventStream
            {
                AggregateRootId   = ObjectId.GenerateNewStringId(),
                AggregateRootType = "Note",
                Events            = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
                Timestamp         = DateTime.UtcNow.Ticks
            };

            var totalCount         = 10000000;
            var count              = 0;
            var performanceService = ObjectContainer.Resolve <IPerformanceService>();

            performanceService.Initialize("WriteChunk").Start();

            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    try
                    {
                        var current = Interlocked.Increment(ref count);
                        if (current > totalCount)
                        {
                            break;
                        }
                        var start             = DateTime.Now;
                        eventStream.Version   = current;
                        eventStream.CommandId = ObjectId.GenerateNewStringId();
                        eventStream.CommandCreateTimestamp = DateTime.Now.Ticks;
                        eventStore.AppendEventStream(eventStream);
                        performanceService.IncrementKeyCount("default", (DateTime.Now - start).TotalMilliseconds);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            });

            Console.ReadLine();
            eventStore.Stop();
        }
Пример #7
0
        static void AddAggregateEventTest()
        {
            ECommonConfiguration
            .Create()
            .UseAutofac()
            .RegisterCommonComponents()
            .UseLog4Net()
            .RegisterUnhandledExceptionHandler()
            .RegisterEStoreComponents()
            .BuildContainer();

            var eventStore = InitEventStore();

            var totalCount         = 100000000;
            var index              = 0;
            var performanceService = ObjectContainer.Resolve <IPerformanceService>();

            performanceService.Initialize("WriteChunk").Start();
            var aggregateRootId   = ObjectId.GenerateNewStringId();
            var aggregateRootType = "Note";
            var events            = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";

            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    try
                    {
                        var start           = DateTime.Now;
                        var currentVersion  = 0;
                        var eventStreamList = new List <IEventStream>();
                        for (var i = 0; i < 5; i++)
                        {
                            currentVersion  = Interlocked.Increment(ref index);
                            var eventStream = new TestEventStream
                            {
                                AggregateRootId        = aggregateRootId,
                                AggregateRootType      = aggregateRootType,
                                Events                 = events,
                                Timestamp              = DateTime.UtcNow.Ticks,
                                Version                = currentVersion,
                                CommandId              = ObjectId.GenerateNewStringId(),
                                CommandCreateTimestamp = DateTime.Now.Ticks
                            };
                            eventStreamList.Add(eventStream);
                            performanceService.IncrementKeyCount("default", (DateTime.Now - start).TotalMilliseconds);
                        }
                        eventStore.AppendEventStreams(eventStreamList);
                        if (index > totalCount)
                        {
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            });

            Console.ReadLine();
            eventStore.Stop();
        }