Exemplo n.º 1
0
        public async Task conditional_deletes_through_lambda_conditions_on_aggregate()
        {
            var shortTrip    = new TripStream().TravelIsUnder(200);
            var longTrip     = new TripStream().TravelIsOver(2000);
            var initialCount = shortTrip.Events.Count + longTrip.Events.Count;

            _output.WriteLine($"Initially publishing {initialCount} events");

            var projection = new TestingSupport.TripProjection();

            projection.ProjectionName = "Trip";

            StoreOptions(x => x.Projections.Add(projection, ProjectionLifecycle.Async), true);

            var agent = await StartDaemon();



            var waiter1 = agent.Tracker.WaitForShardState("Trip:All", initialCount);

            using (var session = theStore.LightweightSession())
            {
                session.Events.Append(shortTrip.StreamId, shortTrip.Events.ToArray());
                session.Events.Append(longTrip.StreamId, longTrip.Events.ToArray());
                await session.SaveChangesAsync();
            }

            await waiter1;

            // This should not trigger a delete
            theSession.Events.Append(shortTrip.StreamId, new VacationOver());

            // This should trigger a delete
            theSession.Events.Append(longTrip.StreamId, new VacationOver());

            await theSession.SaveChangesAsync();

            var totalNumberOfEvents = initialCount + 2;
            var waiter2             = agent.Tracker.WaitForShardState(new ShardState("Trip:All", totalNumberOfEvents), 30.Seconds());

            await waiter2;



            using var query = theStore.QuerySession();

            (await query.LoadAsync <Trip>(shortTrip.StreamId)).ShouldNotBeNull();
            (await query.LoadAsync <Trip>(longTrip.StreamId)).ShouldBeNull();
        }
Exemplo n.º 2
0
        public async Task conditional_deletes_through_lambda_conditions_on_event_only()
        {
            NumberOfStreams = 2;

            Logger.LogDebug("The expected number of events is {NumberOfEvents}", NumberOfEvents);

            var projection = new TestingSupport.TripProjection();

            projection.ProjectionName = "Trip";

            StoreOptions(x => x.Projections.Add(projection, ProjectionLifecycle.Async), true);

            var agent = await StartDaemon();

            await PublishSingleThreaded();

            var waiter = agent.Tracker.WaitForShardState(new ShardState("Trip:All", NumberOfEvents), 30.Seconds());

            await waiter;

            var days = await theSession.Query <Trip>().ToListAsync();

            var notCriticalBreakdownStream = days[0].Id;
            var criticalBreakdownStream    = days[1].Id;

            theSession.Events.Append(notCriticalBreakdownStream, new Breakdown {
                IsCritical = false
            });
            theSession.Events.Append(criticalBreakdownStream, new Breakdown {
                IsCritical = true
            });

            await theSession.SaveChangesAsync();

            var waiter2 = agent.Tracker.WaitForShardState(new ShardState("Trip:All", NumberOfEvents + 2), 300.Seconds());

            await waiter2;



            using var query = theStore.QuerySession();

            (await query.LoadAsync <Trip>(notCriticalBreakdownStream)).ShouldNotBeNull();
            (await query.LoadAsync <Trip>(criticalBreakdownStream)).ShouldBeNull();
        }