protected void WriteMeta(string streamId, string login, string password, string metawriteRole)
 {
     Connection.SetStreamMetadata(streamId, ExpectedVersion.Any,
                                  metawriteRole == null
                                     ? StreamMetadata.Build()
                                     : StreamMetadata.Build().SetReadRole(metawriteRole)
                                  .SetWriteRole(metawriteRole)
                                  .SetMetadataReadRole(metawriteRole)
                                  .SetMetadataWriteRole(metawriteRole),
                                  login == null && password == null ? null : new UserCredentials(login, password));
 }
Example #2
0
        public void setting_empty_metadata_works()
        {
            const string stream = "setting_empty_metadata_works";

            _connection.SetStreamMetadata(stream, ExpectedVersion.EmptyStream, (byte[])null);

            var meta = _connection.GetStreamMetadataAsRawBytes(stream);

            Assert.AreEqual(stream, meta.Stream);
            Assert.AreEqual(false, meta.IsStreamDeleted);
            Assert.AreEqual(0, meta.MetastreamVersion);
            Assert.AreEqual(new byte[0], meta.StreamMetadata);
        }
Example #3
0
        public void after_setting_less_strict_max_count_read_stream_forward_reads_more_events()
        {
            var res = _connection.ReadStreamEventsForward(Stream, 0, 100, false);

            Assert.AreEqual(SliceReadStatus.Success, res.Status);
            Assert.AreEqual(3, res.Events.Length);
            Assert.AreEqual(_testEvents.Skip(2).Select(x => x.EventId).ToArray(),
                            res.Events.Select(x => x.Event.EventId).ToArray());

            _connection.SetStreamMetadata(Stream, 0, StreamMetadata.Build().SetMaxCount(4));

            res = _connection.ReadStreamEventsForward(Stream, 0, 100, false);
            Assert.AreEqual(SliceReadStatus.Success, res.Status);
            Assert.AreEqual(4, res.Events.Length);
            Assert.AreEqual(_testEvents.Skip(1).Select(x => x.EventId).ToArray(),
                            res.Events.Select(x => x.Event.EventId).ToArray());
        }
        private void SetCheckpointStreamMaxCount(int eventNumber)
        {
            if (eventNumber != 0)
            {
                return;
            }

            var metadata = StreamMetadata.Build().SetMaxCount(1);

            _eventStoreConnection.SetStreamMetadata(CheckpointStream, ExpectedVersion.Any, metadata, EventStoreCredentials.Default);
        }
        public override void SetUp()
        {
            base.SetUp();
            _node = new MiniNode(PathName, skipInitializeStandardUsersCheck: false);
            _node.Start();

            _conn = TestConnection.Create(_node.TcpEndPoint);
            _conn.Connect();
            _conn.SetStreamMetadata("$all", -1,
                                    StreamMetadata.Build().SetReadRole(SystemRoles.All),
                                    new UserCredentials(SystemUsers.Admin, SystemUsers.DefaultAdminPassword));
        }
        public override void SetUp()
        {
            base.SetUp();
            _node = new MiniNode(PathName, skipInitializeStandardUsersCheck: false);
            _node.Start();

            _conn = TestConnection.Create(_node.TcpEndPoint);
            _conn.Connect();
            _conn.SetStreamMetadata("$all", -1,
                                    StreamMetadata.Build().SetReadRole(SystemRoles.All),
                                    new UserCredentials(SystemUsers.Admin, SystemUsers.DefaultAdminPassword));
        }
        public override void TestFixtureSetUp()
        {
            base.TestFixtureSetUp();
            _node = new MiniNode(PathName, skipInitializeStandardUsersCheck: false);
            _node.Start();
            _conn = TestConnection.Create(_node.TcpEndPoint);
            _conn.Connect();
            _conn.SetStreamMetadata("$all", -1,
                                    StreamMetadata.Build().SetReadRole(SystemRoles.All),
                                    new UserCredentials(SystemUsers.Admin, SystemUsers.DefaultAdminPassword));

            _testEvents = Enumerable.Range(0, 20).Select(x => TestEvent.NewTestEvent(x.ToString())).ToArray();
            _conn.AppendToStream("stream", ExpectedVersion.EmptyStream, _testEvents);
        }
Example #8
0
        public override void SetUp()
        {
            base.SetUp();
            _node = new MiniNode(PathName);
            _node.Start();

            _connection = TestConnection.Create(_node.TcpEndPoint);
            _connection.Connect();

            _connection.SetStreamMetadata(Stream, ExpectedVersion.EmptyStream, StreamMetadata.Build().SetMaxCount(3));

            _testEvents = Enumerable.Range(0, 5).Select(x => TestEvent.NewTestEvent(data: x.ToString())).ToArray();
            _connection.AppendToStream(Stream, ExpectedVersion.EmptyStream, _testEvents);
        }
Example #9
0
        public override void TestFixtureSetUp()
        {
            base.TestFixtureSetUp();
            _node = new MiniNode(PathName, skipInitializeStandardUsersCheck: false);
            _node.Start();
            _conn = TestConnection.Create(_node.TcpEndPoint);
            _conn.Connect();
            _conn.SetStreamMetadata("$all", -1,
                                    StreamMetadata.Build().SetReadRole(SystemRoles.All),
                                    new UserCredentials(SystemUsers.Admin, SystemUsers.DefaultAdminPassword));

            _testEvents = Enumerable.Range(0, 20).Select(x => TestEvent.NewTestEvent(x.ToString())).ToArray();
            _conn.AppendToStream("stream", ExpectedVersion.EmptyStream, _testEvents);
        }
        public override void SetUp()
        {
            base.SetUp();
            _node = new MiniNode(PathName);
            _node.Start();

            _connection = TestConnection.Create(_node.TcpEndPoint);
            _connection.Connect();

            _connection.SetStreamMetadata(Stream, ExpectedVersion.EmptyStream, StreamMetadata.Build().SetMaxCount(3));

            _testEvents = Enumerable.Range(0, 5).Select(x => TestEvent.NewTestEvent(data: x.ToString())).ToArray();
            _connection.AppendToStream(Stream, ExpectedVersion.EmptyStream, _testEvents);
        }
Example #11
0
        public void soft_deleted_stream_when_recreated_preserves_metadata_except_truncatebefore()
        {
            const string stream = "soft_deleted_stream_when_recreated_preserves_metadata_except_truncatebefore";

            Assert.AreEqual(1, _conn.AppendToStream(stream, ExpectedVersion.NoStream, TestEvent.NewTestEvent(), TestEvent.NewTestEvent()).NextExpectedVersion);

            Assert.AreEqual(0, _conn.SetStreamMetadata(stream, ExpectedVersion.NoStream,
                                                       StreamMetadata.Build().SetTruncateBefore(int.MaxValue)
                                                       .SetMaxCount(100)
                                                       .SetDeleteRole("some-role")
                                                       .SetCustomProperty("key1", true)
                                                       .SetCustomProperty("key2", 17)
                                                       .SetCustomProperty("key3", "some value")).NextExpectedVersion);

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

            Assert.AreEqual(4, _conn.AppendToStream(stream, 1, events).NextExpectedVersion);

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

            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.GetStreamMetadata(stream);

            Assert.AreEqual(1, 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"));
        }
        public void setting_empty_metadata_works()
        {
            const string stream = "setting_empty_metadata_works";

            _connection.SetStreamMetadata(stream, ExpectedVersion.EmptyStream, StreamMetadata.Create());

            var meta = _connection.GetStreamMetadataAsRawBytes(stream);

            Assert.AreEqual(stream, meta.Stream);
            Assert.AreEqual(false, meta.IsStreamDeleted);
            Assert.AreEqual(0, meta.MetastreamVersion);
            Assert.AreEqual(Helper.UTF8NoBom.GetBytes("{}"), meta.StreamMetadata);
        }
        public override void TestFixtureSetUp()
        {
            base.TestFixtureSetUp();
            _node = new MiniNode(PathName, enableTrustedAuth: true);
            _node.Start();

            var userCreateEvent1 = new ManualResetEventSlim();

            _node.Node.MainQueue.Publish(
                new UserManagementMessage.Create(
                    new CallbackEnvelope(
                        m =>
            {
                Assert.IsTrue(m is UserManagementMessage.UpdateResult);
                var msg = (UserManagementMessage.UpdateResult)m;
                Assert.IsTrue(msg.Success);

                userCreateEvent1.Set();
            }), SystemAccount.Principal, "user1", "Test User 1", new string[0], "pa$$1"));

            var userCreateEvent2 = new ManualResetEventSlim();

            _node.Node.MainQueue.Publish(
                new UserManagementMessage.Create(
                    new CallbackEnvelope(
                        m =>
            {
                Assert.IsTrue(m is UserManagementMessage.UpdateResult);
                var msg = (UserManagementMessage.UpdateResult)m;
                Assert.IsTrue(msg.Success);

                userCreateEvent2.Set();
            }), SystemAccount.Principal, "user2", "Test User 2", new string[0], "pa$$2"));

            var adminCreateEvent2 = new ManualResetEventSlim();

            _node.Node.MainQueue.Publish(
                new UserManagementMessage.Create(
                    new CallbackEnvelope(
                        m =>
            {
                Assert.IsTrue(m is UserManagementMessage.UpdateResult);
                var msg = (UserManagementMessage.UpdateResult)m;
                Assert.IsTrue(msg.Success);

                adminCreateEvent2.Set();
            }), SystemAccount.Principal, "adm", "Administrator User", new[] { SystemRoles.Admins }, "admpa$$"));

            Assert.IsTrue(userCreateEvent1.Wait(120000), "User 1 creation failed");
            Assert.IsTrue(userCreateEvent2.Wait(120000), "User 2 creation failed");
            Assert.IsTrue(adminCreateEvent2.Wait(120000), "Administrator User creation failed");

            Connection = TestConnection.Create(_node.TcpEndPoint, TcpType.Normal, _userCredentials);
            Connection.Connect();

            Connection.SetStreamMetadata("noacl-stream", ExpectedVersion.NoStream, StreamMetadata.Build());
            Connection.SetStreamMetadata("read-stream", ExpectedVersion.NoStream, StreamMetadata.Build().SetReadRole("user1"));
            Connection.SetStreamMetadata("write-stream", ExpectedVersion.NoStream, StreamMetadata.Build().SetWriteRole("user1"));
            Connection.SetStreamMetadata("metaread-stream", ExpectedVersion.NoStream, StreamMetadata.Build().SetMetadataReadRole("user1"));
            Connection.SetStreamMetadata("metawrite-stream", ExpectedVersion.NoStream, StreamMetadata.Build().SetMetadataWriteRole("user1"));

            Connection.SetStreamMetadata("$all", ExpectedVersion.Any, StreamMetadata.Build().SetReadRole("user1"), new UserCredentials("adm", "admpa$$"));

            Connection.SetStreamMetadata("$system-acl", ExpectedVersion.NoStream,
                                         StreamMetadata.Build()
                                         .SetReadRole("user1")
                                         .SetWriteRole("user1")
                                         .SetMetadataReadRole("user1")
                                         .SetMetadataWriteRole("user1"), new UserCredentials("adm", "admpa$$"));
            Connection.SetStreamMetadata("$system-adm", ExpectedVersion.NoStream,
                                         StreamMetadata.Build()
                                         .SetReadRole(SystemRoles.Admins)
                                         .SetWriteRole(SystemRoles.Admins)
                                         .SetMetadataReadRole(SystemRoles.Admins)
                                         .SetMetadataWriteRole(SystemRoles.Admins), new UserCredentials("adm", "admpa$$"));

            Connection.SetStreamMetadata("normal-all", ExpectedVersion.NoStream,
                                         StreamMetadata.Build()
                                         .SetReadRole(SystemRoles.All)
                                         .SetWriteRole(SystemRoles.All)
                                         .SetMetadataReadRole(SystemRoles.All)
                                         .SetMetadataWriteRole(SystemRoles.All));
            Connection.SetStreamMetadata("$system-all", ExpectedVersion.NoStream,
                                         StreamMetadata.Build()
                                         .SetReadRole(SystemRoles.All)
                                         .SetWriteRole(SystemRoles.All)
                                         .SetMetadataReadRole(SystemRoles.All)
                                         .SetMetadataWriteRole(SystemRoles.All), new UserCredentials("adm", "admpa$$"));
        }
        public void read_event_respects_truncatebefore()
        {
            const string stream = "read_event_respects_truncatebefore";

            _connection.AppendToStream(stream, ExpectedVersion.EmptyStream, _testEvents);

            _connection.SetStreamMetadata(stream, ExpectedVersion.EmptyStream, StreamMetadata.Build().SetTruncateBefore(2));

            var res = _connection.ReadEvent(stream, 1, false);

            Assert.AreEqual(EventReadStatus.NotFound, res.Status);

            res = _connection.ReadEvent(stream, 2, false);
            Assert.AreEqual(EventReadStatus.Success, res.Status);
            Assert.AreEqual(_testEvents[2].EventId, res.Event.Value.OriginalEvent.EventId);
        }