Example #1
0
        public static void Main(string[] args)
        {
            AbstractSerializer.RegisterKnownType(typeof(UserCreatedEvent));

            // Create serializers after registering known types
            ISerializer[] Serializers =
            {
                new DataContractSerializer(),
                new ProtoBufSerializer(),
                new BsonNetSerializer(),
                new JsonNetSerializer()
            };

            foreach (Func <IAppendOnlyStore> aStoreBuilder in AppendOnlyStores)
            {
                foreach (ISerializer serializer in Serializers)
                {
                    UserId        id     = new UserId(1);
                    List <IEvent> events = new List <IEvent>()
                    {
                        new UserCreatedEvent(id, "John")
                    };

                    IAppendOnlyStore aStore = aStoreBuilder();
                    try
                    {
                        EventStoreDB eStore = new EventStoreDB(aStore, serializer);
                        eStore.Append(id, 0, events);

                        // Warm up various caches
                        for (int i = 0; i < 10; ++i)
                        {
                            EventStream s = eStore.Load(id);
                            eStore.Append(id, s.Version, events);
                        }

                        int      count = 0;
                        DateTime t1    = DateTime.Now;
                        do
                        {
                            id = new UserId(100 + count);
                            //EventStream s = eStore.Load(id);
                            eStore.Append(id, 0, new IEvent[] { new UserCreatedEvent(id, "John") });
                            ++count;
                        }while ((DateTime.Now - t1) < TimeSpan.FromMilliseconds(1000));

                        Console.WriteLine("{0} + {1}: {2}", aStore, serializer, count);
                    }
                    finally
                    {
                        aStore.Dispose();
                    }
                }
            }
        }
Example #2
0
        static void TestLoad(object o)
        {
            TestLoadData data = (TestLoadData)o;

            IAppendOnlyStore appendOnlyStore = data.Store;
            {
                ISerializer  serializer = new JsonNetSerializer();
                EventStoreDB store      = new EventStoreDB(appendOnlyStore, serializer);

                UserId      id = new UserId(data.N);
                EventStream s  = store.Load(id);
                System.Threading.Thread.Sleep(Rand.GetInts(100, 500, 1)[0]);
                Assert.AreEqual(s.Version, 0);
                List <IEvent> events = new List <IEvent>()
                {
                    new UserCreatedEvent(id, "John")
                };
                store.Append(id, 0, events);
            }
        }