public void AddRetryableWriteErrorLabelIfRequired_should_add_RetryableWriteError_for_MongoWriteConcernException_when_required(int errorCode, bool shouldAddErrorLabel) { var exception = CoreExceptionHelper.CreateMongoWriteConcernException(BsonDocument.Parse($"{{ writeConcernError : {{ code : {errorCode} }} }}")); RetryabilityHelper.AddRetryableWriteErrorLabelIfRequired(exception, Feature.ServerReturnsRetryableWriteErrorLabel.LastNotSupportedVersion); var hasRetryableWriteErrorLabel = exception.HasErrorLabel("RetryableWriteError"); hasRetryableWriteErrorLabel.Should().Be(shouldAddErrorLabel); }
public void AddRetryableWriteErrorLabelIfRequired_should_add_RetryableWriteError_for_network_errors() { var exception = (MongoException)CoreExceptionHelper.CreateException(typeof(MongoConnectionException)); RetryabilityHelper.AddRetryableWriteErrorLabelIfRequired(exception); var hasRetryableWriteErrorLabel = exception.HasErrorLabel("RetryableWriteError"); hasRetryableWriteErrorLabel.Should().BeTrue(); }
public void AddRetryableWriteErrorLabelIfRequired_should_add_RetryableWriteError_for_network_errors([Values(false, true)] bool serverReturnsRetryableWriteErrorLabel) { var exception = (MongoException)CoreExceptionHelper.CreateException(typeof(MongoConnectionException)); var feature = Feature.ServerReturnsRetryableWriteErrorLabel; var serverVersion = serverReturnsRetryableWriteErrorLabel ? feature.FirstSupportedVersion : feature.LastNotSupportedVersion; RetryabilityHelper.AddRetryableWriteErrorLabelIfRequired(exception, serverVersion); var hasRetryableWriteErrorLabel = exception.HasErrorLabel("RetryableWriteError"); hasRetryableWriteErrorLabel.Should().BeTrue(); }
public void AddRetryableWriteErrorLabelIfRequired_should_add_RetryableWriteError_when_required(object exceptionDescription, bool shouldAddErrorLabel) { MongoException exception; if (exceptionDescription is Type exceptionType) { exception = (MongoException)CoreExceptionHelper.CreateException(exceptionType); } else { exception = CoreExceptionHelper.CreateMongoCommandException((int)exceptionDescription); } RetryabilityHelper.AddRetryableWriteErrorLabelIfRequired(exception, Feature.ServerReturnsRetryableWriteErrorLabel.LastNotSupportedVersion); var hasRetryableWriteErrorLabel = exception.HasErrorLabel("RetryableWriteError"); hasRetryableWriteErrorLabel.Should().Be(shouldAddErrorLabel); }
public void AddRetryableWriteErrorLabelIfRequired_should_not_add_error_label_for_non_retryWrites_server( [Values(false, true)] bool isNetworkError) { MongoException exception = null; if (isNetworkError) { exception = (MongoException)CoreExceptionHelper.CreateException(typeof(MongoConnectionException)); } else { exception = CoreExceptionHelper.CreateMongoCommandException((int)ServerErrorCode.HostNotFound); } RetryabilityHelper.AddRetryableWriteErrorLabelIfRequired(exception, Feature.RetryableWrites.LastNotSupportedVersion); var hasRetryableWriteErrorLabel = exception.HasErrorLabel("RetryableWriteError"); hasRetryableWriteErrorLabel.Should().BeFalse(); }