Skip to content

Commit 73e2a5b

Browse files
sdfsd
1 parent c1d0832 commit 73e2a5b

File tree

2 files changed

+96
-58
lines changed

2 files changed

+96
-58
lines changed

server/src/test/java/org/elasticsearch/action/search/ExpandSearchPhaseTests.java

Lines changed: 74 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -117,31 +117,34 @@ void sendExecuteMultiSearch(MultiSearchRequest request, SearchTask task, ActionL
117117

118118
SearchHit hit = new SearchHit(1, "ID");
119119
hit.setDocumentField("someField", new DocumentField("someField", Collections.singletonList(collapseValue)));
120-
SearchHits hits = new SearchHits(new SearchHit[] { hit }, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0F);
121-
try {
122-
ExpandSearchPhase phase = newExpandSearchPhase(
123-
mockSearchPhaseContext,
124-
new SearchResponseSections(hits, null, null, false, null, null, 1),
125-
null
126-
);
127-
128-
phase.run();
129-
mockSearchPhaseContext.assertNoFailure();
130-
SearchResponse theResponse = mockSearchPhaseContext.searchResponse.get();
131-
assertNotNull(theResponse);
132-
assertEquals(numInnerHits, theResponse.getHits().getHits()[0].getInnerHits().size());
120+
ExpandSearchPhase phase = newExpandSearchPhase(
121+
mockSearchPhaseContext,
122+
new SearchResponseSections(
123+
new SearchHits(new SearchHit[] { hit }, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0F),
124+
null,
125+
null,
126+
false,
127+
null,
128+
null,
129+
1
130+
),
131+
null
132+
);
133133

134-
for (int innerHitNum = 0; innerHitNum < numInnerHits; innerHitNum++) {
135-
assertSame(
136-
theResponse.getHits().getHits()[0].getInnerHits().get("innerHit" + innerHitNum),
137-
collapsedHits.get(innerHitNum)
138-
);
139-
}
134+
phase.run();
135+
mockSearchPhaseContext.assertNoFailure();
136+
SearchResponse theResponse = mockSearchPhaseContext.searchResponse.get();
137+
assertNotNull(theResponse);
138+
assertEquals(numInnerHits, theResponse.getHits().getHits()[0].getInnerHits().size());
140139

141-
assertTrue(executedMultiSearch.get());
142-
} finally {
143-
hits.decRef();
140+
for (int innerHitNum = 0; innerHitNum < numInnerHits; innerHitNum++) {
141+
assertSame(
142+
theResponse.getHits().getHits()[0].getInnerHits().get("innerHit" + innerHitNum),
143+
collapsedHits.get(innerHitNum)
144+
);
144145
}
146+
147+
assertTrue(executedMultiSearch.get());
145148
} finally {
146149
var resp = mockSearchPhaseContext.searchResponse.get();
147150
if (resp != null) {
@@ -188,8 +191,17 @@ void sendExecuteMultiSearch(MultiSearchRequest request, SearchTask task, ActionL
188191
hit1.setDocumentField("someField", new DocumentField("someField", Collections.singletonList(collapseValue)));
189192
SearchHit hit2 = new SearchHit(2, "ID2");
190193
hit2.setDocumentField("someField", new DocumentField("someField", Collections.singletonList(collapseValue)));
191-
SearchHits hits = new SearchHits(new SearchHit[] { hit1, hit2 }, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0F);
192-
try (SearchResponseSections searchResponseSections = new SearchResponseSections(hits, null, null, false, null, null, 1)) {
194+
try (
195+
SearchResponseSections searchResponseSections = new SearchResponseSections(
196+
new SearchHits(new SearchHit[] { hit1, hit2 }, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0F),
197+
null,
198+
null,
199+
false,
200+
null,
201+
null,
202+
1
203+
)
204+
) {
193205
ExpandSearchPhase phase = newExpandSearchPhase(mockSearchPhaseContext, searchResponseSections, null);
194206
phase.run();
195207
assertThat(mockSearchPhaseContext.phaseFailure.get(), Matchers.instanceOf(RuntimeException.class));
@@ -198,7 +210,6 @@ void sendExecuteMultiSearch(MultiSearchRequest request, SearchTask task, ActionL
198210
assertNull(mockSearchPhaseContext.searchResponse.get());
199211
} finally {
200212
mockSearchPhaseContext.results.close();
201-
hits.decRef();
202213
collapsedHits.decRef();
203214
}
204215
}
@@ -217,19 +228,22 @@ void sendExecuteMultiSearch(MultiSearchRequest request, SearchTask task, ActionL
217228
hit1.setDocumentField("someField", new DocumentField("someField", Collections.singletonList(null)));
218229
SearchHit hit2 = new SearchHit(2, "ID2");
219230
hit2.setDocumentField("someField", new DocumentField("someField", Collections.singletonList(null)));
220-
SearchHits hits = new SearchHits(new SearchHit[] { hit1, hit2 }, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0F);
221-
try {
222-
ExpandSearchPhase phase = newExpandSearchPhase(
223-
mockSearchPhaseContext,
224-
new SearchResponseSections(hits, null, null, false, null, null, 1),
225-
null
226-
);
227-
phase.run();
228-
mockSearchPhaseContext.assertNoFailure();
229-
assertNotNull(mockSearchPhaseContext.searchResponse.get());
230-
} finally {
231-
hits.decRef();
232-
}
231+
ExpandSearchPhase phase = newExpandSearchPhase(
232+
mockSearchPhaseContext,
233+
new SearchResponseSections(
234+
new SearchHits(new SearchHit[] { hit1, hit2 }, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0F),
235+
null,
236+
null,
237+
false,
238+
null,
239+
null,
240+
1
241+
),
242+
null
243+
);
244+
phase.run();
245+
mockSearchPhaseContext.assertNoFailure();
246+
assertNotNull(mockSearchPhaseContext.searchResponse.get());
233247
} finally {
234248
mockSearchPhaseContext.results.close();
235249
var resp = mockSearchPhaseContext.searchResponse.get();
@@ -300,13 +314,20 @@ void sendExecuteMultiSearch(MultiSearchRequest request, SearchTask task, ActionL
300314

301315
SearchHit hit = new SearchHit(1, "ID");
302316
hit.setDocumentField("someField", new DocumentField("someField", Collections.singletonList("foo")));
303-
SearchHits hits = new SearchHits(new SearchHit[] { hit }, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0F);
304-
try (SearchResponseSections searchResponseSections = new SearchResponseSections(hits, null, null, false, null, null, 1)) {
317+
try (
318+
SearchResponseSections searchResponseSections = new SearchResponseSections(
319+
new SearchHits(new SearchHit[] { hit }, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0F),
320+
null,
321+
null,
322+
false,
323+
null,
324+
null,
325+
1
326+
)
327+
) {
305328
ExpandSearchPhase phase = newExpandSearchPhase(mockSearchPhaseContext, searchResponseSections, null);
306329
phase.run();
307330
mockSearchPhaseContext.assertNoFailure();
308-
} finally {
309-
hits.decRef();
310331
}
311332
} finally {
312333
mockSearchPhaseContext.results.close();
@@ -364,13 +385,20 @@ void sendExecuteMultiSearch(MultiSearchRequest request, SearchTask task, ActionL
364385

365386
SearchHit hit = new SearchHit(1, "ID");
366387
hit.setDocumentField("someField", new DocumentField("someField", Collections.singletonList("foo")));
367-
SearchHits hits = new SearchHits(new SearchHit[] { hit }, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0F);
368-
try (SearchResponseSections searchResponseSections = new SearchResponseSections(hits, null, null, false, null, null, 1)) {
388+
try (
389+
SearchResponseSections searchResponseSections = new SearchResponseSections(
390+
new SearchHits(new SearchHit[] { hit }, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0F),
391+
null,
392+
null,
393+
false,
394+
null,
395+
null,
396+
1
397+
)
398+
) {
369399
ExpandSearchPhase phase = newExpandSearchPhase(mockSearchPhaseContext, searchResponseSections, new AtomicArray<>(0));
370400
phase.run();
371401
mockSearchPhaseContext.assertNoFailure();
372-
} finally {
373-
hits.decRef();
374402
}
375403
} finally {
376404
mockSearchPhaseContext.results.close();

server/src/test/java/org/elasticsearch/action/search/FetchLookupFieldsPhaseTests.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,19 @@ void sendExecuteMultiSearch(MultiSearchRequest request, SearchTask task, ActionL
4646
for (int i = 0; i < searchHits.length; i++) {
4747
searchHits[i] = SearchHitTests.createTestItem(randomBoolean(), randomBoolean());
4848
}
49-
SearchHits hits = new SearchHits(searchHits, new TotalHits(numHits, TotalHits.Relation.EQUAL_TO), 1.0f);
50-
try (var sections = new SearchResponseSections(hits, null, null, false, null, null, 1)) {
49+
try (
50+
var sections = new SearchResponseSections(
51+
new SearchHits(searchHits, new TotalHits(numHits, TotalHits.Relation.EQUAL_TO), 1.0f),
52+
null,
53+
null,
54+
false,
55+
null,
56+
null,
57+
1
58+
)
59+
) {
5160
FetchLookupFieldsPhase phase = new FetchLookupFieldsPhase(searchPhaseContext, sections, null);
5261
phase.run();
53-
} finally {
54-
hits.decRef();
5562
}
5663
searchPhaseContext.assertNoFailure();
5764
assertNotNull(searchPhaseContext.searchResponse.get());
@@ -182,16 +189,19 @@ void sendExecuteMultiSearch(
182189
)
183190
);
184191
}
185-
SearchHits searchHits = new SearchHits(
186-
new SearchHit[] { leftHit0, leftHit1 },
187-
new TotalHits(2, TotalHits.Relation.EQUAL_TO),
188-
1.0f
189-
);
190-
try (var sections = new SearchResponseSections(searchHits, null, null, false, null, null, 1)) {
192+
try (
193+
var sections = new SearchResponseSections(
194+
new SearchHits(new SearchHit[] { leftHit0, leftHit1 }, new TotalHits(2, TotalHits.Relation.EQUAL_TO), 1.0f),
195+
null,
196+
null,
197+
false,
198+
null,
199+
null,
200+
1
201+
)
202+
) {
191203
FetchLookupFieldsPhase phase = new FetchLookupFieldsPhase(searchPhaseContext, sections, null);
192204
phase.run();
193-
} finally {
194-
searchHits.decRef();
195205
}
196206
assertTrue(requestSent.get());
197207
searchPhaseContext.assertNoFailure();

0 commit comments

Comments
 (0)