public void recovery_is_called_with_correct_node_id()
        {
            RecoveryResult result;

            LiveProducer.SetLastTimestampBeforeDisconnect(DateTime.MinValue);
            var operation = new RecoveryOperation(LiveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.LiveMessagesOnly }, 0, false);

            operation.Start();
            _recoveryRequestIssuerMock.Verify(x => x.RequestFullOddsRecoveryAsync(It.IsAny <IProducer>(), 0), Times.Once);
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out result));

            LiveProducer.SetLastTimestampBeforeDisconnect(TimeProviderAccessor.Current.Now - TimeSpan.FromHours(1));
            operation.Start();
            _recoveryRequestIssuerMock.Verify(x => x.RequestRecoveryAfterTimestampAsync(It.IsAny <IProducer>(), It.IsAny <DateTime>(), 0), Times.Once);
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out result));

            LiveProducer.SetLastTimestampBeforeDisconnect(DateTime.MinValue);
            operation = new RecoveryOperation(LiveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.LiveMessagesOnly }, 7, false);
            operation.Start();
            _recoveryRequestIssuerMock.Verify(x => x.RequestFullOddsRecoveryAsync(It.IsAny <IProducer>(), 7), Times.Once);
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out result));

            LiveProducer.SetLastTimestampBeforeDisconnect(TimeProviderAccessor.Current.Now - TimeSpan.FromHours(1));
            operation.Start();
            _recoveryRequestIssuerMock.Verify(x => x.RequestRecoveryAfterTimestampAsync(It.IsAny <IProducer>(), It.IsAny <DateTime>(), 7), Times.Once);
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out result));
        }
示例#2
0
        public void RecoveryIsCalledWithCorrectNodeId()
        {
            _liveProducer.SetLastTimestampBeforeDisconnect(DateTime.MinValue);
            var operation = new RecoveryOperation(_liveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.LiveMessagesOnly }, 0, true);

            operation.Start();
            _recoveryRequestIssuerMock.Verify(x => x.RequestFullOddsRecoveryAsync(It.IsAny <IProducer>(), 0), Times.Once);
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out _));

            _liveProducer.SetLastTimestampBeforeDisconnect(TimeProviderAccessor.Current.Now - TimeSpan.FromHours(1));
            operation.Start();
            _recoveryRequestIssuerMock.Verify(x => x.RequestRecoveryAfterTimestampAsync(It.IsAny <IProducer>(), It.IsAny <DateTime>(), 0), Times.Once);
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out _));

            // resetting timestamp
            var liveProducer2 = new Producer(1, "LO", "Live Odds", "https://api.betradar.com/v1/liveodds/", true, 20, 1800, "live", 600);

            operation = new RecoveryOperation(liveProducer2, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.LiveMessagesOnly }, 7, false);
            operation.Start();
            _recoveryRequestIssuerMock.Verify(x => x.RequestFullOddsRecoveryAsync(It.IsAny <IProducer>(), 7), Times.Once);
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out _));

            liveProducer2.SetLastTimestampBeforeDisconnect(TimeProviderAccessor.Current.Now - TimeSpan.FromHours(1));
            operation.Start();
            _recoveryRequestIssuerMock.Verify(x => x.RequestRecoveryAfterTimestampAsync(It.IsAny <IProducer>(), It.IsAny <DateTime>(), 7), Times.Once);
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out _));
        }
示例#3
0
        public void WorksCorrectWithHiAndLowSession()
        {
            var operation = new RecoveryOperation(_liveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.HighPriorityMessages, MessageInterest.LowPriorityMessages }, 0, false);

            operation.Start();

            Assert.IsFalse(operation.TryComplete(MessageInterest.LowPriorityMessages, out var result));
            Assert.IsNull(result);

            Assert.IsTrue(operation.TryComplete(MessageInterest.HighPriorityMessages, out result));
            Assert.IsNotNull(result);
        }
        public void works_ok_with_hi_and_low_interests()
        {
            var operation = new RecoveryOperation(LiveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.HighPriorityMessages, MessageInterest.LowPriorityMessages }, 0, false);

            operation.Start();

            RecoveryResult result;

            Assert.IsFalse(operation.TryComplete(MessageInterest.LowPriorityMessages, out result));
            Assert.IsNull(result);

            Assert.IsTrue(operation.TryComplete(MessageInterest.HighPriorityMessages, out result));
            Assert.IsNotNull(result);
        }
示例#5
0
        public void WorksCorrectWhenUsingScopes()
        {
            var operation = new RecoveryOperation(_premiumCricketProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.PrematchMessagesOnly, MessageInterest.LiveMessagesOnly }, 0, false);

            operation.Start();
            Assert.IsFalse(operation.TryComplete(MessageInterest.LiveMessagesOnly, out _));
            Assert.IsTrue(operation.TryComplete(MessageInterest.PrematchMessagesOnly, out _));

            operation = new RecoveryOperation(_premiumCricketProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.PrematchMessagesOnly, MessageInterest.LiveMessagesOnly, MessageInterest.VirtualSportMessages }, 0, false);
            operation.Start();
            Assert.IsFalse(operation.TryComplete(MessageInterest.PrematchMessagesOnly, out _));
            Assert.IsFalse(operation.TryComplete(MessageInterest.VirtualSportMessages, out _));
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out _));
        }
        public void works_correct_when_using_scopes()
        {
            RecoveryResult    result;
            RecoveryOperation operation;

            operation = new RecoveryOperation(PremiumCricketProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.PrematchMessagesOnly, MessageInterest.LiveMessagesOnly }, 0, false);
            operation.Start();
            Assert.IsFalse(operation.TryComplete(MessageInterest.LiveMessagesOnly, out result));
            Assert.IsTrue(operation.TryComplete(MessageInterest.PrematchMessagesOnly, out result));

            operation = new RecoveryOperation(PremiumCricketProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.PrematchMessagesOnly, MessageInterest.LiveMessagesOnly, MessageInterest.VirtualSportMessages }, 0, false);
            operation.Start();
            Assert.IsFalse(operation.TryComplete(MessageInterest.PrematchMessagesOnly, out result));
            Assert.IsFalse(operation.TryComplete(MessageInterest.VirtualSportMessages, out result));
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out result));
        }
示例#7
0
        public void CorrectRecoveryOperationIsInvoked()
        {
            _liveProducer.SetLastTimestampBeforeDisconnect(DateTime.MinValue);
            var operation = new RecoveryOperation(_liveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.LiveMessagesOnly }, 0, false);

            operation.Start();
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out _));

            _liveProducer.SetLastTimestampBeforeDisconnect(TimeProviderAccessor.Current.Now - TimeSpan.FromMinutes(10));

            operation.Start();
            _recoveryRequestIssuerMock.Verify(x => x.RequestRecoveryAfterTimestampAsync(It.IsAny <IProducer>(), It.IsAny <DateTime>(), 0), Times.Once);
            _recoveryRequestIssuerMock.Verify(x => x.RequestFullOddsRecoveryAsync(It.IsAny <IProducer>(), 0), Times.Once);

            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out _));
        }
示例#8
0
        public void RecoveryIsCalledWithCorrectAdjustedAfter()
        {
            var operation = new RecoveryOperation(_liveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.LiveMessagesOnly }, 0, true);

            _liveProducer.SetLastTimestampBeforeDisconnect(TimeProviderAccessor.Current.Now - TimeSpan.FromMinutes(321));
            operation.Start();
            _recoveryRequestIssuerMock.Verify(x => x.RequestRecoveryAfterTimestampAsync(It.IsAny <IProducer>(), _liveProducer.LastTimestampBeforeDisconnect, 0), Times.Once);
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out _));

            _liveProducer.SetLastTimestampBeforeDisconnect(TimeProviderAccessor.Current.Now - TimeSpan.FromMinutes(90));
            operation.Start();
            _recoveryRequestIssuerMock.Verify(x => x.RequestRecoveryAfterTimestampAsync(It.IsAny <IProducer>(), _liveProducer.LastTimestampBeforeDisconnect, 0), Times.Once);
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out _));

            _liveProducer.SetLastTimestampBeforeDisconnect(TimeProviderAccessor.Current.Now - TimeSpan.FromMinutes(10));
            operation.Start();
            _recoveryRequestIssuerMock.Verify(x => x.RequestRecoveryAfterTimestampAsync(It.IsAny <IProducer>(), _liveProducer.LastTimestampBeforeDisconnect, 0), Times.Once);
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out _));
        }
        public void recovery_is_called_with_correct_after()
        {
            RecoveryResult result;
            var            operation = new RecoveryOperation(LiveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.LiveMessagesOnly }, 0, false);

            LiveProducer.SetLastTimestampBeforeDisconnect(TimeProviderAccessor.Current.Now - TimeSpan.FromMinutes(10));
            operation.Start();
            _recoveryRequestIssuerMock.Verify(x => x.RequestRecoveryAfterTimestampAsync(It.IsAny <IProducer>(), LiveProducer.LastTimestampBeforeDisconnect, 0), Times.Once);
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out result));

            LiveProducer.SetLastTimestampBeforeDisconnect(TimeProviderAccessor.Current.Now - TimeSpan.FromMinutes(90));
            operation.Start();
            _recoveryRequestIssuerMock.Verify(x => x.RequestRecoveryAfterTimestampAsync(It.IsAny <IProducer>(), LiveProducer.LastTimestampBeforeDisconnect, 0), Times.Once);
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out result));

            LiveProducer.SetLastTimestampBeforeDisconnect(TimeProviderAccessor.Current.Now - TimeSpan.FromMinutes(321));
            operation.Start();
            _recoveryRequestIssuerMock.Verify(x => x.RequestRecoveryAfterTimestampAsync(It.IsAny <IProducer>(), LiveProducer.LastTimestampBeforeDisconnect, 0), Times.Once);
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out result));
        }
示例#10
0
        public void OperationCanBeReused()
        {
            var operation = new RecoveryOperation(_liveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.LiveMessagesOnly }, 0, false);

            operation.Start();
            _timeProvider.AddSeconds(60);
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out _));

            _timeProvider.AddSeconds(1800);
            operation.Start();
            _timeProvider.AddSeconds(120);
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out _));

            operation.Start();
            _timeProvider.AddSeconds(_liveProducer.MaxRecoveryTime + 1);
            Assert.IsTrue(operation.HasTimedOut());
            Assert.IsNotNull(operation.CompleteTimedOut());

            _timeProvider.AddSeconds(10);
            operation.Start();
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out _));
        }
示例#11
0
        public void FirstInterruptTimeIsRecorded()
        {
            var operation = new RecoveryOperation(_liveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.AllMessages }, 0, false);

            operation.Start();

            _timeProvider.AddSeconds(60);
            var interruptTime = _timeProvider.Now;

            operation.Interrupt(interruptTime);


            _timeProvider.AddSeconds(60);
            operation.Interrupt(_timeProvider.Now);

            operation.TryComplete(MessageInterest.AllMessages, out var result);
            Assert.IsNotNull(result);
            Assert.AreEqual(result.InterruptedAt, interruptTime);
        }
        public void works_correct_with_only_one_session()
        {
            RecoveryResult    result;
            RecoveryOperation operation;

            operation = new RecoveryOperation(LiveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.AllMessages }, 0, false);
            operation.Start();
            Assert.IsTrue(operation.TryComplete(MessageInterest.AllMessages, out result));

            operation = new RecoveryOperation(LiveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.LiveMessagesOnly }, 0, false);
            operation.Start();
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out result));

            operation = new RecoveryOperation(LiveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.PrematchMessagesOnly }, 0, false);
            operation.Start();
            Assert.IsTrue(operation.TryComplete(MessageInterest.PrematchMessagesOnly, out result));

            operation = new RecoveryOperation(LiveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.VirtualSportMessages }, 0, false);
            operation.Start();
            Assert.IsTrue(operation.TryComplete(MessageInterest.VirtualSportMessages, out result));

            operation = new RecoveryOperation(LiveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.HighPriorityMessages }, 0, false);
            operation.Start();
            Assert.IsTrue(operation.TryComplete(MessageInterest.HighPriorityMessages, out result));

            operation = new RecoveryOperation(LiveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.LowPriorityMessages }, 0, false);
            operation.Start();
            Assert.IsTrue(operation.TryComplete(MessageInterest.LowPriorityMessages, out result));

            operation = new RecoveryOperation(LiveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.AllMessages }, 0, false);
            operation.Start();
            Assert.IsFalse(operation.TryComplete(MessageInterest.LiveMessagesOnly, out result));
            Assert.IsFalse(operation.TryComplete(MessageInterest.PrematchMessagesOnly, out result));
            Assert.IsFalse(operation.TryComplete(MessageInterest.VirtualSportMessages, out result));
            Assert.IsFalse(operation.TryComplete(MessageInterest.HighPriorityMessages, out result));
            Assert.IsFalse(operation.TryComplete(MessageInterest.LowPriorityMessages, out result));
            Assert.IsTrue(operation.TryComplete(MessageInterest.AllMessages, out result));
        }
示例#13
0
        public void ValuesAfterCompletionAreCorrect()
        {
            var operation = new RecoveryOperation(_liveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.AllMessages }, 0, false);

            operation.Start();
            var startTime = _timeProvider.Now;

            _timeProvider.AddSeconds(60);

            var completed = operation.TryComplete(MessageInterest.AllMessages, out var result);

            Assert.IsTrue(completed);
            Assert.IsNotNull(result);

            Assert.IsTrue(result.Success);
            Assert.AreEqual(1, result.RequestId);
            Assert.AreEqual(startTime, result.StartTime);
            Assert.IsNull(result.InterruptedAt);
            Assert.IsFalse(result.TimedOut);

            Assert.IsFalse(operation.IsRunning);
            Assert.IsNull(operation.RequestId);
        }
示例#14
0
        public void WorksCorrectWithOnlyOneSession()
        {
            var operation = new RecoveryOperation(_liveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.AllMessages }, 0, false);

            operation.Start();
            Assert.IsTrue(operation.TryComplete(MessageInterest.AllMessages, out _));

            operation = new RecoveryOperation(_liveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.LiveMessagesOnly }, 0, false);
            operation.Start();
            Assert.IsTrue(operation.TryComplete(MessageInterest.LiveMessagesOnly, out _));

            operation = new RecoveryOperation(_liveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.PrematchMessagesOnly }, 0, false);
            operation.Start();
            Assert.IsTrue(operation.TryComplete(MessageInterest.PrematchMessagesOnly, out _));

            operation = new RecoveryOperation(_liveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.VirtualSportMessages }, 0, false);
            operation.Start();
            Assert.IsTrue(operation.TryComplete(MessageInterest.VirtualSportMessages, out _));

            operation = new RecoveryOperation(_liveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.HighPriorityMessages }, 0, false);
            operation.Start();
            Assert.IsTrue(operation.TryComplete(MessageInterest.HighPriorityMessages, out _));

            operation = new RecoveryOperation(_liveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.LowPriorityMessages }, 0, false);
            operation.Start();
            Assert.IsTrue(operation.TryComplete(MessageInterest.LowPriorityMessages, out _));

            operation = new RecoveryOperation(_liveProducer, _recoveryRequestIssuerMock.Object, new[] { MessageInterest.AllMessages }, 0, false);
            operation.Start();
            Assert.IsFalse(operation.TryComplete(MessageInterest.LiveMessagesOnly, out _));
            Assert.IsFalse(operation.TryComplete(MessageInterest.PrematchMessagesOnly, out _));
            Assert.IsFalse(operation.TryComplete(MessageInterest.VirtualSportMessages, out _));
            Assert.IsFalse(operation.TryComplete(MessageInterest.HighPriorityMessages, out _));
            Assert.IsFalse(operation.TryComplete(MessageInterest.LowPriorityMessages, out _));
            Assert.IsTrue(operation.TryComplete(MessageInterest.AllMessages, out _));
        }