private static void CheckOriginalException(ElasticsearchClientException exception)
 {
     if (exception.FailureReason == null)
     {
         return;
     }
     throw Errors.GetValueOrDefault((PipelineFailure)exception.FailureReason,
                                    new Exception("An UnKnown error occurred"));
 }
        public void Validate_ShouldThrowAllDataNotFoundException_WhenFailedShardsIsNotZero()
        {
            var elasticsearchClientException = new ElasticsearchClientException(PipelineFailure.Unexpected, "exception", new Exception());
            var iSearchResponse = Substitute.For <ISearchResponse <Doc> >();

            iSearchResponse.IsValid.Returns(false);
            iSearchResponse.OriginalException.Returns(elasticsearchClientException);

            Assert.Throws <Exception>(iSearchResponse.Validate);
        }
        public void Validate_ShouldThrowBadAuthenticationException_WhenBadAuthenticationIsTrue()
        {
            var elasticsearchClientException = new ElasticsearchClientException(PipelineFailure.BadAuthentication, "exception", new Exception());
            var searchResponse = Substitute.For <ISearchResponse <Doc> >();

            searchResponse.IsValid.Returns(false);
            searchResponse.OriginalException.Returns(elasticsearchClientException);

            Assert.Throws <Exception>(searchResponse.Validate);
        }
Ejemplo n.º 4
0
        private Mock <GetResponse <T> > ExceptionGetResponse <T>(ElasticsearchClientException originalException)
            where T : class
        {
            var response = new Mock <GetResponse <T> >();
            var apiCall  = new Mock <IApiCallDetails>();

            apiCall.Setup(x => x.OriginalException)
            .Returns(originalException);
            response.SetupGet(x => x.ApiCall)
            .Returns(apiCall.Object);
            response.SetupGet(x => x.IsValid)
            .Returns(false);
            return(response);
        }
Ejemplo n.º 5
0
        public ILoggerBuilder TryCreateLogger()
        {
            try
            {
                _logger = new LoggerConfiguration()
                          .ReadFrom.Configuration(_config.Configuration)
                          .WriteTo.Elasticsearch(ElasticsearchSinkOptions())
                          .WriteTo.Console()
                          .WriteTo.Debug()
                          .CreateLogger();
            }
            catch (ElasticsearchClientException exception)
            {
                _elkCreateException = exception;
            }

            return(this);
        }