Beispiel #1
0
        public async Task If_events_have_been_processed_then_the_correct_number_of_remaining_events_is_returned()
        {
            //arrange
            EventHandlerProgress progress = null;

            Events.Write(5);

            var eventsProcessed = 0;
            IUpdateProjectionWhen <IEvent> projector = null;

            projector = CreateProjector <IEvent>(e =>
            {
                if (eventsProcessed == 4)
                {
                    progress = CalculateProgressFor(projector);
                }
                eventsProcessed++;
            });

            //act
            await RunCatchupSingleBatch(projector);

            //assert
            progress.BatchRemainingEvents
            .Should()
            .Be(1);
        }
Beispiel #2
0
        public async Task If_events_have_been_processed_after_initial_catchup_then_the_remaining_time_is_estimated_correctly()
        {
            //arrange
            Events.Write(10);
            EventHandlerProgress progress            = null;
            var eventsProcessed                      = 0;
            IUpdateProjectionWhen <IEvent> projector = null;

            projector = CreateProjector <IEvent>(e =>
            {
                if (eventsProcessed == 15)
                {
                    progress = CalculateProgressFor(projector);
                }
                VirtualClock.Current.AdvanceBy(TimeSpan.FromSeconds(1));
                eventsProcessed++;
            });
            await RunCatchupSingleBatch(projector);

            //new set of events come in
            Events.Write(10);

            //act
            await RunCatchupSingleBatch(projector);

            progress.BatchTimeRemaining
            .Should()
            .Be(TimeSpan.FromSeconds(5));
        }
Beispiel #3
0
        public async Task During_initial_catchup_the_percent_completed_is_estimated_correctly()
        {
            //arrange
            Events.Write(10);
            var eventCount                = EventStoreDbContext().DisposeAfter(_ => _.Events.Count());
            var eventsProcessed           = 0;
            EventHandlerProgress progress = null;

            IUpdateProjectionWhen <IEvent> projector = null;

            projector = CreateProjector <IEvent>(e =>
            {
                if (eventsProcessed == eventCount / 10 + 1)
                {
                    VirtualClock.Current.AdvanceBy(10.Minutes());
                    progress = CalculateProgressFor(projector);
                }
                eventsProcessed++;
            });

            //act
            // catch up enough events to hit the if block in the projector
            var batchSize = eventCount / 8;

            await RunCatchupSingleBatch(projector,
                                        startAtEventId : 0,
                                        batchSize : batchSize);

            // assert
            progress.InitialCatchupPercentageCompleted
            .Should()
            .BeInRange(10, 11);
        }
Beispiel #4
0
        public async Task During_initial_catchup_the_remaining_time_is_estimated_correctly_across_multiple_batches()
        {
            //arrange
            Events.Write(20, randomEventTypes: true);
            var eventCount = EventStoreDbContext().DisposeAfter(_ => _.Events.Count());

            var eventsProcessed           = 0;
            EventHandlerProgress progress = null;

            IUpdateProjectionWhen <IEvent> projector = null;

            var numberOfEventsToProcessBeforeCalculating = eventCount / 100;

            projector = CreateProjector <IEvent>(e =>
            {
                eventsProcessed++;
                if (eventsProcessed == numberOfEventsToProcessBeforeCalculating)
                {
                    VirtualClock.Current.AdvanceBy(1.Minutes());
                    progress = CalculateProgressFor(projector);
                }
            });

            //act
            var batchSize = eventCount / 1000;

            for (var i = 0; i < 13; i++)
            {
                await RunCatchupSingleBatch(projector,
                                            startAtEventId : 0,
                                            batchSize : batchSize);
            }

            // assert
            var expectedTimeRemaining = TimeRemaining(
                1.Minutes(),
                eventsProcessed: numberOfEventsToProcessBeforeCalculating,
                eventsRemaining: eventCount - numberOfEventsToProcessBeforeCalculating);

            Console.WriteLine(new { eventCount, batchSize, eventsProcessed, numberOfEventsToProcessBeforeCalculating, expectedTimeRemaining });

            progress.InitialCatchupTimeRemaining
            .Should()
            .BeCloseTo(expectedTimeRemaining,
                       precision: (int)6.Minutes().TotalMilliseconds);
        }
Beispiel #5
0
        public override List <Object> solution()
        {
            m_returnObjects = new List <object>();;
            Progress progressForm = new Progress();

            progressForm.Cancel += new Progress.EventHandlerCancel(onFormCancel);
            Started             += new EventHandlerStart(progressForm.onStarted);
            Progress            += new EventHandlerProgress(progressForm.onProgress);
            Finished            += new EventHandlerFinish(progressForm.onFinished);

            m_worker = new Thread(new ThreadStart(solutionThread));

            progressForm.Shown += new EventHandler(onFormShow);
            progressForm.ShowDialog();

            m_worker.Join();

            return(m_returnObjects);
        }
Beispiel #6
0
        public override bool make(List <Object> objects)
        {
            m_objects = objects;
            Progress progressForm = new Progress();

            progressForm.Cancel += new Progress.EventHandlerCancel(onFormCancel);

            Started   += new EventHandlerStart(progressForm.onStarted);
            Progress  += new EventHandlerProgress(progressForm.onProgress);
            ProgressA += new EventHandlerProgressA(progressForm.onProgressA);
            ProgressB += new EventHandlerProgressB(progressForm.onProgressB);
            Finished  += new EventHandlerFinish(progressForm.onFinished);
            m_worker   = new System.Threading.Thread(new System.Threading.ThreadStart(worker));

            progressForm.Shown += new EventHandler(onDialogShown);
            progressForm.ShowDialog();

            m_worker.Join();
            progressForm.Close();
            return(true);
        }
Beispiel #7
0
        public override List <Object> opened(bool noSavedOnly)
        {
            m_returnObjects = new List <object>();;
            Progress progressForm = new Progress();

            progressForm.Cancel += new Progress.EventHandlerCancel(onFormCancel);
            Started             += new EventHandlerStart(progressForm.onStarted);
            Progress            += new EventHandlerProgress(progressForm.onProgress);
            ProgressA           += new EventHandlerProgressA(progressForm.onProgressA);
            Finished            += new EventHandlerFinish(progressForm.onFinished);

            m_worker = new Thread(new ParameterizedThreadStart(openedThread));

            progressForm.Tag    = noSavedOnly;
            progressForm.Shown += new EventHandler(onFormShow);
            progressForm.ShowDialog();

            m_worker.Join();

            return(m_returnObjects);
        }