|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
| 3 | +using System.Globalization; |
3 | 4 | using System.Linq;
|
4 | 5 | using System.Threading.Tasks;
|
5 | 6 | using Elastic.Xunit.XunitPlumbing;
|
|
12 | 13 |
|
13 | 14 | namespace Tests.Document.Multiple.MultiGet
|
14 | 15 | {
|
15 |
| - public class GetManyApiTests : IClusterFixture<ReadOnlyCluster> |
| 16 | + public class GetManyApiTests : IClusterFixture<WritableCluster> |
16 | 17 | {
|
17 | 18 | private readonly IElasticClient _client;
|
18 | 19 | private readonly IEnumerable<long> _ids = Developer.Developers.Select(d => d.Id).Take(10);
|
19 | 20 |
|
20 |
| - public GetManyApiTests(ReadOnlyCluster cluster) => _client = cluster.Client; |
| 21 | + public GetManyApiTests(WritableCluster cluster) => _client = cluster.Client; |
21 | 22 |
|
22 | 23 | [I] public void UsesDefaultIndexAndInferredType()
|
23 | 24 | {
|
@@ -45,6 +46,129 @@ [I] public async Task UsesDefaultIndexAndInferredTypeAsync()
|
45 | 46 | }
|
46 | 47 | }
|
47 | 48 |
|
| 49 | + [I] public async Task ReturnsDocMatchingDistinctIds() |
| 50 | + { |
| 51 | + var id = _ids.First(); |
| 52 | + |
| 53 | + var response = await _client.GetManyAsync<Developer>(new[] { id, id, id }); |
| 54 | + response.Count().Should().Be(1); |
| 55 | + foreach (var hit in response) |
| 56 | + { |
| 57 | + hit.Index.Should().NotBeNullOrWhiteSpace(); |
| 58 | + hit.Id.Should().Be(id.ToString(CultureInfo.InvariantCulture)); |
| 59 | + hit.Found.Should().BeTrue(); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + [I] public void ReturnsDocsMatchingDistinctIdsFromDifferentIndices() |
| 64 | + { |
| 65 | + var developerIndex = Nest.Indices.Index<Developer>(); |
| 66 | + var indexName = developerIndex.GetString(_client.ConnectionSettings); |
| 67 | + var reindexName = $"{indexName}-getmany-distinctids"; |
| 68 | + |
| 69 | + var reindexResponse = _client.ReindexOnServer(r => r |
| 70 | + .Source(s => s |
| 71 | + .Index(developerIndex) |
| 72 | + .Query<Developer>(q => q |
| 73 | + .Ids(ids => ids.Values(_ids)) |
| 74 | + ) |
| 75 | + ) |
| 76 | + .Destination(d => d |
| 77 | + .Index(reindexName)) |
| 78 | + .Refresh() |
| 79 | + ); |
| 80 | + |
| 81 | + if (!reindexResponse.IsValid) |
| 82 | + throw new Exception($"problem reindexing documents for integration test: {reindexResponse.DebugInformation}"); |
| 83 | + |
| 84 | + var id = _ids.First(); |
| 85 | + |
| 86 | + var multiGetResponse = _client.MultiGet(s => s |
| 87 | + .RequestConfiguration(r => r.ThrowExceptions()) |
| 88 | + .Get<Developer>(m => m |
| 89 | + .Id(id) |
| 90 | + .Index(indexName) |
| 91 | + ) |
| 92 | + .Get<Developer>(m => m |
| 93 | + .Id(id) |
| 94 | + .Index(reindexName) |
| 95 | + ) |
| 96 | + ); |
| 97 | + |
| 98 | + var response = multiGetResponse.GetMany<Developer>(new [] { id, id }); |
| 99 | + |
| 100 | + response.Count().Should().Be(2); |
| 101 | + foreach (var hit in response) |
| 102 | + { |
| 103 | + hit.Index.Should().NotBeNullOrWhiteSpace(); |
| 104 | + hit.Id.Should().NotBeNullOrWhiteSpace(); |
| 105 | + hit.Found.Should().BeTrue(); |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + [I] public void ReturnsDocsMatchingDistinctIdsFromDifferentIndicesWithRequestLevelIndex() |
| 110 | + { |
| 111 | + var developerIndex = Nest.Indices.Index<Developer>(); |
| 112 | + var indexName = developerIndex.GetString(_client.ConnectionSettings); |
| 113 | + var reindexName = $"{indexName}-getmany-distinctidsindex"; |
| 114 | + |
| 115 | + var reindexResponse = _client.ReindexOnServer(r => r |
| 116 | + .Source(s => s |
| 117 | + .Index(developerIndex) |
| 118 | + .Query<Developer>(q => q |
| 119 | + .Ids(ids => ids.Values(_ids)) |
| 120 | + ) |
| 121 | + ) |
| 122 | + .Destination(d => d |
| 123 | + .Index(reindexName)) |
| 124 | + .Refresh() |
| 125 | + ); |
| 126 | + |
| 127 | + if (!reindexResponse.IsValid) |
| 128 | + throw new Exception($"problem reindexing documents for integration test: {reindexResponse.DebugInformation}"); |
| 129 | + |
| 130 | + var id = _ids.First(); |
| 131 | + |
| 132 | + var multiGetResponse = _client.MultiGet(s => s |
| 133 | + .Index(indexName) |
| 134 | + .RequestConfiguration(r => r.ThrowExceptions()) |
| 135 | + .Get<Developer>(m => m |
| 136 | + .Id(id) |
| 137 | + ) |
| 138 | + .Get<Developer>(m => m |
| 139 | + .Id(id) |
| 140 | + .Index(reindexName) |
| 141 | + ) |
| 142 | + ); |
| 143 | + |
| 144 | + var response = multiGetResponse.GetMany<Developer>(new [] { id, id }); |
| 145 | + |
| 146 | + response.Count().Should().Be(2); |
| 147 | + var seenIndices = new HashSet<string>(2); |
| 148 | + |
| 149 | + foreach (var hit in response) |
| 150 | + { |
| 151 | + hit.Index.Should().NotBeNullOrWhiteSpace(); |
| 152 | + seenIndices.Add(hit.Index); |
| 153 | + hit.Id.Should().NotBeNullOrWhiteSpace(); |
| 154 | + hit.Found.Should().BeTrue(); |
| 155 | + } |
| 156 | + |
| 157 | + seenIndices.Should().HaveCount(2).And.Contain(new [] { indexName, reindexName }); |
| 158 | + } |
| 159 | + |
| 160 | + [I] public async Task ReturnsSourceMatchingDistinctIds() |
| 161 | + { |
| 162 | + var id = _ids.First(); |
| 163 | + |
| 164 | + var sources = await _client.SourceManyAsync<Developer>(new[] { id, id, id }); |
| 165 | + sources.Count().Should().Be(1); |
| 166 | + foreach (var hit in sources) |
| 167 | + { |
| 168 | + hit.Id.Should().Be(id); |
| 169 | + } |
| 170 | + } |
| 171 | + |
48 | 172 | [I] public async Task CanHandleNotFoundResponses()
|
49 | 173 | {
|
50 | 174 | var response = await _client.GetManyAsync<Developer>(_ids.Select(i => i * 100));
|
|
0 commit comments