Esempio n. 1
0
        public void get_current_version()
        {
            using (var store = new FileAppendOnlyStore(new DirectoryInfo(_storePath)))
            {
                store.Initialize();
                var currentVersion = store.GetCurrentVersion();
                store.Append("versiontest", Encoding.UTF8.GetBytes("test message1"));
                store.Append("versiontest", Encoding.UTF8.GetBytes("test message2"));
                store.Append("versiontest", Encoding.UTF8.GetBytes("test message3"));

                Assert.AreEqual(currentVersion + 3, store.GetCurrentVersion());
            }
        }
Esempio n. 2
0
        public void read_store_all_records()
        {
            var stream = Guid.NewGuid().ToString();

            using (var store = new FileAppendOnlyStore(new DirectoryInfo(_storePath)))
            {
                store.Initialize();
                var currentVersion = store.GetCurrentVersion();
                for (int i = 0; i < 2; i++)
                {
                    store.Append(stream, Encoding.UTF8.GetBytes("test message" + i));
                }

                var records = store.ReadRecords(-1, Int32.MaxValue).ToArray();

                Assert.AreEqual(currentVersion + 2, records.Length);

                for (var i = currentVersion; i < currentVersion + 2; i++)
                {
                    Assert.AreEqual("test message" + (i - currentVersion), Encoding.UTF8.GetString(records[i].Data));
                    Assert.AreEqual(i - currentVersion + 1, records[i].StreamVersion);
                    Assert.AreEqual(i + 1, records[i].StoreVersion);
                }
            }
        }
        public void append_data()
        {
            _store.Initialize();
            var       currentVersion = _store.GetCurrentVersion();
            const int messagesCount  = 3;

            for (int i = 0; i < messagesCount; i++)
            {
                _store.Append("stream1", Encoding.UTF8.GetBytes("test message" + i));
            }

            var data = _store.ReadRecords("stream1", currentVersion, Int32.MaxValue).ToArray();

            for (int i = 0; i < messagesCount; i++)
            {
                Assert.AreEqual("test message" + i, Encoding.UTF8.GetString(data[i].Data));
            }

            Assert.AreEqual(messagesCount, data.Length);
        }
Esempio n. 4
0
        public static ConsoleEnvironment Build()
        {
            var handler = new SynchronousEventHandler();

            var inbox = new InboxProjection();
            handler.RegisterHandler(inbox);

            //var store = new InMemoryStore(handler);

            var store = new FileAppendOnlyStore(new DirectoryInfo(Directory.GetCurrentDirectory()));
            store.Initialize();
            var messageStore = new MessageStore(store);
            messageStore.LoadDataContractsFromAssemblyOf(typeof(ActionDefined));
            var currentVersion = store.GetCurrentVersion();
            var log = LogManager.GetLoggerFor<ConsoleEnvironment>();
            log.Debug("Event Store ver {0}", currentVersion);

            if (currentVersion > 0)
            {
                log.Debug("Running in-memory replay");
                foreach (var record in messageStore.EnumerateAllItems(0, int.MaxValue))
                {
                    foreach (var item in record.Items.OfType<Event>())
                    {
                        handler.Handle(item);
                    }
                }
                log.Debug("Replay complete");
            }

            var events = new EventStore(messageStore,handler);

            var tenant = new TenantAppService(events, new RealTimeProvider());
            var build = new ConsoleEnvironment
                {
                    Store = events,
                    Tenant = tenant,
                    Commands = ConsoleCommands.Actions,
                    Id = new TenantId(1),
                    Inbox = inbox
                };
            return build;
        }