Exemple #1
0
        public void should_not_be_able_to_read_event_from_stream_forward()
        {
            var readResult = ReplicationTestHelper.ReadStreamEventsForward(_liveNode, _streamId);

            Assert.AreEqual(1, readResult.Events.Count());
            Assert.AreEqual(ReadStreamResult.Success, readResult.Result);
        }
Exemple #2
0
        public void should_be_able_to_read_event_from_stream_backward_on_master()
        {
            var readResult = ReplicationTestHelper.ReadStreamEventsBackward(GetMaster(), _streamId);

            Assert.AreEqual(ReadStreamResult.Success, readResult.Result);
            Assert.AreEqual(1, readResult.Events.Count());
        }
Exemple #3
0
        public void should_be_able_to_read_event_on_slaves()
        {
            var slaves = GetSlaves();

            foreach (var s in slaves)
            {
                var readResult = ReplicationTestHelper.ReadEvent(s, _streamId, 0);
                Assert.AreEqual(ReadEventResult.Success, readResult.Result);
            }
        }
Exemple #4
0
        public void should_be_able_to_read_event_from_all_backward_on_slaves()
        {
            var slaves = GetSlaves();

            foreach (var s in slaves)
            {
                var readResult = ReplicationTestHelper.ReadAllEventsBackward(s, _commitPosition);
                Assert.AreEqual(1, readResult.Events.Where(x => x.OriginalStreamId == _streamId).Count());
            }
        }
Exemple #5
0
        public void should_be_able_to_read_event_from_stream_backward_on_slaves()
        {
            var slaves = GetSlaves();

            foreach (var s in slaves)
            {
                var readResult = ReplicationTestHelper.ReadStreamEventsBackward(s, _streamId);
                Assert.AreEqual(1, readResult.Events.Count());
                Assert.AreEqual(ReadStreamResult.Success, readResult.Result);
            }
        }
        public void should_be_able_to_read_event_from_stream_backward_on_slaves()
        {
            var slaves          = GetSlaves();
            var quorum          = (slaves.Count() + 1) / 2 + 1;
            var successfulReads = 0;

            foreach (var s in slaves)
            {
                var readResult = ReplicationTestHelper.ReadStreamEventsBackward(s, _streamId);
                successfulReads += readResult.Events.Count();
            }

            Assert.GreaterOrEqual(successfulReads, quorum - 1);
        }
        public void should_be_able_to_read_event_on_slaves()
        {
            var slaves          = GetSlaves();
            var quorum          = (slaves.Count() + 1) / 2 + 1;
            var successfulReads = 0;

            foreach (var s in slaves)
            {
                var readResult = ReplicationTestHelper.ReadEvent(s, _streamId, 0);
                successfulReads += readResult.Result == ReadEventResult.Success?1:0;
            }

            Assert.GreaterOrEqual(successfulReads, quorum - 1);
        }
        public void should_be_able_to_read_event_from_all_backward_on_slaves()
        {
            var slaves          = GetSlaves();
            var quorum          = (slaves.Count() + 1) / 2 + 1;
            var successfulReads = 0;

            foreach (var s in slaves)
            {
                var readResult = ReplicationTestHelper.ReadAllEventsBackward(s, _commitPosition);
                successfulReads += readResult.Events.Where(x => x.OriginalStreamId == _streamId).Count();
            }

            Assert.GreaterOrEqual(successfulReads, quorum - 1);
        }
Exemple #9
0
        protected override async Task Given()
        {
            _expectedNumberOfRoleAssignments.Wait(5000);

            var leader = GetLeader();

            Assert.IsNotNull(leader, "Could not get leader node");

            // Set the checkpoint so the check is not skipped
            leader.Db.Config.ReplicationCheckpoint.Write(0);

            _subscriptionsConfirmed = new CountdownEvent(3);
            _leaderSubscription     = new TestSubscription <TLogFormat, TStreamId>(leader, 1, _streamId, _subscriptionsConfirmed);
            _leaderSubscription.CreateSubscription();

            _followerSubscriptions = new List <TestSubscription <TLogFormat, TStreamId> >();
            var followers = GetFollowers();

            foreach (var s in followers)
            {
                var followerSubscription = new TestSubscription <TLogFormat, TStreamId>(s, 1, _streamId, _subscriptionsConfirmed);
                _followerSubscriptions.Add(followerSubscription);
                followerSubscription.CreateSubscription();
            }

            if (!_subscriptionsConfirmed.Wait(_timeout))
            {
                Assert.Fail("Timed out waiting for subscriptions to confirm");
            }

            var events      = new Event[] { new Event(Guid.NewGuid(), "test-type", false, new byte[10], new byte[0]) };
            var writeResult = ReplicationTestHelper.WriteEvent(leader, events, _streamId);

            Assert.AreEqual(OperationResult.Success, writeResult.Result);

            await base.Given();

            var replicas = GetFollowers();

            AssertEx.IsOrBecomesTrue(
                () => {
                var leaderIndex = leader.Db.Config.IndexCheckpoint.Read();
                return(replicas[0].Db.Config.IndexCheckpoint.Read() == leaderIndex &&
                       replicas[1].Db.Config.IndexCheckpoint.Read() == leaderIndex);
            },
                timeout: TimeSpan.FromSeconds(2));
        }
Exemple #10
0
        protected override void Given()
        {
            _expectedNumberOfRoleAssignments.Wait(5000);

            var master = GetMaster();

            Assert.IsNotNull(master, "Could not get master node");

            var events      = new Event[] { new Event(Guid.NewGuid(), "test-type", false, new byte[10], new byte[0]) };
            var writeResult = ReplicationTestHelper.WriteEvent(master, events, _streamId);

            Assert.AreEqual(OperationResult.Success, writeResult.Result);
            _commitPosition = writeResult.CommitPosition;

            // Set checkpoint to starting value
            master.Db.Config.ReplicationCheckpoint.Write(-1);
            base.Given();
        }
        protected override void Given()
        {
            _expectedNumberOfRoleAssignments.Wait(5000);

            var master = GetMaster();

            Assert.IsNotNull(master, "Could not get master node");

            // Set the checkpoint so the check is not skipped
            master.Db.Config.ReplicationCheckpoint.Write(0);

            var events      = new Event[] { new Event(Guid.NewGuid(), "test-type", false, new byte[10], new byte[0]) };
            var writeResult = ReplicationTestHelper.WriteEvent(master, events, _streamId);

            Assert.AreEqual(OperationResult.Success, writeResult.Result);
            _commitPosition = writeResult.CommitPosition;

            Assert.IsTrue(_commitPosition <= GetMaster().Db.Config.ReplicationCheckpoint.ReadNonFlushed(),
                          "Replication checkpoint should be greater than event commit position");
            base.Given();
        }
Exemple #12
0
        protected override async Task Given()
        {
            _expectedNumberOfRoleAssignments.Wait(5000);

            _liveNode = GetMaster();
            Assert.IsNotNull(_liveNode, "Could not get master node");

            var events      = new Event[] { new Event(Guid.NewGuid(), "test-type", false, new byte[10], new byte[0]) };
            var writeResult = ReplicationTestHelper.WriteEvent(_liveNode, events, _streamId);

            Assert.AreEqual(OperationResult.Success, writeResult.Result);
            _commitPosition = writeResult.CommitPosition;

            var slaves = GetSlaves();

            foreach (var s in slaves)
            {
                await ShutdownNode(s.DebugIndex);
            }

            await base.Given();
        }
        protected override void Given()
        {
            _expectedNumberOfRoleAssignments.Wait(5000);

            var master = GetMaster();

            Assert.IsNotNull(master, "Could not get master node");

            // Set the checkpoint so the check is not skipped
            master.Db.Config.ReplicationCheckpoint.Write(0);

            _subscriptionsConfirmed = new CountdownEvent(3);
            _masterSubscription     = new TestSubscription(master, 1, _streamId, _subscriptionsConfirmed);
            _masterSubscription.CreateSubscription();

            _slaveSubscriptions = new List <TestSubscription>();
            var slaves = GetSlaves();

            foreach (var s in slaves)
            {
                var slaveSubscription = new TestSubscription(s, 1, _streamId, _subscriptionsConfirmed);
                _slaveSubscriptions.Add(slaveSubscription);
                slaveSubscription.CreateSubscription();
            }

            if (!_subscriptionsConfirmed.Wait(_timeout))
            {
                Assert.Fail("Timed out waiting for subscriptions to confirm");
            }

            var events      = new Event[] { new Event(Guid.NewGuid(), "test-type", false, new byte[10], new byte[0]) };
            var writeResult = ReplicationTestHelper.WriteEvent(master, events, _streamId);

            Assert.AreEqual(OperationResult.Success, writeResult.Result);

            base.Given();
        }
Exemple #14
0
        public void should_be_able_to_read_event_on_master()
        {
            var readResult = ReplicationTestHelper.ReadEvent(GetMaster(), _streamId, 0);

            Assert.AreEqual(ReadEventResult.Success, readResult.Result);
        }
Exemple #15
0
        public void should_not_be_able_to_read_event()
        {
            var readResult = ReplicationTestHelper.ReadEvent(_liveNode, _streamId, 0);

            Assert.AreEqual(ReadEventResult.Success, readResult.Result);
        }
Exemple #16
0
        public void should_be_able_to_read_event_from_all_backward_on_master()
        {
            var readResult = ReplicationTestHelper.ReadAllEventsBackward(GetMaster(), _commitPosition);

            Assert.AreEqual(1, readResult.Events.Where(x => x.OriginalStreamId == _streamId).Count());
        }
Exemple #17
0
        public void should_be_able_to_read_event_from_all_forward()
        {
            var readResult = ReplicationTestHelper.ReadAllEventsForward(_liveNode, _commitPosition);

            Assert.AreEqual(1, readResult.Events.Where(x => x.OriginalStreamId == _streamId).Count());
        }