Example #1
0
        public async Task DublicateEventThrowsAsync()
        {
            var es      = new StreamStoneEventStore(table, TypeResolver.FromMap(TypeResolver.GetEventsFromTypes(typeof(TestEvent))));
            var eventid = Guid.NewGuid().ToString();

            var id = Guid.NewGuid();
            var e  = new TestEvent(id)
            {
                Meta = new Dictionary <string, string>()
                {
                    { "EventId", eventid }
                }
            };


            await es.AppendToStreamAsync("testing", 0, new[] { e });

            var e2 = new TestEvent(id)
            {
                Meta = new Dictionary <string, string>()
                {
                    { "EventId", eventid }
                }
            };

            await Assert.ThrowsAsync <DuplicateEventException>(() => es.AppendToStreamAsync("testing", 1, new[] { e2 }));
        }
Example #2
0
 public static OrderModule Initialize(IReliableStateManager stateManager, Func <IEvent[], Task> eventLogger)
 => Initialize(stateManager, tx => new ReliableEventStore(
                   stateManager,
                   tx,
                   Serialization.Json(),
                   Serialization.JsonDeserialization(TypeResolver.FromMap(TypeResolver.GetEventsFromTypes(typeof(ItemAddedEvent))))       //TODO "share" with publisher
                   ),
               (tx, events) => stateManager.EnqueuAsync(tx, events, Serialization.Json()),
               eventLogger);
Example #3
0
        public void ConfigureServices(IServiceCollection services)
        {
            var deserializer = Serialization.JsonDeserialization(TypeResolver.FromMap(TypeResolver.GetEventsFromTypes(typeof(ItemAddedEvent))));

            services.AddSingleton(sc => CartModule.Initialize(sc.GetService <IReliableStateManager>(), events => Task.CompletedTask));
            services.AddSingleton <Microsoft.Extensions.Hosting.IHostedService>(sc => new Publisher(sc.GetService <IReliableStateManager>(), deserializer));
            services
            .AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }
Example #4
0
        public async Task WriteReadAsync()
        {
            var es = new StreamStoneEventStore(table, TypeResolver.FromMap(TypeResolver.GetEventsFromTypes(typeof(TestEvent))));

            var id = Guid.NewGuid();
            var e  = new TestEvent(id)
            {
                Meta = new Dictionary <string, string>()
                {
                    { "EventId", Guid.NewGuid().ToString() }
                }
            };

            await es.AppendToStreamAsync("testing", 0, new[] { e });

            var r = await es.LoadEventStreamAsync("testing", 1);

            Assert.Equal(1, r.Version);
        }
Example #5
0
 public static IHostBuilder CreateHostBuilder(string[] args) =>
 Host.CreateDefaultBuilder(args)
 .ConfigureWebHostDefaults(webBuilder =>
                           webBuilder.ConfigureServices((ctx, services) =>
                                                        services
                                                        .Tap(s =>
 {
     //if (ctx.Configuration.GetValue<bool>("fiffi-dapr"))
     //    s.AddFiffiDapr();
     //else
     s.AddFiffiInMemory();
 })
                                                        .AddApplicationInsightsTelemetry()
                                                        .AddSingleton(TypeResolver.FromMap(TypeResolver.GetEventsInNamespace <GameCreated>()))
                                                        .AddSingleton(sp => GameModule.Initialize(
                                                                          sp.GetRequiredService <IAdvancedEventStore>(),
                                                                          sp.GetRequiredService <ISnapshotStore>(),
                                                                          events => sp.GetService <GameModule>().WhenAsync(events)
                                                                          ))
                                                        .AddSwaggerGen(c => c.SwaggerDoc("v1", new OpenApiInfo {
     Title = "RPS Game", Version = "v1"
 }))
                                                        .AddLogging(b => b.AddFilter <ApplicationInsightsLoggerProvider>("", LogLevel.Information))
                                                        .AddMvc()
                                                        .AddDapr()
                                                        )
                           .Configure(app =>
 {
     app.UseRouting();
     app.UseCloudEvents();
     app.UseAuthorization();
     app.UseSwagger();
     app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json",
                                             "RPS Game v1"));
     app.UseEndpoints(endpoints =>
     {
         endpoints.MapSubscribeHandler();
         endpoints.MapControllers();
         endpoints.MapDefaultControllerRoute();
     });
 })
                           );
        public async Task AppendAsync()
        {
            var settings = new ModuleOptions
            {
                ServiceUri = serviceUri,
                Key        = key
            };

            var s = new CosmoStoreEventStore(settings.ConnectionString,
                                             TypeResolver.FromMap(TypeResolver.GetEventsFromTypes(typeof(TestEvent))));

            _ = await s.AppendToStreamAsync("test", 0, new IEvent[] { new TestEvent("id").AddTestMetaData <string>(new AggregateId("id")) });

            _ = await s.AppendToStreamAsync("test", 1, new IEvent[] { new TestEvent("id").AddTestMetaData <string>(new AggregateId("id")) });

            var r = await s.LoadEventStreamAsync("test", 0);

            var e = r.Events.ToList();

            Assert.Equal(2, e.Count);
            Assert.True(e.All(x => x.Meta.Keys.Any()));
        }
Example #7
0
        public async Task AB_Projections()
        {
            var events = new List <EventRecord>
            {
                new Depareted {
                    Time        = 0,
                    TransportId = 0,
                    Kind        = Kind.Truck,
                    Location    = Location.Factory,
                    Destination = Location.Port,
                    Cargo       = new [] { new Cargo(0, Location.A, Location.Factory) }
                },
                new Depareted {
                    Time        = 0,
                    TransportId = 1,
                    Kind        = Kind.Truck,
                    Location    = Location.Factory,
                    Destination = Location.B,
                    Cargo       = new [] { new Cargo(1, Location.B, Location.Factory) }
                },
                new Arrived {
                    Time        = 1,
                    TransportId = 0,
                    Kind        = Kind.Truck,
                    Location    = Location.Port,
                    Cargo       = new [] { new Cargo(0, Location.A, Location.Factory) }
                },
                new Depareted {
                    Time        = 1,
                    TransportId = 0,
                    Kind        = Kind.Truck,
                    Location    = Location.Port,
                    Destination = Location.Factory
                },
                new Depareted {
                    Time        = 1,
                    TransportId = 2,
                    Kind        = Kind.Ship,
                    Location    = Location.Port,
                    Destination = Location.A,
                    Cargo       = new [] { new Cargo(0, Location.A, Location.Factory) }
                },
                new Arrived {
                    Time        = 2,
                    TransportId = 0,
                    Kind        = Kind.Truck,
                    Location    = Location.Factory
                },
                new Arrived {
                    Time        = 5,
                    TransportId = 1,
                    Kind        = Kind.Truck,
                    Location    = Location.B,
                    Cargo       = new [] { new Cargo(1, Location.B, Location.Factory) }
                },
                new Depareted {
                    Time        = 5,
                    TransportId = 1,
                    Kind        = Kind.Truck,
                    Location    = Location.B,
                    Destination = Location.Factory
                },
                new Depareted {
                    Time        = 5,
                    TransportId = 1,
                    Kind        = Kind.Truck,
                    Location    = Location.B,
                    Destination = Location.Factory
                },
                new Arrived {
                    Time        = 5,
                    TransportId = 2,
                    Kind        = Kind.Ship,
                    Location    = Location.A,
                    Cargo       = new [] { new Cargo(0, Location.A, Location.Factory) }
                },
                new Depareted {
                    Time        = 5,
                    TransportId = 2,
                    Kind        = Kind.Ship,
                    Location    = Location.A,
                    Destination = Location.Port
                },
            };

            var eventsWithMeta = events.ToArray().ToEnvelopes("").Select(e => e.Tap(x => e.Meta.AddTypeInfo(e))).ToArray();
            var store          = new Fiffi.FileSystem.FileSystemEventStore("teststore", TypeResolver.FromMap(TypeResolver.GetEventsFromTypes(typeof(Depareted), typeof(Arrived))));

            _ = await store.AppendToStreamAsync("all", eventsWithMeta);

            //{ "event": "DEPART", "time": 0, "transport_id": 0, "kind": "TRUCK", "location": "FACTORY", "destination": "PORT", "cargo": [{"cargo_id": 0, "destination": "A", "origin": "FACTORY"}]}
            //{"event": "DEPART", "time": 0, "transport_id": 1, "kind": "TRUCK", "location": "FACTORY", "destination": "B", "cargo": [{"cargo_id": 1, "destination": "B", "origin": "FACTORY"}]}
            //{"event": "ARRIVE", "time": 1, "transport_id": 0, "kind": "TRUCK", "location": "PORT", "cargo": [{"cargo_id": 0, "destination": "A", "origin": "FACTORY"}]}
            //{"event": "DEPART", "time": 1, "transport_id": 0, "kind": "TRUCK", "location": "PORT", "destination": "FACTORY"}
            //{"event": "DEPART", "time": 1, "transport_id": 2, "kind": "SHIP", "location": "PORT", "destination": "A", "cargo": [{"cargo_id": 0, "destination": "A", "origin": "FACTORY"}]}
            //{"event": "ARRIVE", "time": 2, "transport_id": 0, "kind": "TRUCK", "location": "FACTORY"}
            //{"event": "ARRIVE", "time": 5, "transport_id": 1, "kind": "TRUCK", "location": "B", "cargo": [{"cargo_id": 1, "destination": "B", "origin": "FACTORY"}]}
            //{"event": "DEPART", "time": 5, "transport_id": 1, "kind": "TRUCK", "location": "B", "destination": "FACTORY"}
            //{"event": "ARRIVE", "time": 5, "transport_id": 2, "kind": "SHIP", "location": "A", "cargo": [{"cargo_id": 0, "destination": "A", "origin": "FACTORY"}]}
            //{"event": "DEPART", "time": 5, "transport_id": 2, "kind": "SHIP", "location": "A", "destination": "PORT"}
        }