Пример #1
0
        private Task RunIteration()
        {
            var countItem = CreateCountItem();
            var sumCheckForBankAccount0 = CreateSumCheckForBankAccount0();

            var writeTask = WriteData();

            var expectedAllEventsCount  = (Streams * EventsPerStream + Streams).ToString();
            var expectedEventsPerStream = EventsPerStream.ToString();

            var store = GetConnection();

            var successTask = Task.Factory.StartNew <bool>(() =>
            {
                var success   = false;
                var stopWatch = new Stopwatch();
                while (stopWatch.Elapsed < TimeSpan.FromMilliseconds(10 * (Streams * EventsPerStream + Streams)))
                {
                    if (writeTask.IsFaulted)
                    {
                        throw new ApplicationException("Failed to write data");
                    }

                    if (writeTask.IsCompleted && !stopWatch.IsRunning)
                    {
                        stopWatch.Start();
                    }

                    success = CheckProjectionState(store, countItem, "count", x => x == expectedAllEventsCount) &&
                              CheckProjectionState(store, sumCheckForBankAccount0, "success", x => x == expectedEventsPerStream);

                    if (success)
                    {
                        break;
                    }

                    Thread.Sleep(500);
                }
                return(success);
            });

            return(Task.Factory.ContinueWhenAll(new [] { writeTask, successTask }, tasks => { Log.Info("Iteration {0} tasks completed", GetIterationCode()); Task.WaitAll(tasks); Log.Info("Iteration {0} successfull", GetIterationCode()); }));
        }
Пример #2
0
        private Task RunIteration()
        {
            var nodeProcessId = StartNode();


            var sumCheckForBankAccount0 = CreateSumCheckForBankAccount0();

            var writeTask = WriteData();

            var expectedEventsPerStream = EventsPerStream.ToString();

            var successTask = Task.Factory.StartNew <bool>(() =>
            {
                var store = GetConnection();

                var success   = true;
                var stopWatch = new Stopwatch();

                var wasLessLastTime = false;
                while (stopWatch.Elapsed < TimeSpan.FromMilliseconds(10 * (Streams * EventsPerStream + Streams)))
                {
                    if (!wasLessLastTime)
                    {
                        KillNode(nodeProcessId);
                        nodeProcessId = StartNode();
                    }

                    if (writeTask.IsFaulted)
                    {
                        throw new ApplicationException("Failed to write data");
                    }

                    if (writeTask.IsCompleted && !stopWatch.IsRunning)
                    {
                        stopWatch.Start();
                    }

                    var count1 = GetProjectionStateValue(store, sumCheckForBankAccount0, "success", int.Parse, -1);
                    for (var i = 0; i < 5; ++i)
                    {
                        Thread.Sleep(TimeSpan.FromSeconds(1));
                        var count2 = GetProjectionStateValue(store, sumCheckForBankAccount0, "success", int.Parse, -1);

                        if (count1 > count2)
                        {
                            if (wasLessLastTime)
                            {
                                success = false;
                                break;
                            }
                            wasLessLastTime = true;
                        }

                        count1 = count2;
                    }

                    if (!success)
                    {
                        break;
                    }

                    if (CheckProjectionState(store, sumCheckForBankAccount0, "success", x => x == expectedEventsPerStream))
                    {
                        break;
                    }
                }

                KillNode(nodeProcessId);

                return(success);
            });

            return(Task.Factory.ContinueWhenAll(new[] { writeTask, successTask }, tasks => { Log.Info("Iteration {0} tasks completed", GetIterationCode()); Task.WaitAll(tasks); Log.Info("Iteration {0} successfull", GetIterationCode()); }));
        }
Пример #3
0
        protected override void RunInternal()
        {
            var success = true;

            var nodeProcessId = StartNode();

            var countProjections = new List <string>();
            var bankProjections  = new List <string>();

            while (GetIterationCode() < Streams / 3)
            {
                SetNextIterationCode();

                countProjections.Add(CreateCountItem());
                bankProjections.Add(CreateSumCheckForBankAccount0());

                Log.Info("Created {0} and {1}", bankProjections[bankProjections.Count - 1],
                         countProjections[countProjections.Count - 1]);
            }

            KillNode(nodeProcessId);
            nodeProcessId = StartNode();

            var writeTask = WriteData();

            writeTask.Wait();

            KillNode(nodeProcessId);
            nodeProcessId = StartNode();

            int count = 10;

            while (count > 0)
            {
                Log.Info("Stop and start projection, remaining iterations {0}, waiting for data to be written.", count);

                var t1 = StartOrStopProjection(countProjections, false);
                var t2 = StartOrStopProjection(bankProjections, false);

                Task.WaitAll(new[] { t1, t2 });
                Thread.Sleep(TimeSpan.FromSeconds(10));

                var t3 = StartOrStopProjection(countProjections, true);
                var t4 = StartOrStopProjection(bankProjections, true);

                Task.WaitAll(new[] { t3, t4 });
                var sleepTimeSeconds = 60 + Streams * EventsPerStream / 1000.0;
                Log.Info("Sleep 1 for {0} seconds", sleepTimeSeconds);
                Thread.Sleep(TimeSpan.FromSeconds(sleepTimeSeconds));

                if (writeTask.IsCompleted)
                {
                    count -= 1;
                }

                if (writeTask.IsFaulted)
                {
                    throw new ApplicationException("Failed to write data", writeTask.Exception);
                }

                success = CheckProjectionState(GetConnection(),
                                               bankProjections[bankProjections.Count - 1],
                                               "success",
                                               x => x == EventsPerStream.ToString());
                if (success)
                {
                    break;
                }
            }

            count   = 10;
            success = false;
            while (!success && count > 0)
            {
                Log.Info("Wait until projections are computed, remaining iterations {0}", count);
                KillNode(nodeProcessId);
                nodeProcessId = StartNode();

                var sleepTimeSeconds = (Streams * EventsPerStream) / 50;
                Log.Info("Sleep 2 for {0} seconds", sleepTimeSeconds);
                Thread.Sleep(TimeSpan.FromSeconds(sleepTimeSeconds));

                success = CheckProjectionState(GetConnection(),
                                               bankProjections[bankProjections.Count - 1],
                                               "success",
                                               x => x == EventsPerStream.ToString());
                count -= 1;
            }

            if (!success)
            {
                throw new ApplicationException("Last bank projection failed");
            }
        }
        protected override void RunInternal()
        {
            var nodeProcessId = StartNode();

            var countItem = CreateCountItem();
            var sumCheckForBankAccount0 = CreateSumCheckForBankAccount0();

            var writeTask = WriteData();

            var success = false;
            var expectedAllEventsCount  = (Streams * EventsPerStream + Streams).ToString();
            var expectedEventsPerStream = EventsPerStream.ToString();

            var isWatchStarted = false;
            var store          = GetConnection();

            var stopWatch = new Stopwatch();

            while (stopWatch.Elapsed < TimeSpan.FromMilliseconds(1000 + 5 * Streams * EventsPerStream))
            {
                if (writeTask.IsFaulted)
                {
                    throw new ApplicationException("Failed to write data");
                }

                if (writeTask.IsCompleted && !stopWatch.IsRunning)
                {
                    stopWatch.Start();
                    isWatchStarted = true;
                }

                success = CheckProjectionState(store, countItem, "count", x => x == expectedAllEventsCount) &&
                          CheckProjectionState(store, sumCheckForBankAccount0, "success", x => x == expectedEventsPerStream);

                if (success)
                {
                    break;
                }

                if (isWatchStarted)
                {
                    stopWatch.Stop();
                }

                Thread.Sleep(IterationSleepInterval);
                KillNode(nodeProcessId);
                nodeProcessId = StartNode();

                if (isWatchStarted)
                {
                    stopWatch.Start();
                }
            }

            writeTask.Wait();

            KillNode(nodeProcessId);

            if (!success)
            {
                throw new ApplicationException(string.Format("Projections did not complete with expected result in time"));
            }
        }