コード例 #1
0
        public void should_append_with_stream_exists_exp_ver_to_existing_stream()
        {
            const string stream = "should_append_with_stream_exists_exp_ver_to_existing_stream";

            using (var store = BuildConnection(_node))
            {
                store.ConnectAsync().Wait();
                store.AppendToStreamAsync(stream, ExpectedVersion.EmptyStream, TestEvent.NewTestEvent()).Wait();

                var append = store.AppendToStreamAsync(stream, ExpectedVersion.StreamExists, new[] { TestEvent.NewTestEvent() });
                Assert.DoesNotThrow(append.Wait);
            }
        }
コード例 #2
0
        public void should_append_with_stream_exists_exp_ver_to_stream_with_multiple_events()
        {
            const string stream = "should_append_with_stream_exists_exp_ver_to_stream_with_multiple_events";

            using (var store = BuildConnection(_node))
            {
                store.ConnectAsync().Wait();
                for (var i = 0; i < 5; i++)
                {
                    store.AppendToStreamAsync(stream, ExpectedVersion.Any, TestEvent.NewTestEvent()).Wait();
                }

                var append = store.AppendToStreamAsync(stream, ExpectedVersion.StreamExists, new[] { TestEvent.NewTestEvent() });
                Assert.DoesNotThrow(append.Wait);
            }
        }
コード例 #3
0
        public void multiple_idempotent_writes()
        {
            const string stream = "multiple_idempotent_writes";

            using (var store = BuildConnection(_node))
            {
                store.ConnectAsync().Wait();

                var events = new[] { TestEvent.NewTestEvent(), TestEvent.NewTestEvent(), TestEvent.NewTestEvent(), TestEvent.NewTestEvent() };
                Assert.AreEqual(3, store.AppendToStreamAsync(stream, ExpectedVersion.Any, events).Result.NextExpectedVersion);
                Assert.AreEqual(3, store.AppendToStreamAsync(stream, ExpectedVersion.Any, events).Result.NextExpectedVersion);
            }
        }
コード例 #4
0
        public void should_fail_writing_with_any_exp_ver_to_deleted_stream()
        {
            const string stream = "should_fail_writing_with_any_exp_ver_to_deleted_stream";

            using (var store = BuildConnection(_node))
            {
                store.ConnectAsync().Wait();

                try
                {
                    store.DeleteStreamAsync(stream, ExpectedVersion.EmptyStream, hardDelete: true).Wait();
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc);
                    Assert.Fail();
                }

                var append = store.AppendToStreamAsync(stream, ExpectedVersion.Any, new[] { TestEvent.NewTestEvent() });
                Assert.That(() => append.Wait(), Throws.Exception.TypeOf <AggregateException>().With.InnerException.TypeOf <StreamDeletedException>());
            }
        }
コード例 #5
0
        public void soft_deleted_stream_returns_no_stream_and_no_events_on_read()
        {
            const string stream = "soft_deleted_stream_returns_no_stream_and_no_events_on_read";

            Assert.AreEqual(1, _conn.AppendToStreamAsync(stream, ExpectedVersion.NoStream, TestEvent.NewTestEvent(), TestEvent.NewTestEvent()).Result.NextExpectedVersion);
            _conn.DeleteStreamAsync(stream, 1).Wait();

            var res = _conn.ReadStreamEventsForwardAsync(stream, 0, 100, false).Result;

            Assert.AreEqual(SliceReadStatus.StreamNotFound, res.Status);
            Assert.AreEqual(0, res.Events.Length);
            Assert.AreEqual(1, res.LastEventNumber);
        }
コード例 #6
0
        public void soft_deleted_stream_allows_recreation_when_expver_no_stream()
        {
            const string stream = "soft_deleted_stream_allows_recreation_when_expver_no_stream";

            Assert.AreEqual(1, _conn.AppendToStreamAsync(stream, ExpectedVersion.NoStream, TestEvent.NewTestEvent(), TestEvent.NewTestEvent()).Result.NextExpectedVersion);
            _conn.DeleteStreamAsync(stream, 1).Wait();

            var events = new[] { TestEvent.NewTestEvent(), TestEvent.NewTestEvent(), TestEvent.NewTestEvent() };

            Assert.AreEqual(4, _conn.AppendToStreamAsync(stream, ExpectedVersion.NoStream, events).Result.NextExpectedVersion);

            var res = _conn.ReadStreamEventsForwardAsync(stream, 0, 100, false).Result;

            Assert.AreEqual(SliceReadStatus.Success, res.Status);
            Assert.AreEqual(4, res.LastEventNumber);
            Assert.AreEqual(3, res.Events.Length);
            Assert.AreEqual(events.Select(x => x.EventId), res.Events.Select(x => x.OriginalEvent.EventId));
            Assert.AreEqual(new[] { 2, 3, 4 }, res.Events.Select(x => x.OriginalEvent.EventNumber));

            var meta = _conn.GetStreamMetadataAsync(stream).Result;

            Assert.AreEqual(2, meta.StreamMetadata.TruncateBefore);
            Assert.AreEqual(1, meta.MetastreamVersion);
        }
コード例 #7
0
        public void setting_nonjson_metadata_on_nonempty_soft_deleted_stream_recreates_stream_keeping_original_metadata()
        {
            const string stream = "setting_nonjson_metadata_on_nonempty_soft_deleted_stream_recreates_stream_overriding_metadata";

            Assert.AreEqual(1, _conn.AppendToStreamAsync(stream, ExpectedVersion.NoStream, TestEvent.NewTestEvent(), TestEvent.NewTestEvent()).Result.NextExpectedVersion);
            _conn.DeleteStreamAsync(stream, 1, hardDelete: false).Wait();

            Assert.AreEqual(1, _conn.SetStreamMetadataAsync(stream, 0, new byte[256]).Result.NextExpectedVersion);

            var res = _conn.ReadStreamEventsForwardAsync(stream, 0, 100, false).Result;

            Assert.AreEqual(SliceReadStatus.Success, res.Status);
            Assert.AreEqual(1, res.LastEventNumber);
            Assert.AreEqual(2, res.Events.Length);
            Assert.AreEqual(new[] { 0, 1 }, res.Events.Select(x => x.OriginalEventNumber).ToArray());

            var meta = _conn.GetStreamMetadataAsRawBytesAsync(stream).Result;

            Assert.AreEqual(1, meta.MetastreamVersion);
            Assert.AreEqual(new byte[256], meta.StreamMetadata);
        }
コード例 #8
0
        public void setting_json_metadata_on_nonempty_soft_deleted_stream_recreates_stream_not_overriding_metadata()
        {
            const string stream = "setting_json_metadata_on_nonempty_soft_deleted_stream_recreates_stream_not_overriding_metadata";

            Assert.AreEqual(1, _conn.AppendToStreamAsync(stream, ExpectedVersion.NoStream, TestEvent.NewTestEvent(), TestEvent.NewTestEvent()).Result.NextExpectedVersion);
            _conn.DeleteStreamAsync(stream, 1, hardDelete: false).Wait();

            Assert.AreEqual(1, _conn.SetStreamMetadataAsync(stream, 0,
                                                            StreamMetadata.Build().SetMaxCount(100)
                                                            .SetDeleteRole("some-role")
                                                            .SetCustomProperty("key1", true)
                                                            .SetCustomProperty("key2", 17)
                                                            .SetCustomProperty("key3", "some value")).Result.NextExpectedVersion);

            var res = _conn.ReadStreamEventsForwardAsync(stream, 0, 100, false).Result;

            Assert.AreEqual(SliceReadStatus.Success, res.Status);
            Assert.AreEqual(1, res.LastEventNumber);
            Assert.AreEqual(0, res.Events.Length);

            var meta = _conn.GetStreamMetadataAsync(stream).Result;

            Assert.AreEqual(2, meta.MetastreamVersion);
            Assert.AreEqual(2, meta.StreamMetadata.TruncateBefore);
            Assert.AreEqual(100, meta.StreamMetadata.MaxCount);
            Assert.AreEqual("some-role", meta.StreamMetadata.Acl.DeleteRole);
            Assert.AreEqual(true, meta.StreamMetadata.GetValue <bool>("key1"));
            Assert.AreEqual(17, meta.StreamMetadata.GetValue <int>("key2"));
            Assert.AreEqual("some value", meta.StreamMetadata.GetValue <string>("key3"));
        }
コード例 #9
0
        public void soft_deleted_stream_appends_both_writes_when_expver_any()
        {
            const string stream = "soft_deleted_stream_appends_both_concurrent_writes_when_expver_any";

            Assert.AreEqual(1, _conn.AppendToStreamAsync(stream, ExpectedVersion.NoStream, TestEvent.NewTestEvent(), TestEvent.NewTestEvent()).Result.NextExpectedVersion);
            _conn.DeleteStreamAsync(stream, 1).Wait();

            var events1 = new[] { TestEvent.NewTestEvent(), TestEvent.NewTestEvent(), TestEvent.NewTestEvent() };
            var events2 = new[] { TestEvent.NewTestEvent(), TestEvent.NewTestEvent() };

            Assert.AreEqual(4, _conn.AppendToStreamAsync(stream, ExpectedVersion.Any, events1).Result.NextExpectedVersion);
            Assert.AreEqual(6, _conn.AppendToStreamAsync(stream, ExpectedVersion.Any, events2).Result.NextExpectedVersion);

            var res = _conn.ReadStreamEventsForwardAsync(stream, 0, 100, false).Result;

            Assert.AreEqual(SliceReadStatus.Success, res.Status);
            Assert.AreEqual(6, res.LastEventNumber);
            Assert.AreEqual(5, res.Events.Length);
            Assert.AreEqual(events1.Concat(events2).Select(x => x.EventId), res.Events.Select(x => x.OriginalEvent.EventId));
            Assert.AreEqual(new[] { 2, 3, 4, 5, 6 }, res.Events.Select(x => x.OriginalEvent.EventNumber));

            var meta = _conn.GetStreamMetadataAsync(stream).Result;

            Assert.AreEqual(2, meta.StreamMetadata.TruncateBefore);
            Assert.AreEqual(1, meta.MetastreamVersion);
        }
コード例 #10
0
        public void soft_deleted_stream_allows_recreation_only_for_first_write()
        {
            const string stream = "soft_deleted_stream_allows_recreation_only_for_first_write";

            Assert.AreEqual(1, _conn.AppendToStreamAsync(stream, ExpectedVersion.NoStream, TestEvent.NewTestEvent(), TestEvent.NewTestEvent()).Result.NextExpectedVersion);
            _conn.DeleteStreamAsync(stream, 1).Wait();

            var events = new[] { TestEvent.NewTestEvent(), TestEvent.NewTestEvent(), TestEvent.NewTestEvent() };

            Assert.AreEqual(4, _conn.AppendToStreamAsync(stream, ExpectedVersion.NoStream, events).Result.NextExpectedVersion);
            Assert.That(() => _conn.AppendToStreamAsync(stream, ExpectedVersion.NoStream, TestEvent.NewTestEvent()).Wait(),
                        Throws.Exception.InstanceOf <AggregateException>()
                        .With.InnerException.InstanceOf <WrongExpectedVersionException>());

            var res = _conn.ReadStreamEventsForwardAsync(stream, 0, 100, false).Result;

            Assert.AreEqual(SliceReadStatus.Success, res.Status);
            Assert.AreEqual(4, res.LastEventNumber);
            Assert.AreEqual(3, res.Events.Length);
            Assert.AreEqual(events.Select(x => x.EventId), res.Events.Select(x => x.OriginalEvent.EventId));
            Assert.AreEqual(new[] { 2, 3, 4 }, res.Events.Select(x => x.OriginalEvent.EventNumber));

            var meta = _conn.GetStreamMetadataAsync(stream).Result;

            Assert.AreEqual(2, meta.StreamMetadata.TruncateBefore);
            Assert.AreEqual(1, meta.MetastreamVersion);
        }
コード例 #11
0
        public void soft_deleted_stream_can_be_hard_deleted()
        {
            const string stream = "soft_deleted_stream_can_be_deleted";

            Assert.AreEqual(1, _conn.AppendToStreamAsync(stream, ExpectedVersion.NoStream, TestEvent.NewTestEvent(), TestEvent.NewTestEvent()).Result.NextExpectedVersion);
            _conn.DeleteStreamAsync(stream, 1).Wait();
            _conn.DeleteStreamAsync(stream, ExpectedVersion.Any, hardDelete: true).Wait();

            var res = _conn.ReadStreamEventsForwardAsync(stream, 0, 100, false).Result;

            Assert.AreEqual(SliceReadStatus.StreamDeleted, res.Status);
            var meta = _conn.GetStreamMetadataAsync(stream).Result;

            Assert.AreEqual(true, meta.IsStreamDeleted);

            Assert.That(() => _conn.AppendToStreamAsync(stream, ExpectedVersion.Any, TestEvent.NewTestEvent()).Wait(),
                        Throws.Exception.InstanceOf <AggregateException>()
                        .With.InnerException.InstanceOf <StreamDeletedException>());
        }