public void when_verify_events_where_events_count_less_100()
        {
            _store.AppendToStore("stream1", new List <MessageAttribute>(), 0, new List <object> {
                new SerializerTest1("message1")
            });
            _store.AppendToStore("stream1", new List <MessageAttribute>(), 1, new List <object> {
                new SerializerTest1("message1")
            });

            var records = _store.EnumerateAllItems(0, 100).ToArray();

            _publisher.VerifyEventStreamSanity();

            Assert.AreEqual(2, records.Length);
        }
Example #2
0
        public void AppendEventsToStream(string name, long streamVersion, ICollection <Event> events)
        {
            if (events.Count == 0)
            {
                return;
            }
            // functional events don't have an identity

            try
            {
                _msgStore.AppendToStore(name, streamVersion, events.Cast <object>().ToArray());
            }
            catch (AppendOnlyStoreConcurrencyException e)
            {
                // load server events
                var server = LoadEventStream(name);
                // throw a real problem
                throw OptimisticConcurrencyException.Create(server.StreamVersion, e.ExpectedStreamVersion, name, server.Events);
            }
            // sync handling. Normally we would push this to async
            foreach (var @event in events)
            {
                _msgHandler.Handle(@event);
            }
        }
Example #3
0
        public void when_append_to_store()
        {
            var store = new MessageStore(_appendOnlyStore, _serializer);

            store.AppendToStore("stream5", MessageAttribute.Empty, -1, new[] { new SerializerTest1 {
                                                                                   Name = "name1"
                                                                               } });
            var records = store.EnumerateMessages("stream5", 0, Int32.MaxValue).ToArray();

            Assert.AreEqual(1, records.Length);
            Assert.AreEqual(1, records[0].Items.Length);
            Assert.AreEqual("name1", (records[0].Items[0] as SerializerTest1).Name);
        }
Example #4
0
        public void when_append_to_store()
        {
            var store = new MessageStore(_appendOnlyStore, _serializer);

            store.AppendToStore("stream5", MessageAttribute.Empty, -1, new[] { "msg1", "msg2", "msg3" });
            var records = store.EnumerateMessages("stream5", 0, Int32.MaxValue).ToArray();

            Assert.AreEqual(1, records.Length);
            Assert.AreEqual(3, records[0].Items.Length);
            //todo simple types are not properly deserialize
            //Assert.AreEqual("msg1", records[0].Items[0].ToString());
            //Assert.AreEqual("msg2", records[0].Items[1].ToString());
            //Assert.AreEqual("msg3", records[0].Items[2].ToString());
        }
Example #5
0
        public void SetUp()
        {
            _serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), typeof(string) });
            _path       = Path.Combine(Path.GetTempPath(), "MessageStore", Guid.NewGuid().ToString());
            if (!Directory.Exists(_path))
            {
                Directory.CreateDirectory(_path);
            }
            _appendOnlyStore = new FileAppendOnlyStore(new DirectoryInfo(_path));

            var store = new MessageStore(_appendOnlyStore, _serializer);

            store.AppendToStore("stream1", MessageAttribute.Empty, -1, new[] { new SerializerTest1("msg1") });
            store.AppendToStore("stream2", MessageAttribute.Empty, -1, new[] { new SerializerTest1("msg1"), new SerializerTest1("msg2") });
            store.AppendToStore("stream3", MessageAttribute.Empty, -1, new[] { new SerializerTest1("msg1"), new SerializerTest1("msg2"), new SerializerTest1("msg3") });
            store.RecordMessage("stream4", new ImmutableEnvelope("EnvId", DateTime.UtcNow, new SerializerTest1("msg1"), MessageAttribute.Empty));

            _appendOnlyStore.Close();
            _appendOnlyStore = new FileAppendOnlyStore(new DirectoryInfo(_path));
            _appendOnlyStore.Initialize();

            _store = new MessageStore(_appendOnlyStore, _serializer);
        }
Example #6
0
        public void AppendEventsToStream(IIdentity id, long streamVersion, ICollection <IEvent> events)
        {
            if (events.Count == 0)
            {
                return;
            }
            // functional events don't have an identity
            var name = IdentityToKey(id);

            try
            {
                _store.AppendToStore(name, MessageAttribute.Empty, streamVersion, events.Cast <object>().ToArray());
            }
            catch (AppendOnlyStoreConcurrencyException e)
            {
                // load server events
                var server = LoadEventStream(id);
                // throw a real problem
                throw OptimisticConcurrencyException.Create(server.StreamVersion, e.ExpectedStreamVersion, id, server.Events);
            }
        }