@@ -133,26 +133,24 @@ public void testWaitForCompletion() throws InterruptedException {
133
133
for (int i = 0 ; i < numSkippedShards ; i ++) {
134
134
skippedShards .add (new SearchShard (null , new ShardId ("0" , "0" , 1 )));
135
135
}
136
-
137
- int numShardFailures = 0 ;
136
+ int totalShards = numShards + numSkippedShards ;
138
137
task .getSearchProgressActionListener ().onListShards (shards , skippedShards , SearchResponse .Clusters .EMPTY , false );
139
138
for (int i = 0 ; i < numShards ; i ++) {
140
139
task .getSearchProgressActionListener ().onPartialReduce (shards .subList (i , i +1 ),
141
140
new TotalHits (0 , TotalHits .Relation .GREATER_THAN_OR_EQUAL_TO ), null , 0 );
142
- assertCompletionListeners (task , numShards + numSkippedShards , numSkippedShards , numShardFailures , true );
141
+ assertCompletionListeners (task , totalShards , 1 + numSkippedShards , numSkippedShards , 0 , true );
143
142
}
144
143
task .getSearchProgressActionListener ().onFinalReduce (shards ,
145
144
new TotalHits (0 , TotalHits .Relation .GREATER_THAN_OR_EQUAL_TO ), null , 0 );
146
- assertCompletionListeners (task , numShards + numSkippedShards , numSkippedShards , numShardFailures , true );
145
+ assertCompletionListeners (task , totalShards , totalShards , numSkippedShards , 0 , true );
147
146
((AsyncSearchTask .Listener )task .getProgressListener ()).onResponse (
148
- newSearchResponse (numShards +numSkippedShards , numShards , numSkippedShards ));
149
- assertCompletionListeners (task , numShards +numSkippedShards ,
150
- numSkippedShards , numShardFailures , false );
147
+ newSearchResponse (totalShards , totalShards , numSkippedShards ));
148
+ assertCompletionListeners (task , totalShards , totalShards , numSkippedShards , 0 , false );
151
149
}
152
150
153
151
public void testWithFetchFailures () throws InterruptedException {
154
152
AsyncSearchTask task = createAsyncSearchTask ();
155
- int numShards = randomIntBetween (0 , 10 );
153
+ int numShards = randomIntBetween (2 , 10 );
156
154
List <SearchShard > shards = new ArrayList <>();
157
155
for (int i = 0 ; i < numShards ; i ++) {
158
156
shards .add (new SearchShard (null , new ShardId ("0" , "0" , 1 )));
@@ -162,38 +160,72 @@ public void testWithFetchFailures() throws InterruptedException {
162
160
for (int i = 0 ; i < numSkippedShards ; i ++) {
163
161
skippedShards .add (new SearchShard (null , new ShardId ("0" , "0" , 1 )));
164
162
}
165
-
163
+ int totalShards = numShards + numSkippedShards ;
166
164
task .getSearchProgressActionListener ().onListShards (shards , skippedShards , SearchResponse .Clusters .EMPTY , false );
167
165
for (int i = 0 ; i < numShards ; i ++) {
168
166
task .getSearchProgressActionListener ().onPartialReduce (shards .subList (i , i +1 ),
169
167
new TotalHits (0 , TotalHits .Relation .GREATER_THAN_OR_EQUAL_TO ), null , 0 );
170
- assertCompletionListeners (task , numShards + numSkippedShards , numSkippedShards , 0 , true );
168
+ assertCompletionListeners (task , totalShards , 1 + numSkippedShards , numSkippedShards , 0 , true );
171
169
}
172
170
task .getSearchProgressActionListener ().onFinalReduce (shards ,
173
171
new TotalHits (0 , TotalHits .Relation .GREATER_THAN_OR_EQUAL_TO ), null , 0 );
174
- int numFetchFailures = randomIntBetween (0 , numShards );
172
+ int numFetchFailures = randomIntBetween (1 , numShards - 1 );
173
+ ShardSearchFailure [] shardSearchFailures = new ShardSearchFailure [numFetchFailures ];
175
174
for (int i = 0 ; i < numFetchFailures ; i ++) {
175
+ IOException failure = new IOException ("boum" );
176
176
task .getSearchProgressActionListener ().onFetchFailure (i ,
177
177
new SearchShardTarget ("0" , new ShardId ("0" , "0" , 1 ), null , OriginalIndices .NONE ),
178
- new IOException ( "boum" ) );
179
-
178
+ failure );
179
+ shardSearchFailures [ i ] = new ShardSearchFailure ( failure );
180
180
}
181
- assertCompletionListeners (task , numShards + numSkippedShards , numSkippedShards , numFetchFailures , true );
181
+ assertCompletionListeners (task , totalShards , totalShards , numSkippedShards , numFetchFailures , true );
182
182
((AsyncSearchTask .Listener )task .getProgressListener ()).onResponse (
183
- newSearchResponse (numShards +numSkippedShards , numShards , numSkippedShards ));
184
- assertCompletionListeners (task , numShards +numSkippedShards ,
185
- numSkippedShards , numFetchFailures , false );
183
+ newSearchResponse (totalShards , totalShards - numFetchFailures , numSkippedShards , shardSearchFailures ));
184
+ assertCompletionListeners (task , totalShards , totalShards - numFetchFailures , numSkippedShards , numFetchFailures , false );
185
+ }
186
+
187
+ public void testFatalFailureDuringFetch () throws InterruptedException {
188
+ AsyncSearchTask task = createAsyncSearchTask ();
189
+ int numShards = randomIntBetween (0 , 10 );
190
+ List <SearchShard > shards = new ArrayList <>();
191
+ for (int i = 0 ; i < numShards ; i ++) {
192
+ shards .add (new SearchShard (null , new ShardId ("0" , "0" , 1 )));
193
+ }
194
+ List <SearchShard > skippedShards = new ArrayList <>();
195
+ int numSkippedShards = randomIntBetween (0 , 10 );
196
+ for (int i = 0 ; i < numSkippedShards ; i ++) {
197
+ skippedShards .add (new SearchShard (null , new ShardId ("0" , "0" , 1 )));
198
+ }
199
+ int totalShards = numShards + numSkippedShards ;
200
+ task .getSearchProgressActionListener ().onListShards (shards , skippedShards , SearchResponse .Clusters .EMPTY , false );
201
+ for (int i = 0 ; i < numShards ; i ++) {
202
+ task .getSearchProgressActionListener ().onPartialReduce (shards .subList (0 , i +1 ),
203
+ new TotalHits (0 , TotalHits .Relation .GREATER_THAN_OR_EQUAL_TO ), null , 0 );
204
+ assertCompletionListeners (task , totalShards , i + 1 + numSkippedShards , numSkippedShards , 0 , true );
205
+ }
206
+ task .getSearchProgressActionListener ().onFinalReduce (shards ,
207
+ new TotalHits (0 , TotalHits .Relation .GREATER_THAN_OR_EQUAL_TO ), null , 0 );
208
+ for (int i = 0 ; i < numShards ; i ++) {
209
+ task .getSearchProgressActionListener ().onFetchFailure (i ,
210
+ new SearchShardTarget ("0" , new ShardId ("0" , "0" , 1 ), null , OriginalIndices .NONE ),
211
+ new IOException ("boum" ));
212
+ }
213
+ assertCompletionListeners (task , totalShards , totalShards , numSkippedShards , numShards , true );
214
+ ((AsyncSearchTask .Listener )task .getProgressListener ()).onFailure (new IOException ("boum" ));
215
+ assertCompletionListeners (task , totalShards , totalShards , numSkippedShards , numShards , true );
186
216
}
187
217
188
- private static SearchResponse newSearchResponse (int totalShards , int successfulShards , int skippedShards ) {
218
+ private static SearchResponse newSearchResponse (int totalShards , int successfulShards , int skippedShards ,
219
+ ShardSearchFailure ... shardFailures ) {
189
220
InternalSearchResponse response = new InternalSearchResponse (SearchHits .empty (),
190
221
InternalAggregations .EMPTY , null , null , false , null , 1 );
191
222
return new SearchResponse (response , null , totalShards , successfulShards , skippedShards ,
192
- 100 , ShardSearchFailure . EMPTY_ARRAY , SearchResponse .Clusters .EMPTY );
223
+ 100 , shardFailures , SearchResponse .Clusters .EMPTY );
193
224
}
194
225
195
226
private void assertCompletionListeners (AsyncSearchTask task ,
196
227
int expectedTotalShards ,
228
+ int expectedSuccessfulShards ,
197
229
int expectedSkippedShards ,
198
230
int expectedShardFailures ,
199
231
boolean isPartial ) throws InterruptedException {
@@ -204,6 +236,7 @@ private void assertCompletionListeners(AsyncSearchTask task,
204
236
@ Override
205
237
public void onResponse (AsyncSearchResponse resp ) {
206
238
assertThat (resp .getSearchResponse ().getTotalShards (), equalTo (expectedTotalShards ));
239
+ assertThat (resp .getSearchResponse ().getSuccessfulShards (), equalTo (expectedSuccessfulShards ));
207
240
assertThat (resp .getSearchResponse ().getSkippedShards (), equalTo (expectedSkippedShards ));
208
241
assertThat (resp .getSearchResponse ().getFailedShards (), equalTo (expectedShardFailures ));
209
242
assertThat (resp .isPartial (), equalTo (isPartial ));
0 commit comments