|
| 1 | +using System; |
| 2 | +using System.IO; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using Elasticsearch.Net; |
| 6 | +using FluentAssertions; |
| 7 | +using Nest; |
| 8 | +using Tests.Framework; |
| 9 | +using Tests.Framework.Integration; |
| 10 | +using Tests.Framework.MockData; |
| 11 | + |
| 12 | +namespace Tests.Reproduce |
| 13 | +{ |
| 14 | + public class GithubIssue2152 |
| 15 | + { |
| 16 | + [U] |
| 17 | + public void CanDeserializeNestedBulkError() |
| 18 | + { |
| 19 | + var nestedCausedByError = @"{ |
| 20 | + ""took"": 4, |
| 21 | + ""errors"": true, |
| 22 | + ""items"": [{ |
| 23 | + ""update"": { |
| 24 | + ""_index"": ""index-name"", |
| 25 | + ""_type"": ""type-name"", |
| 26 | + ""_id"": ""1"", |
| 27 | + ""status"": 400, |
| 28 | + ""error"": { |
| 29 | + ""type"": ""illegal_argument_exception"", |
| 30 | + ""reason"": ""failed to execute script"", |
| 31 | + ""caused_by"": { |
| 32 | + ""type"": ""script_exception"", |
| 33 | + ""reason"": ""failed to run inline script [use(java.lang.Exception) {throw new Exception(\""Customized Exception\"")}] using lang [groovy]"", |
| 34 | + ""caused_by"": { |
| 35 | + ""type"": ""privileged_action_exception"", |
| 36 | + ""reason"": null, |
| 37 | + ""caused_by"": { |
| 38 | + ""type"": ""exception"", |
| 39 | + ""reason"": ""Custom Exception"" |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + }] |
| 46 | + }"; |
| 47 | + |
| 48 | + var bytes = Encoding.UTF8.GetBytes(nestedCausedByError); |
| 49 | + var connection = new InMemoryConnection(bytes); |
| 50 | + var settings = new ConnectionSettings(new SingleNodeConnectionPool(new Uri("http://localhost:9200")), connection); |
| 51 | + var client = new ElasticClient(settings); |
| 52 | + |
| 53 | + var bulkResponse = client.Bulk(new BulkDescriptor()); |
| 54 | + |
| 55 | + bulkResponse.Errors.Should().BeTrue(); |
| 56 | + |
| 57 | + var firstOperation = bulkResponse.ItemsWithErrors.First(); |
| 58 | + |
| 59 | + firstOperation.Error.Should().NotBeNull(); |
| 60 | + firstOperation.Error.CausedBy.Should().NotBeNull(); |
| 61 | + firstOperation.Error.CausedBy.InnerCausedBy.Should().NotBeNull(); |
| 62 | + firstOperation.Error.CausedBy.InnerCausedBy.InnerCausedBy.Should().NotBeNull(); |
| 63 | + } |
| 64 | + |
| 65 | + [U] |
| 66 | + public void CanDeserializeNestedError() |
| 67 | + { |
| 68 | + var nestedCausedByError = @"{ |
| 69 | + ""status"": 400, |
| 70 | + ""error"": { |
| 71 | + ""type"": ""illegal_argument_exception"", |
| 72 | + ""reason"": ""failed to execute script"", |
| 73 | + ""caused_by"": { |
| 74 | + ""type"": ""script_exception"", |
| 75 | + ""reason"": ""failed to run inline script [use(java.lang.Exception) {throw new Exception(\""Customized Exception\"")}] using lang [groovy]"", |
| 76 | + ""caused_by"": { |
| 77 | + ""type"": ""privileged_action_exception"", |
| 78 | + ""reason"": null, |
| 79 | + ""caused_by"": { |
| 80 | + ""type"": ""exception"", |
| 81 | + ""reason"": ""Custom Exception"" |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + }"; |
| 87 | + |
| 88 | + var bytes = Encoding.UTF8.GetBytes(nestedCausedByError); |
| 89 | + var connection = new InMemoryConnection(bytes, 400); |
| 90 | + var settings = new ConnectionSettings(new SingleNodeConnectionPool(new Uri("http://localhost:9200")), connection); |
| 91 | + var client = new ElasticClient(settings); |
| 92 | + |
| 93 | + var searchResponse = client.Search<object>(s => s); |
| 94 | + |
| 95 | + searchResponse.IsValid.Should().BeFalse(); |
| 96 | + searchResponse.ServerError.Should().NotBeNull(); |
| 97 | + searchResponse.ServerError.Error.Should().NotBeNull(); |
| 98 | + searchResponse.ServerError.Error.CausedBy.Should().NotBeNull(); |
| 99 | + searchResponse.ServerError.Error.CausedBy.InnerCausedBy.Should().NotBeNull(); |
| 100 | + searchResponse.ServerError.Error.CausedBy.InnerCausedBy.InnerCausedBy.Should().NotBeNull(); |
| 101 | + } |
| 102 | + } |
| 103 | +} |
0 commit comments