示例#1
0
        public void correct_timestamp_is_used_when_recovery_is_interrupted_do_to_unsubscribed_alive()
        {
            var recoveryOperationMock = new Mock <IRecoveryOperation>();

            recoveryOperationMock.Setup(x => x.Start()).Returns(true);
            _producerRecoveryManager = new ProducerRecoveryManager(_producer, recoveryOperationMock.Object, _timestampTracker);

            //start the recovery
            _producerRecoveryManager.ProcessSystemMessage(_messageBuilder.BuildAlive());
            Assert.AreEqual(_producerRecoveryManager.Status, ProducerRecoveryStatus.Started);
            //make sure that after the the recoveryOperationMock IsRunning returns true
            recoveryOperationMock.Setup(x => x.IsRunning).Returns(true);

            //let's go over few normal cycles without user messages
            _producerRecoveryManager.CheckStatus();
            _producerRecoveryManager.ProcessSystemMessage(_messageBuilder.BuildAlive());
            _timeProvider.AddSeconds(10);
            _producerRecoveryManager.CheckStatus();
            var lastAlive = _messageBuilder.BuildAlive();

            _producerRecoveryManager.ProcessSystemMessage(lastAlive);

            // let's feed the recovery manager with unsubscribed alive
            _timeProvider.AddSeconds(10);
            var unsubscribedAlive = _messageBuilder.BuildAlive();

            unsubscribedAlive.subscribed = 0;
            _producerRecoveryManager.ProcessSystemMessage(unsubscribedAlive);
            recoveryOperationMock.Verify(x => x.Interrupt(SdkInfo.FromEpochTime(lastAlive.timestamp)), Times.Once);
            Assert.AreEqual(ProducerRecoveryStatus.Started, _producerRecoveryManager.Status);
        }
        public void recovery_is_started_after_connection_is_back()
        {
            _timeProvider.Now = new DateTime(2000, 1, 1, 12, 0, 0);
            var disconnectedTime = _timeProvider.Now - TimeSpan.FromHours(2);

            _producer.SetLastTimestampBeforeDisconnect(disconnectedTime);

            var recoveryOperation = new RecoveryOperation(_producer, _recoveryRequestIssuerMock.Object, new[] { DefaultInterest }, 0, false);
            var recoveryManager   = new ProducerRecoveryManager(_producer, recoveryOperation, _timestampTracker, 30);

            recoveryManager.ProcessSystemMessage(_messageBuilder.BuildAlive());
            _recoveryRequestIssuerMock.Verify(x => x.RequestRecoveryAfterTimestampAsync(_producer, disconnectedTime, 0), Times.Once);
            Assert.AreEqual(ProducerRecoveryStatus.Started, recoveryManager.Status);
            Debug.Assert(recoveryOperation.RequestId != null, "recoveryOperation.RequestId != null");
            recoveryManager.ProcessUserMessage(_messageBuilder.BuildSnapshotComplete(recoveryOperation.RequestId.Value), DefaultInterest);
            Assert.AreEqual(ProducerRecoveryStatus.Completed, recoveryManager.Status);
            recoveryManager.ProcessUserMessage(_messageBuilder.BuildAlive(_producer.Id, _timeProvider.Now), DefaultInterest);

            recoveryManager.ConnectionShutdown();
            Assert.AreEqual(ProducerRecoveryStatus.Error, recoveryManager.Status);
            recoveryManager.ConnectionRecovered();
            var time = _timeProvider.Now;

            _timeProvider.AddSeconds(40);
            recoveryManager.ProcessSystemMessage(_messageBuilder.BuildAlive());
            Assert.AreEqual(ProducerRecoveryStatus.Started, recoveryManager.Status);
            _recoveryRequestIssuerMock.Verify(x => x.RequestRecoveryAfterTimestampAsync(_producer, time, 0));
        }
示例#3
0
        public void recovery_is_restarted_after_connection_is_shutdown()
        {
            var recoveryOperationMock = new Mock <IRecoveryOperation>();

            recoveryOperationMock.Setup(x => x.Start()).Returns(true);
            _producerRecoveryManager = new ProducerRecoveryManager(_producer, recoveryOperationMock.Object, _timestampTracker);
            _producerRecoveryManager.ProcessSystemMessage(_messageBuilder.BuildAlive());
            Assert.AreEqual(ProducerRecoveryStatus.Started, _producerRecoveryManager.Status);
            recoveryOperationMock.Verify(x => x.Start(), Times.Once);
            _producerRecoveryManager.ConnectionShutdown();
            Assert.AreEqual(ProducerRecoveryStatus.Error, _producerRecoveryManager.Status);
            recoveryOperationMock.Verify(x => x.Reset(), Times.Once);
            _producerRecoveryManager.ProcessSystemMessage(_messageBuilder.BuildAlive());
            recoveryOperationMock.Verify(x => x.Start(), Times.Exactly(2));
        }
示例#4
0
        public void received_messages_invoke_correct_method_on_timestamp_tracker()
        {
            var timestampTrackerMock = new Mock <ITimestampTracker>();

            _producerRecoveryManager = new ProducerRecoveryManager(_producer, new Mock <IRecoveryOperation>().Object, timestampTrackerMock.Object);

            var userAlive = _messageBuilder.BuildAlive();

            _producerRecoveryManager.ProcessUserMessage(userAlive, DefaultInterest);
            timestampTrackerMock.Verify(x => x.ProcessUserMessage(DefaultInterest, userAlive), Times.Once);

            var systemAlive = _messageBuilder.BuildAlive();

            _producerRecoveryManager.ProcessSystemMessage(systemAlive);
            timestampTrackerMock.Verify(x => x.ProcessSystemAlive(systemAlive), Times.Once);

            var betStop = _messageBuilder.BuildBetStop();

            _producerRecoveryManager.ProcessUserMessage(betStop, DefaultInterest);
            timestampTrackerMock.Verify(x => x.ProcessUserMessage(DefaultInterest, betStop), Times.Once);

            var oddsChange = _messageBuilder.BuildOddsChange();

            _producerRecoveryManager.ProcessUserMessage(oddsChange, DefaultInterest);
            timestampTrackerMock.Verify(x => x.ProcessUserMessage(DefaultInterest, oddsChange), Times.Once);
        }
示例#5
0
        public void behaves_correctly_when_in_not_started_state()
        {
            _producerRecoveryManager.CheckStatus();
            Assert.AreEqual(_producerRecoveryManager.Status, ProducerRecoveryStatus.NotStarted);
            _producerRecoveryManager.ProcessUserMessage(_messageBuilder.BuildAlive(), MessageInterest.AllMessages);
            Assert.AreEqual(ProducerRecoveryStatus.NotStarted, _producerRecoveryManager.Status);
            _producerRecoveryManager.ProcessUserMessage(_messageBuilder.BuildBetStop(), DefaultInterest);
            Assert.AreEqual(ProducerRecoveryStatus.NotStarted, _producerRecoveryManager.Status);
            _producerRecoveryManager.ProcessUserMessage(_messageBuilder.BuildOddsChange(), DefaultInterest);
            Assert.AreEqual(ProducerRecoveryStatus.NotStarted, _producerRecoveryManager.Status);
            _producerRecoveryManager.ProcessUserMessage(_messageBuilder.BuildSnapshotComplete(1), DefaultInterest);
            Assert.AreEqual(ProducerRecoveryStatus.NotStarted, _producerRecoveryManager.Status);
            _producerRecoveryManager.ProcessSystemMessage(_messageBuilder.BuildAlive());
            Assert.AreEqual(ProducerRecoveryStatus.Started, _producerRecoveryManager.Status);
            _timeProvider.AddSeconds(30);
            _producerRecoveryManager.CheckStatus();
            Assert.AreEqual(ProducerRecoveryStatus.Started, _producerRecoveryManager.Status);

            //get everything to default state
            CreateTestInstances();
            // alive from wrong producer does nothing ...
            _producerRecoveryManager.ProcessSystemMessage(_messageBuilder.BuildAlive(5));
            Assert.AreEqual(ProducerRecoveryStatus.NotStarted, _producerRecoveryManager.Status);
            // non-subscribed alive changes state
            _producerRecoveryManager.ProcessSystemMessage(_messageBuilder.BuildAlive(null, null, false));
            Assert.AreEqual(ProducerRecoveryStatus.Started, _producerRecoveryManager.Status);
        }