Exemple #1
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));
        }
        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();
        }