public void OnCompleted_WhenRecoveredEqualsToTotalForAllFiles()
        {
            var elastickClientMock = ElastickClientMock(RecoveryStatusFixture("test", 1, 1));

            var sut = new RestoreStatusHumbleObject(elastickClientMock.Object,
                                                    RestoreRequestFixture());

            sut.Next      += (sender, args) => Assert.Fail();
            sut.Completed += (sender, args) => Assert.NotNull(args.RecoveryStatusResponse);
            sut.Error     += (sender, args) => Assert.Fail(args.Exception.Message);

            sut.CheckStatus();
        }
        public void OnNext_WhenRecoveredLessThanTotalForAllFiles()
        {
            var elastickClientMock = ElastickClientMock(RecoveryStatusFixture("test", 1, 2));

            var sut = new RestoreStatusHumbleObject(elastickClientMock.Object,
                                                    RestoreRequestFixture());

            sut.Next      += (sender, args) => Assert.AreEqual(1, args.RecoveryStatusResponse.Indices.Count);
            sut.Completed += (sender, args) => Assert.Fail("Can't complete");
            sut.Error     += (sender, args) => Assert.Fail(args.Exception.Message);

            sut.CheckStatus();
        }
        public void ShouldCallRecoveryStatus()
        {
            var elastickClientMock = new Mock <IElasticClient>();

            var sut = new RestoreStatusHumbleObject(elastickClientMock.Object,
                                                    RestoreRequestFixture());

            sut.CheckStatus();

            elastickClientMock.Verify(x => x
                                      .RecoveryStatus(
                                          It.Is <RecoveryStatusRequest>(
                                              request =>
                                              request.Indices.Count() == 1 &&
                                              request.Indices.ElementAt(0).Name == "test" &&
                                              request.Indices.ElementAt(0).Type == typeof(object) &&
                                              request.Detailed)),
                                      Times.AtLeastOnce);
        }
        public void RestoreResponseInvalid_Exception()
        {
            var elastickClientMock   = new Mock <IElasticClient>();
            var recoveryResponseMock = new Mock <IRecoveryStatusResponse>();

            recoveryResponseMock.Setup(x => x.IsValid).Returns(false);

            elastickClientMock.Setup(x => x.RecoveryStatus(It.IsAny <IRecoveryStatusRequest>()))
            .Returns(() => recoveryResponseMock.Object);

            var sut = new RestoreStatusHumbleObject(elastickClientMock.Object,
                                                    RestoreRequestFixture());

            sut.Next      += (sender, args) => Assert.Fail("");
            sut.Completed += (sender, args) => Assert.Fail("Can't complete");
            sut.Error     += (sender, args) =>
            {
                throw args.Exception;
            };

            sut.CheckStatus();
        }
        public void ShouldCallRecoveryStatus_Rename()
        {
            var elastickClientMock = new Mock <IElasticClient>();

            RestoreRequest restoreRequestFixture = RestoreRequestFixture("test_tmp");

            restoreRequestFixture.RenamePattern     = "_(.+)";
            restoreRequestFixture.RenameReplacement = "_restored_$1";

            var sut = new RestoreStatusHumbleObject(elastickClientMock.Object,
                                                    restoreRequestFixture);

            sut.CheckStatus();

            elastickClientMock.Verify(x => x
                                      .RecoveryStatus(
                                          It.Is <RecoveryStatusRequest>(
                                              request =>
                                              request.Indices.Count() == 1 &&
                                              request.Indices.ElementAt(0).Name == Regex.Replace("test_tmp", restoreRequestFixture.RenamePattern, restoreRequestFixture.RenameReplacement) &&
                                              request.Indices.ElementAt(0).Type == typeof(object) &&
                                              request.Detailed)),
                                      Times.AtLeastOnce);
        }
Esempio n. 6
0
        private void Restore(object state)
        {
            var observer = state as IObserver <IRecoveryStatusResponse>;

            if (observer == null)
            {
                throw new ArgumentException($"must be an {nameof(IObserver<IRecoveryStatusResponse>)}", nameof(state));
            }

            try
            {
                var watch = new Stopwatch();
                watch.Start();

                _restoreStatusHumbleObject.CheckStatus();

                _timer.Change(TimeSpan.FromMilliseconds(Math.Max(0, _interval.TotalMilliseconds - watch.ElapsedMilliseconds)),
                              Timeout.InfiniteTimeSpan);
            }
            catch (Exception exception)
            {
                observer.OnError(exception);
            }
        }