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