/// <inheritdoc/>
        public async Task <bool> MoveNextAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            bool hasMore;

            try
            {
                hasMore = await _cursor.MoveNextAsync(cancellationToken).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                if (RetryabilityHelper.IsResumableChangeStreamException(ex))
                {
                    _cursor = await _changeStreamOperation.ResumeAsync(_binding, cancellationToken).ConfigureAwait(false);

                    hasMore = await _cursor.MoveNextAsync(cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    throw;
                }
            }

            ProcessBatch(hasMore);
            return(hasMore);
        }
Exemple #2
0
        public void IsResumableChangeStreamException_should_return_expected_result_for_servers_with_new_behavior_and_errors(Type exceptionType, bool isResumable)
        {
            var exception = (MongoException)CoreExceptionHelper.CreateException(exceptionType);

            var result = RetryabilityHelper.IsResumableChangeStreamException(exception, Feature.ServerReturnsResumableChangeStreamErrorLabel.FirstSupportedVersion);

            result.Should().Be(isResumable);
        }
Exemple #3
0
        public void IsResumableChangeStreamException_should_return_expected_result_using_exception_type(Type exceptionType, bool expectedResult)
        {
            var exception = CoreExceptionHelper.CreateException(exceptionType);

            var result = RetryabilityHelper.IsResumableChangeStreamException(exception);

            result.Should().Be(expectedResult);
        }
Exemple #4
0
        public void IsResumableChangeStreamException_should_return_expected_result_using_code(int code, bool expectedResult)
        {
            var exception = CoreExceptionHelper.CreateMongoCommandException(code);

            var result = RetryabilityHelper.IsResumableChangeStreamException(exception);

            result.Should().Be(expectedResult);
        }
        public void IsResumableChangeStreamException_should_return_expected_result_using_error_label(string label, bool expectedResult)
        {
            var exception = CoreExceptionHelper.CreateMongoCommandException(label: label);

            var result = RetryabilityHelper.IsResumableChangeStreamException(exception);

            result.Should().Be(expectedResult);
        }
Exemple #6
0
        public void IsResumableChangeStreamException_should_return_expected_result_for_servers_with_new_behavior([Values(false, true)] bool hasResumableChangeStreamErrorLabel)
        {
            var exception = CoreExceptionHelper.CreateMongoCommandException(-1);

            if (hasResumableChangeStreamErrorLabel)
            {
                exception.AddErrorLabel("ResumableChangeStreamError");
            }

            var result = RetryabilityHelper.IsResumableChangeStreamException(exception, Feature.ServerReturnsResumableChangeStreamErrorLabel.FirstSupportedVersion);

            result.Should().Be(hasResumableChangeStreamErrorLabel);
        }
Exemple #7
0
        public void IsResumableChangeStreamException_should_return_expected_result_for_servers_with_old_behavior(object exceptionDescription, bool isResumable)
        {
            MongoException exception;

            if (exceptionDescription is Type exceptionType)
            {
                exception = (MongoException)CoreExceptionHelper.CreateException(exceptionType);
            }
            else
            {
                exception = CoreExceptionHelper.CreateMongoCommandException((int)exceptionDescription);
            }

            var result = RetryabilityHelper.IsResumableChangeStreamException(exception, Feature.ServerReturnsResumableChangeStreamErrorLabel.LastNotSupportedVersion);

            result.Should().Be(isResumable);
        }
Exemple #8
0
        /// <inheritdoc/>
        public bool MoveNext(CancellationToken cancellationToken = default(CancellationToken))
        {
            bool hasMore;

            while (true)
            {
                try
                {
                    hasMore = _cursor.MoveNext(cancellationToken);
                    break;
                }
                catch (Exception ex) when(RetryabilityHelper.IsResumableChangeStreamException(ex))
                {
                    var newCursor = _changeStreamOperation.Resume(_binding, cancellationToken);

                    _cursor.Dispose();
                    _cursor = newCursor;
                }
            }

            ProcessBatch(hasMore);
            return(hasMore);
        }
Exemple #9
0
        /// <inheritdoc/>
        public async Task <bool> MoveNextAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            bool hasMore;

            while (true)
            {
                try
                {
                    hasMore = await _cursor.MoveNextAsync(cancellationToken).ConfigureAwait(false);

                    break;
                }
                catch (Exception ex) when(RetryabilityHelper.IsResumableChangeStreamException(ex))
                {
                    var newCursor = await _changeStreamOperation.ResumeAsync(_binding, cancellationToken).ConfigureAwait(false);

                    _cursor.Dispose();
                    _cursor = newCursor;
                }
            }

            ProcessBatch(hasMore);
            return(hasMore);
        }
        /// <inheritdoc/>
        public bool MoveNext(CancellationToken cancellationToken = default(CancellationToken))
        {
            bool hasMore;

            try
            {
                hasMore = _cursor.MoveNext(cancellationToken);
            }
            catch (Exception ex)
            {
                if (RetryabilityHelper.IsResumableChangeStreamException(ex))
                {
                    _cursor = _changeStreamOperation.Resume(_binding, cancellationToken);
                    hasMore = _cursor.MoveNext(cancellationToken);
                }
                else
                {
                    throw;
                }
            }

            ProcessBatch(hasMore);
            return(hasMore);
        }