예제 #1
0
        public async Task Concurrent_Appends_In_Different_Aggregates_Should_Succeed_Without_Concurrency_Conflicts()
        {
            const int numTasks = 10;
            int       executionDurationInSeconds = 60;

            List <ConcurrentTestContext> testContexts = new List <ConcurrentTestContext>();

            var tasks = Enumerable.Range(0, numTasks)
                        .Select(i =>
            {
                ConcurrentTestContext testContext =
                    new ConcurrentTestContext(_testData, _store);

                testContexts.Add(testContext);

                return(testContext.Run());
            }).ToArray();

            await Task.Delay(executionDurationInSeconds * 1000);

            foreach (var tctx in testContexts)
            {
                tctx.Stop();
            }

            Task.WaitAll(tasks);

            foreach (var tctx in testContexts)
            {
                Assert.AreEqual(0, tctx.ConcurrentErrorsDetected);

                var aggregate = await GetAggregate(tctx.AggregateId);

                Assert.AreEqual(tctx.AggregateVersion, aggregate.aggregate_event_seq);

                var createdEvents = await GetEvents(tctx.AggregateId);

                Assert.AreEqual(
                    tctx.AggregateVersion,
                    createdEvents.Count());
            }

            string message =
                @"Num of concurrent aggregates: {0}
                    Total Succeeded Appends: {1}";

            Assert.Pass(message,
                        testContexts.Count,
                        testContexts.Select(c => c.SucceededApends).Sum());
        }
예제 #2
0
        public async Task Concurrent_Appends_In_Same_Aggregate_Should_Succeed_And_Detect_Concurrency_Conflicts()
        {
            int numTasks = 10;
            int executionDurationInSeconds = 60;

            ConcurrentTestContext testContext = new ConcurrentTestContext(_testData, _store);

            var tasks = Enumerable.Range(0, numTasks)
                        .Select(i => testContext.Run())
                        .ToArray();

            await Task.Delay(executionDurationInSeconds * 1000);

            testContext.Stop();

            Task.WaitAll(tasks);

            var aggregate = await GetAggregate(testContext.AggregateId);

            Assert.AreEqual(testContext.AggregateVersion, aggregate.aggregate_event_seq);

            var createdEvents = await GetEvents(testContext.AggregateId);

            Assert.AreEqual(
                testContext.AggregateVersion,
                createdEvents.Count());

            string message =
                @"Aggregate Version: {0}
                  Succeeded Appends: {1}
                  Concurrency Errors Detected: {2}";

            Assert.Pass(message,
                        testContext.AggregateVersion,
                        testContext.SucceededApends,
                        testContext.ConcurrentErrorsDetected);
        }