public async Task <IActionResult> GetOrders()
        {
            var eventStoreConnection = new EventStoreBuilder();
            var result = await eventStoreConnection.GetProjection("orders");

            return(Ok(result));
        }
        public async System.Threading.Tasks.Task Should_CreateALeadProfieUponCreationOfQuoteGivenUserDoesntExist()
        {
            var email = (Email)"*****@*****.**";

            var rate = RateBuilder.WithDefaults();

            var wedding = WeddingBuilder.WithDefaults(rate);

            var quote = new WeddingQuote(email, wedding, rate);

            var eventStore = new EventStoreBuilder().Build();

            var context = new DblDipDbContextBuilder()
                          .Add(rate)
                          .Add(wedding)
                          .Add(quote)
                          .SaveChanges()
                          .Build();

            var sut = new QuoteCreatedSaga(context, eventStore);

            await sut.Handle(new QuoteCreated(quote), default);

            var user = context.Set <User>().Where(x => x.Username == email).Single();
        }
Beispiel #3
0
        public void BuildEventStore()
        {
            var storeBuilder = new EventStoreBuilder(ApplicationNameSpace);

            var eventStore = storeBuilder.Build(new EventStore());

            TestUtils.SnapshotTest(eventStore);
        }
Beispiel #4
0
        public static EventStoreBuilder WithMsSqlPersistor(this EventStoreBuilder builder, string connectionString, Action <IMsSqlPersistorBuilder> persistorBuilder = null)
        {
            var sqlPersistorBuilder = new MsSqlPersistorBuilder(builder.Logger, connectionString);

            if (persistorBuilder != null)
            {
                persistorBuilder(sqlPersistorBuilder);
            }
            builder.WithPersistor(new MsSqlPersistor(sqlPersistorBuilder.Linearizer, connectionString));
            return(builder);
        }
        public async System.Threading.Tasks.Task Should_CreateUserAndAccountWithRolesUponProfileCreated()
        {
            var context = DblDipDbContextBuilder.WithDefaults();

            var store = EventStoreBuilder.WithDefaults();

            var profile = ClientBuilder.WithDefaults();

            var sut = new ProfileCreatedSaga(store);

            await sut.Handle(new (profile), default);
Beispiel #6
0
        public async Task Run()
        {
            try
            {
                var store = new EventStoreBuilder()
                            .WithSerializer(new JilSerializer())
                            .WithLogger(new NLogLogger("Ses"))
                            .WithDefaultContractsRegistry(typeof(SampleRunner).Assembly)
                            .WithMsSqlPersistor(connectionString, x =>
                {
                    x.Destroy(true);
                    x.Initialize();
                    x.RunLinearizer(TimeSpan.FromMilliseconds(20), TimeSpan.FromMinutes(20));
                })
                            .Build();

                await Task.Delay(1000);

                await Sample1(store);
                await Sample2(store);

                Console.WriteLine(@"Starting subscriptions");
                var subs = SampleSubscriptions();
                await subs.StartAsync();

                foreach (var poller in subs.GetPollers())
                {
                    Console.WriteLine(poller);
                    foreach (var state in poller.SourceSequenceInfo)
                    {
                        Console.WriteLine($@"\t{state}");
                    }
                }

                await Task.Delay(5000);

                Console.WriteLine(@"Stopping subscriptions");
                store.Dispose();
                subs.Dispose();
                Console.WriteLine(@"Starting perf test");
                await SamplePerfTest();

                Console.WriteLine(@"Press any key to exit...");
                Console.ReadKey();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.ReadKey();
            }
        }
        public void SaveOneMillionEventsWithLMDBAndDummyPublisher()
        {
            int numberOfEvents = 1000000;
            int serialId       = 0;

            //For some reason, the values higher than 500 MB does not work.

            //TB = 1099511627776
            //GB = 1073741824
            //500MB = 524288000
            //100MB = 104857600

            IEventStoreBuilder builder = new EventStoreBuilder();
            var eventStore             = builder.UseLMDBRepository()
                                         .Configuration(@"c:\temp\lmdbevents", 2, 524288000, new ProtobufEventsSerializer())
                                         .UseCustom(new DummyEventPublisher())
                                         .Build();

            var before = DateTime.Now;

            var tasks = new ConcurrentBag <Task>();

            foreach (int i in Enumerable.Range(0, numberOfEvents))
            {
                tasks.Add(eventStore.Process(new EventTransaction
                {
                    Events = new[] {
                        new Event
                        {
                            AggregateId     = Guid.NewGuid(),
                            SerialId        = serialId++,
                            SerializedEvent = BitConverter.GetBytes(i),
                            EventType       = "A type of event"
                        }
                    }
                }));
            }

            Task.WhenAll(tasks.ToArray()).Wait();

            var after = DateTime.Now;

            var timeInMilliseconds = (after - before).TotalMilliseconds;
            var rate = numberOfEvents / (after - before).TotalSeconds;

            eventStore.Dispose();

            Assert.True(true, string.Format("Added {0} in {1} milliseconds, which is a rate of {2} per second", numberOfEvents, timeInMilliseconds, rate));
        }
        public void ReadOneMillionFromLMDB()
        {
            int numberOfEvents = 1000000;
            int serialId       = 0;

            IEventStoreBuilder builder = new EventStoreBuilder();
            var eventStore             = builder.UseLMDBRepository()
                                         .Configuration(@"c:\temp\lmdbevents", 2, 524288000, new ProtobufEventsSerializer())
                                         .UseCustom(new DummyEventPublisher())
                                         .Build();

            var tasks = new ConcurrentBag <Task>();

            foreach (int i in Enumerable.Range(0, numberOfEvents))
            {
                tasks.Add(eventStore.Process(new EventTransaction
                {
                    Events = new[] {
                        new Event
                        {
                            AggregateId     = Guid.NewGuid(),
                            SerialId        = serialId++,
                            SerializedEvent = BitConverter.GetBytes(i),
                            EventType       = "A type of event"
                        }
                    }
                }));
            }

            Task.WhenAll(tasks.ToArray()).Wait();

            var before = DateTime.Now;

            var x = eventStore.GetAllEvents(0, 1000000);

            var after = DateTime.Now;

            var timeInMilliseconds = (after - before).TotalMilliseconds;
            var rate = numberOfEvents / (after - before).TotalSeconds;

            eventStore.Dispose();

            Assert.True(true, string.Format("Read {0} in {1} milliseconds, which is a rate of {2} per second", numberOfEvents, timeInMilliseconds, rate));
        }
        public static void ConfigureEventStorage(this IServiceCollection services, IConfiguration configuration)
        {
            var config = new ConfigRoot();

            configuration.Bind(config);
            services.AddSingleton(
                typeof(IStreamStore),
                sp => EventStoreBuilder
                .WithConnectionString(config.EventStorage.ConnectionString)
                .UseDefaultCredentials(
                    new UserCredentials(
                        username: config.EventStorage.UserName,
                        password: config.EventStorage.Password))
                .DisableTlsConnection()
                .KeepReconnecting()
                .KeepRetrying()
                .Build());
            Console.WriteLine("connection established " + config.ToJson());
        }
Beispiel #10
0
        private static async Task SamplePerfTest()
        {
            using (var store = new EventStoreBuilder()
                               .WithDefaultContractsRegistry(typeof(SampleRunner).Assembly)
                               .WithMsSqlPersistor(connectionString, c => c.RunLinearizer(TimeSpan.FromMilliseconds(10), TimeSpan.FromSeconds(240)))
                               .WithSerializer(new JilSerializer())
                               .Build())
            {
                const int count = 10000;
                var       tasks = new List <Task>(count);
                var       token = new System.Threading.CancellationToken();
                var       sw    = Stopwatch.StartNew();
                for (var i = 0; i < count; i++)
                {
                    var task = Task.Run(async() =>
                    {
                        using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, options, TransactionScopeAsyncFlowOption.Enabled))
                        {
                            var streamId  = SequentialGuid.NewGuid();
                            var aggregate = new ShoppingCart(streamId, Guid.Empty);
                            aggregate.AddItem(SequentialGuid.NewGuid(), name: "Product 1", quantity: 3);

                            var commitId = SequentialGuid.NewGuid();
                            var stream   = new EventStream(commitId, aggregate.TakeUncommittedEvents());

                            await store.SaveChangesAsync(streamId, ExpectedVersion.NoStream, stream, token);

                            scope.Complete();
                        }
                    }, token);
                    tasks.Add(task);
                }
                await Task.WhenAll(tasks);

                sw.Stop();
                Console.WriteLine($@"Overall time {sw.ElapsedMilliseconds}ms - {(count / sw.Elapsed.TotalSeconds)}");
                Console.WriteLine(@"Waiting for Linearizer...");
                await Task.Delay(10000, token);

                Console.WriteLine(@"Done.");
            }
        }
Beispiel #11
0
        public async Task <IEventStore> GetEventStore(Assembly[] contractsRegistryAssemblies, IConcurrencyConflictResolver resolver = null)
        {
            if (!_databaseCreated)
            {
                await CreateDatabase(GetLocation());
            }

            var builder = new EventStoreBuilder()
                          .WithDefaultContractsRegistry(contractsRegistryAssemblies)
                          .WithMsSqlPersistor(ConnectionString, x =>
            {
                x.Initialize();
            })
                          .WithSerializer(new JilSerializer());

            if (resolver != null)
            {
                builder.WithConcurrencyConflictResolver(resolver);
            }

            return(builder.Build());
        }
        public void BuildLMDBEventStoreDoesNotThrow()
        {
            IEventStoreBuilder builder = new EventStoreBuilder();

            EventStore es = null;

            es = builder.UseLMDBRepository()
                 .Configuration(@"c:\lmdb", 2, 10485760, new ProtobufEventsSerializer())
                 .UseCustom(new DummyEventPublisher())
                 .Build();

            Assert.NotNull(es);

            //Clean up database
            es.Dispose();


            //Cleaning up disk

            GC.Collect();
            GC.WaitForPendingFinalizers();

            var datafile = Path.Combine(@"c:\lmdb", "data.mdb");

            if (File.Exists(datafile))
            {
                File.Delete(datafile);
            }

            var lockfile = Path.Combine(@"c:\lmdb", "lock.mdb");

            if (File.Exists(lockfile))
            {
                File.Delete(lockfile);
            }
        }
Beispiel #13
0
 public AggregateService()
 {
     _eventStoreBuilder = new EventStoreBuilder();
 }
        public void BuildingWithMissingDataThrowsException()
        {
            EventStoreBuilder builder = new EventStoreBuilder();

            Assert.Throws <Exception>(() => builder.Build());
        }
Beispiel #15
0
 public ProjectionService()
 {
     _eventStoreBuilder = new EventStoreBuilder();
 }