Esempio n. 1
0
        public async Task configured_stop_all()
        {
            var projection1 = new SometimesFailingProjection("one");

            projection1.StartThrowingExceptionsAtSequence(10, new DivideByZeroException());

            var projection2 = new SometimesFailingProjection("two");

            StoreOptions(opts =>
            {
                opts.Projections.Add(projection1, ProjectionLifecycle.Async);
                opts.Projections.Add(projection2, ProjectionLifecycle.Async);
                opts.Projections.OnException <ApplyEventException>().AndInner <DivideByZeroException>().StopAll();
            });

            using var node = await StartDaemon();

            NumberOfStreams = 10;
            await PublishSingleThreaded();

            await node.Tracker.WaitForHighWaterMark(NumberOfEvents);

            await node.WaitForShardToStop("two:All");

            await node.WaitForShardToStop("one:All");


            node.StatusFor("one:All").ShouldBe(AgentStatus.Stopped);
            node.StatusFor("two:All").ShouldBe(AgentStatus.Stopped);
        }
Esempio n. 2
0
        public async Task projections_are_stopped_with_unhandled_exceptions()
        {
            var projection1 = new SometimesFailingProjection("one");

            projection1.StartThrowingExceptionsAtSequence(10, new ArithmeticException(), new BadImageFormatException());

            var projection2 = new SometimesFailingProjection("two");

            StoreOptions(opts =>
            {
                opts.Projections.Add(projection1, ProjectionLifecycle.Async);
                opts.Projections.Add(projection2, ProjectionLifecycle.Async);
                opts.Projections.OnException <ArithmeticException>()
                .RetryLater(50.Milliseconds(), 50.Milliseconds());
            });

            using var node = await StartDaemon();

            NumberOfStreams = 10;
            await PublishSingleThreaded();

            await node.Tracker.WaitForHighWaterMark(NumberOfEvents);

            await node.WaitForShardToStop("one:All");

            node.StatusFor("one:All").ShouldBe(AgentStatus.Stopped);
            node.StatusFor("two:All").ShouldBe(AgentStatus.Running);
        }
Esempio n. 3
0
        public async Task projections_can_continue_with_handled_exceptions_after_a_pause()
        {
            var projection1 = new SometimesFailingProjection("one");

            projection1.StartThrowingExceptionsAtSequence(10, new ArithmeticException(), new ArithmeticException(), new ArithmeticException());

            StoreOptions(opts =>
            {
                opts.Events.Projections.Add(projection1, ProjectionLifecycle.Async);
                opts.Events.Daemon.OnException <ArithmeticException>()
                .RetryLater(50.Milliseconds(), 50.Milliseconds()).Then.Pause(50.Milliseconds());
            });

            using var node = await StartDaemon();

            var waiter = node.Tracker.WaitForShardCondition(
                state => state.ShardName.EqualsIgnoreCase("one:All") && state.Action == ShardAction.Paused,
                "one:All is Paused", 1.Minutes());

            NumberOfStreams = 10;
            await PublishSingleThreaded();

            await waiter;
            await node.Tracker.WaitForShardState("one:All", NumberOfEvents);

            node.StatusFor("one:All").ShouldBe(AgentStatus.Running);
        }
Esempio n. 4
0
        [Fact] // Rerun this test if it fails. I think that thread exhaustion nails this sometimes
        public async Task projections_can_continue_with_handled_exceptions()
        {
            var projection1 = new SometimesFailingProjection("one");

            projection1.StartThrowingExceptionsAtSequence(10, new ArithmeticException(), new ArithmeticException());

            StoreOptions(opts =>
            {
                opts.Projections.Add(projection1, ProjectionLifecycle.Async);
                opts.Projections.OnException <ArithmeticException>()
                .RetryLater(50.Milliseconds(), 50.Milliseconds());
            });

            using var node = await StartDaemon();

            NumberOfStreams = 10;
            await PublishSingleThreaded();

            await node.Tracker.WaitForHighWaterMark(NumberOfEvents);

            var i = 0;

            while (i < 10)
            {
                if (node.StatusFor("one:All") == AgentStatus.Running)
                {
                    break;
                }
                await Task.Delay(1.Seconds());

                i++;
            }
            node.StatusFor("one:All").ShouldBe(AgentStatus.Running);
        }
Esempio n. 5
0
        public async Task projections_stops_on_too_many_tries()
        {
            var projection1 = new SometimesFailingProjection("one");

            projection1.StartThrowingExceptionsAtSequence(10, new ArithmeticException(), new ArithmeticException(), new ArithmeticException(), new ArithmeticException());

            StoreOptions(opts =>
            {
                opts.Projections.Add(projection1, ProjectionLifecycle.Async);
                opts.Projections.OnException <ArithmeticException>()
                .RetryLater(50.Milliseconds(), 50.Milliseconds());
            });

            using var node = await StartDaemon();

            NumberOfStreams = 10;
            await PublishMultiThreaded(3);

            await node.WaitForShardToStop("one:All");

            node.StatusFor("one:All").ShouldBe(AgentStatus.Stopped);
        }
Esempio n. 6
0
        public async Task projections_can_continue_with_handled_exceptions_after_a_pause()
        {
            // WARNING -- this test doesn't consistently pass if it's running with other tests,
            // but should succeed running by itself.

            var projection1 = new SometimesFailingProjection("one");

            projection1.StartThrowingExceptionsAtSequence(10, new ArithmeticException(), new ArithmeticException(), new ArithmeticException());

            StoreOptions(opts =>
            {
                opts.Projections.Add(projection1, ProjectionLifecycle.Async);
                opts.Projections
                .OnException <ApplyEventException>()
                .AndInner <ArithmeticException>()
                .RetryLater(50.Milliseconds(), 50.Milliseconds())
                .Then.Pause(50.Milliseconds());
            });

            using var node = await StartDaemon();

            var waiter = node.Tracker.WaitForShardCondition(
                state => state.ShardName.EqualsIgnoreCase("one:All") && state.Action == ShardAction.Paused,
                "one:All is Paused", 5.Minutes());

            NumberOfStreams = 10;
            await PublishSingleThreaded();

            await waiter;
            await node.Tracker.WaitForShardState("one:All", NumberOfEvents);

            if (node.StatusFor("one:All") != AgentStatus.Running)
            {
                await Task.Delay(250.Milliseconds());

                node.StatusFor("one:All").ShouldBe(AgentStatus.Running);
            }
        }