示例#1
0
        public void UriFormatting(string index, string documentType, string expectedUri)
        {
            var connection = new ElasticConnection(new Uri("http://a.b.com:9000/"), index: index);

            Assert.Equal(expectedUri, connection.GetSearchUri(new SearchRequest {
                DocumentType = documentType
            }).ToString());
        }
示例#2
0
        public void PrettySetsUriQueryWhenNoOtherQueryUriParameters()
        {
            var connection = new ElasticConnection(new Uri("http://coruscant.gov/some"), options: new ElasticConnectionOptions {
                Pretty = true
            });
            var prettyUri = connection.GetSearchUri(new SearchRequest {
                DocumentType = "type1", Filter = criteria
            });

            Assert.Equal("pretty=true", prettyUri.GetComponents(UriComponents.Query, UriFormat.Unescaped));
        }
        public static async void SearchAsyncCapturesRequestInfoOnFailure()
        {
            var spyLog = new SpyLog();
            var brokenConnection = new ElasticConnection(new Uri("http://localhost:12"), index: "MyIndex");
            var processor = new ElasticRequestProcessor(brokenConnection, mapping, spyLog, new RetryPolicy(spyLog, 100, 1));
            var searchRequest = new SearchRequest { DocumentType = "docType" };
            var formatter = new SearchRequestFormatter(brokenConnection, mapping, searchRequest);

            var ex = await Record.ExceptionAsync(() => processor.SearchAsync(searchRequest, CancellationToken.None));

            Assert.IsType<RetryFailedException>(ex);
            var retryLogEntry = Assert.Single(spyLog.Entries, s => s.AdditionalInfo.ContainsKey("category") && s.AdditionalInfo["category"].Equals("retry"));
            Assert.Equal("MyIndex", retryLogEntry.AdditionalInfo["index"]);
            Assert.Equal(brokenConnection.GetSearchUri(searchRequest), retryLogEntry.AdditionalInfo["uri"]);
            Assert.Equal(formatter.Body, retryLogEntry.AdditionalInfo["query"]);
        }
示例#4
0
        public void PrettyChangesUriQueryParameterWhenDifferentValueAlreadyExists()
        {
            var connection = new ElasticConnection(new Uri("http://coruscant.gov/some?pretty=false&human=true"),
                                                   options: new ElasticConnectionOptions {
                Pretty = true
            });
            var prettyUri = connection.GetSearchUri(new SearchRequest {
                DocumentType = "type1", Filter = criteria
            });

            var parameters = prettyUri.GetComponents(UriComponents.Query, UriFormat.Unescaped).Split('&');

            Assert.Equal(2, parameters.Length);
            Assert.Contains("human=true", parameters);
            Assert.Contains("pretty=true", parameters);
        }
        public void PrettyAppendsUriQueryParameterWhenOtherQueryUriParameters()
        {
            var connection = new ElasticConnection(new Uri("http://coruscant.gov/some?human=false"),
                                                   options: new ElasticConnectionOptions {
                Pretty = true
            });
            var prettyUri = connection.GetSearchUri(new SearchRequest {
                IndexType = "type1", Query = criteria
            });

            var parameters = prettyUri.GetComponents(UriComponents.Query, UriFormat.Unescaped).Split('&');

            Assert.Equal(2, parameters.Length);
            Assert.Contains("human=false", parameters);
            Assert.Contains("pretty=true", parameters);
        }
        public static async void SearchAsyncCapturesRequestInfoOnFailure()
        {
            var spyLog           = new SpyLog();
            var brokenConnection = new ElasticConnection(new Uri("http://localhost:12"), index: "MyIndex");
            var processor        = new ElasticRequestProcessor(brokenConnection, mapping, spyLog, new RetryPolicy(spyLog, 100, 1));
            var searchRequest    = new SearchRequest {
                IndexType = "docType"
            };
            var formatter = new SearchRequestFormatter(brokenConnection, mapping, searchRequest);

            var ex = await Record.ExceptionAsync(() => processor.SearchAsync(searchRequest, CancellationToken.None));

            Assert.IsType <RetryFailedException>(ex);
            var retryLogEntry = Assert.Single(spyLog.Entries, s => s.AdditionalInfo.ContainsKey("category") && s.AdditionalInfo["category"].Equals("retry"));

            Assert.Equal("MyIndex", retryLogEntry.AdditionalInfo["index"]);
            Assert.Equal(brokenConnection.GetSearchUri(searchRequest), retryLogEntry.AdditionalInfo["uri"]);
            Assert.Equal(formatter.Body, retryLogEntry.AdditionalInfo["query"]);
        }
        public void PrettyChangesUriQueryParameterWhenDifferentValueAlreadyExists()
        {
            var connection = new ElasticConnection(new Uri("http://coruscant.gov/some?pretty=false&human=true"),
                options: new ElasticConnectionOptions { Pretty = true });
            var prettyUri = connection.GetSearchUri(new SearchRequest { DocumentType = "type1", Filter = criteria });

            var parameters = prettyUri.GetComponents(UriComponents.Query, UriFormat.Unescaped).Split('&');
            Assert.Equal(2, parameters.Length);
            Assert.Contains("human=true", parameters);
            Assert.Contains("pretty=true", parameters);
        }
        public void PrettySetsUriQueryWhenNoOtherQueryUriParameters()
        {
            var connection = new ElasticConnection(new Uri("http://coruscant.gov/some"), options: new ElasticConnectionOptions { Pretty = true });
            var prettyUri = connection.GetSearchUri(new SearchRequest { DocumentType = "type1", Filter = criteria });

            Assert.Equal("pretty=true", prettyUri.GetComponents(UriComponents.Query, UriFormat.Unescaped));
        }
        public void UriFormatting(string index, string documentType, string expectedUri)
        {
            var connection = new ElasticConnection(new Uri("http://a.b.com:9000/"), index: index);

            Assert.Equal(expectedUri, connection.GetSearchUri(new SearchRequest { DocumentType = documentType }).ToString());
        }