Exemple #1
0
        [Test]//Do not worry about it if this test fails when running in ncrunch. It runs it much slower for some reason. Probably due to intrumenting the assembly. Just ignore it in ncrunch.
        public void A_hundred_thousand_events_large_aggregate_with_four_migrations_should_load_cached_in_less_than_150_milliseconds()
        {
            var eventMigrations = Seq.Create <IEventMigration>(
                Before <E6> .Insert <E2>(),
                Before <E7> .Insert <E3>(),
                Before <E8> .Insert <E4>(),
                Before <E9> .Insert <E5>()
                ).ToArray();

            using (var container = CreateContainerForEventStoreType(() => eventMigrations, EventStoreType))
            {
                var timeSource = container.Resolve <DummyTimeSource>();

                var history   = Seq.OfTypes <Ec1>().Concat(1.Through(100000).Select(index => typeof(E1))).ToArray();
                var aggregate = TestAggregate.FromEvents(timeSource, Guid.NewGuid(), history);
                container.ExecuteUnitOfWorkInIsolatedScope(() => container.Resolve <IEventStoreSession>().Save(aggregate));

                //Warm up cache..
                container.ExecuteUnitOfWorkInIsolatedScope(() => container.Resolve <IEventStoreSession>().Get <TestAggregate>(aggregate.Id));

                TimeAsserter.Execute(
                    maxTotal: 150.Milliseconds().AdjustRuntimeForNCrunch(boost: 6),
                    description: "load aggregate in isolated scope",
                    action: () => container.ExecuteInIsolatedScope(() => container.Resolve <IEventStoreSession>().Get <TestAggregate>(aggregate.Id)));
            }
        }
 public void Inserting_E3_E4_before_E1()
 {
     RunMigrationTest(new MigrationScenario(
                          Seq.OfTypes <Ec1, E1, Ef>(),
                          Seq.OfTypes <Ec1, E3, E4, E1, Ef>(),
                          Before <E1> .Insert <E3, E4>()));
 }
        public void Calling_before_after_or_replace_1000_000_times_takes_less_than_60_milliseconds()
        {
            var before = Before <E3> .Insert <E2>().CreateSingleAggregateInstanceHandlingMigrator();

            var replace = Replace <E3> .With <E2>().CreateSingleAggregateInstanceHandlingMigrator();

            var after = After <E3> .Insert <E2>().CreateSingleAggregateInstanceHandlingMigrator();

            var @event        = new E2();
            var eventModifier = new EventModifier(@event, _ => { });

            var numberOfEventsToInspect = 1000000;
            var maxtime = TestEnvironmentPerformance.AdjustRuntime(60.Milliseconds(), boost: 12.0);

            TimeAsserter.Execute(
                maxTotal: maxtime,
                description: $"{nameof(before)}",
                iterations: numberOfEventsToInspect,
                action: () => before.MigrateEvent(@event, @eventModifier));
            TimeAsserter.Execute(
                maxTotal: maxtime,
                description: $"{nameof(replace)}",
                iterations: numberOfEventsToInspect,
                action: () => replace.MigrateEvent(@event, @eventModifier));
            TimeAsserter.Execute(
                maxTotal: maxtime,
                description: $"{nameof(after)}",
                iterations: numberOfEventsToInspect,
                action: () => after.MigrateEvent(@event, @eventModifier));
        }
 public void Inserting_E2_Before_E1()
 {
     RunMigrationTest(
         new MigrationScenario(
             Seq.OfTypes <Ec1, E1>(),
             Seq.OfTypes <Ec1, E2, E1>(),
             Before <E1> .Insert <E2>()));
 }
 public void Inserting_E3_E4_before_E1_then_E5_before_E4_2()
 {
     RunMigrationTest(new MigrationScenario(
                          Seq.OfTypes <Ec1, E1, Ef, Ef>(),
                          Seq.OfTypes <Ec1, E3, E5, E4, E1, Ef, Ef>(),
                          Before <E1> .Insert <E3, E4>(), //Ec1, E3, E4 E1, Ef, Ef
                          Before <E4> .Insert <E5>()));   //Ec1, E3, E5, E4, E1, Ef, Ef
 }
 public void Given_Ec1_E1_Inserting_E2_before_E1_then_E3_before_E2()
 {
     RunMigrationTest(new MigrationScenario(
                          Seq.OfTypes <Ec1, E1>(),
                          Seq.OfTypes <Ec1, E3, E2, E1>(),
                          Before <E1> .Insert <E2>(),   //Ec1, E2, E1
                          Before <E2> .Insert <E3>())); //Ec1, E3, E2, E1
 }
 public void Inserting_E3_E4_before_E1_then_E5_before_E4_then_replace_E4_with_E6()
 {
     RunMigrationTest(new MigrationScenario(
                          Seq.OfTypes <Ec1, E1, Ef>(),
                          Seq.OfTypes <Ec1, E6, E5, E4, E1, Ef>(),
                          Before <E1> .Insert <E3, E4>(), //Ec1, E3, E4, E1, Ef
                          Before <E4> .Insert <E5>(),     //Ec1, E3, E5, E4, E1, Ef
                          Replace <E3> .With <E6>()));    //Ec1, E6, E5, E4, E1, Ef
 }
 public void Inserting_E3_E4_before_E1_then_E5_before_E4_then_replace_E4_with_E6_then_replace_Ef_with_E7_then_insert_E8_after_E7()
 {
     RunMigrationTest(new MigrationScenario
                          (Seq.OfTypes <Ec1, E1, Ef>(),
                          Seq.OfTypes <Ec1, E6, E5, E4, E1, E7, E8>(),
                          Before <E1> .Insert <E3, E4>(), //Ec1, E3, E4, E1, Ef
                          Before <E4> .Insert <E5>(),     //Ec1, E3, E5, E4, E1, Ef
                          Replace <E3> .With <E6>(),      //Ec1, E6, E5, E4, E1, Ef
                          Replace <Ef> .With <E7>(),      //Ec1, E6, E5, E4, E1, E7
                          After <E7> .Insert <E8>()));    //Ec1, E6, E5, E4, E1, E7, E8
 }
 public void Given_Ec1_E1_before_E1_E2_after_E2_E3_throws_NonIdempotentMigrationDetectedException()
 {
     this.Invoking(
         me =>
         RunMigrationTest(
             new MigrationScenario(
                 Seq.OfTypes <Ec1, E1>(),
                 Seq.OfTypes <Ec1, E2, E3, E1>(),
                 Before <E1> .Insert <E2>(),
                 After <E2> .Insert <E3>())))
     .ShouldThrow <NonIdempotentMigrationDetectedException>();
 }
        public void With_four_migrations_that_change_nothing_mutation_takes_less_than_10_milliseconds()
        {
            var eventMigrations = Seq.Create <IEventMigration>(
                Before <E3> .Insert <E1>(),
                Before <E5> .Insert <E1>(),
                Before <E7> .Insert <E1>(),
                Before <E9> .Insert <E1>()
                ).ToArray();

            var maxAverage = 10.Milliseconds().AdjustRuntimeForNCrunch(boost: 6);

            TimeAsserter.Execute(
                maxTotal: maxAverage,
                maxTries: 10,
                description: "load aggregate in isolated scope",
                timeFormat: "ss\\.fff",
                action: () => { SingleAggregateInstanceEventStreamMutator.MutateCompleteAggregateHistory(eventMigrations, _history); });
        }
        public void With_four_migrations_mutation_that_all_actually_changes_things_migration_takes_less_than_15_milliseconds()
        {
            var eventMigrations = Seq.Create <IEventMigration>(
                Before <E2> .Insert <E3>(),
                Before <E4> .Insert <E5>(),
                Before <E6> .Insert <E7>(),
                Before <E8> .Insert <E9>()
                ).ToArray();

            var maxAverage = TestEnvironmentPerformance.AdjustRuntime(15.Milliseconds(), boost: 2);

            TimeAsserter.Execute(
                maxTotal: maxAverage,
                description: "load aggregate in isolated scope",
                maxTries: 10,
                timeFormat: "ss\\.fff",
                action: () => { SingleAggregateInstanceEventStreamMutator.MutateCompleteAggregateHistory(eventMigrations, _history); });
        }
        public void Inserting_E2_Before_E1_Persisting_and_then_Inserting_E3_before_E1()
        {
            var firstMigration  = Seq.Create(Before <E1> .Insert <E2>()).ToArray();
            var secondMigration = Seq.Create(Before <E1> .Insert <E3>()).ToArray();
            IReadOnlyList <IEventMigration> migrations = new List <IEventMigration>();

            using (var container = CreateContainerForEventStoreType(() => migrations, EventStoreType))
            {
                container.Resolve <DummyTimeSource>().UtcNow = DateTime.Parse("2001-01-01 12:00");

                var id = Guid.Parse("00000000-0000-0000-0000-000000000001");
                var initialAggregate = TestAggregate.FromEvents(container.Resolve <IUtcTimeTimeSource>(), id, Seq.OfTypes <Ec1, E1>());
                var expectedHistoryAfterFirstMigration  = TestAggregate.FromEvents(container.Resolve <IUtcTimeTimeSource>(), id, Seq.OfTypes <Ec1, E2, E1>()).History;
                var expectedHistoryAfterSecondMigration = TestAggregate.FromEvents(container.Resolve <IUtcTimeTimeSource>(), id, Seq.OfTypes <Ec1, E2, E3, E1>()).History;

                Func <IEventStoreSession> session    = () => container.Resolve <IEventStoreSession>();
                Func <IEventStore>        eventStore = () => container.Resolve <IEventStore>();

                container.ExecuteUnitOfWorkInIsolatedScope(() => session().Save(initialAggregate));
                migrations = firstMigration;
                var historyWithFirstMigrationUnPersisted = container.ExecuteUnitOfWorkInIsolatedScope(() => session().Get <TestAggregate>(id).History);

                container.ExecuteUnitOfWorkInIsolatedScope(() => eventStore().PersistMigrations());
                var historyAfterPersistingFirstMigration = container.ExecuteUnitOfWorkInIsolatedScope(() => session().Get <TestAggregate>(id).History);
                AssertStreamsAreIdentical(expectedHistoryAfterFirstMigration, historyWithFirstMigrationUnPersisted, nameof(historyWithFirstMigrationUnPersisted));
                AssertStreamsAreIdentical(expectedHistoryAfterFirstMigration, historyAfterPersistingFirstMigration, nameof(historyAfterPersistingFirstMigration));

                migrations = secondMigration;
                ClearEventstoreCache(container);
                var historyWithSecondMigrationUnPersisted = container.ExecuteUnitOfWorkInIsolatedScope(() => session().Get <TestAggregate>(id).History);

                container.ExecuteUnitOfWorkInIsolatedScope(() => eventStore().PersistMigrations());
                var historyAfterPersistingSecondMigration = container.ExecuteUnitOfWorkInIsolatedScope(() => session().Get <TestAggregate>(id).History);
                AssertStreamsAreIdentical(expectedHistoryAfterSecondMigration, historyWithSecondMigrationUnPersisted, nameof(historyWithSecondMigrationUnPersisted));
                AssertStreamsAreIdentical(expectedHistoryAfterSecondMigration, historyAfterPersistingSecondMigration, nameof(historyAfterPersistingSecondMigration));
            }
        }