Skip to content

Commit 9b3c579

Browse files
committed
scrollId still needed in a few places
1 parent 2114f93 commit 9b3c579

File tree

6 files changed

+20
-34
lines changed

6 files changed

+20
-34
lines changed

modules/reindex/src/test/java/org/elasticsearch/reindex/ClientScrollableHitSourceTests.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,7 @@ private SearchResponse createSearchResponse() {
167167
new TotalHits(0, TotalHits.Relation.EQUAL_TO),
168168
0
169169
);
170-
return SearchResponseUtils.response(hits)
171-
.scrollId(randomSimpleString(random(), 1, 10))
172-
.shards(5, 4, 0)
173-
.tookInMillis(randomLong())
174-
.build();
170+
return SearchResponseUtils.response(hits).scrollId(randomSimpleString(random(), 1, 10)).shards(5, 4, 0).build();
175171
}
176172

177173
private void assertSameHits(List<? extends ScrollableHitSource.Hit> actual, SearchHit[] expected) {

test/framework/src/main/java/org/elasticsearch/search/SearchResponseUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ public SearchResponseBuilder shardFailures(ShardSearchFailure... failures) {
193193
return this;
194194
}
195195

196+
public SearchResponseBuilder shardFailures(List<ShardSearchFailure> failures) {
197+
shardFailures = List.copyOf(failures);
198+
return this;
199+
}
200+
196201
public SearchResponseBuilder clusters(Clusters clusters) {
197202
this.clusters = clusters;
198203
return this;

x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichCacheTests.java

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
package org.elasticsearch.xpack.enrich;
88

9-
import org.elasticsearch.action.ActionListener;
109
import org.elasticsearch.action.search.SearchResponse;
1110
import org.elasticsearch.common.bytes.BytesReference;
1211
import org.elasticsearch.core.TimeValue;
@@ -27,6 +26,7 @@
2726
import java.util.concurrent.TimeUnit;
2827
import java.util.concurrent.atomic.AtomicLong;
2928

29+
import static org.elasticsearch.action.support.ActionTestUtils.assertNoFailureListener;
3030
import static org.hamcrest.Matchers.equalTo;
3131
import static org.hamcrest.Matchers.not;
3232
import static org.hamcrest.Matchers.notNullValue;
@@ -123,18 +123,10 @@ public void testComputeIfAbsent() throws InterruptedException {
123123
searchResponseActionListener.onResponse(searchResponse);
124124
searchResponse.decRef();
125125
queriedDatabaseLatch.countDown();
126-
}, new ActionListener<>() {
127-
@Override
128-
public void onResponse(List<Map<?, ?>> response) {
129-
assertThat(response, equalTo(searchResponseMap));
130-
notifiedOfResultLatch.countDown();
131-
}
132-
133-
@Override
134-
public void onFailure(Exception e) {
135-
fail(e);
136-
}
137-
});
126+
}, assertNoFailureListener(response -> {
127+
assertThat(response, equalTo(searchResponseMap));
128+
notifiedOfResultLatch.countDown();
129+
}));
138130
assertThat(queriedDatabaseLatch.await(5, TimeUnit.SECONDS), equalTo(true));
139131
assertThat(notifiedOfResultLatch.await(5, TimeUnit.SECONDS), equalTo(true));
140132
EnrichStatsAction.Response.CacheStats cacheStats = enrichCache.getStats(randomAlphaOfLength(10));
@@ -150,17 +142,7 @@ public void onFailure(Exception e) {
150142
CountDownLatch notifiedOfResultLatch = new CountDownLatch(1);
151143
enrichCache.computeIfAbsent("policy1-1", "1", 1, (searchResponseActionListener) -> {
152144
fail("Expected no call to the database because item should have been in the cache");
153-
}, new ActionListener<>() {
154-
@Override
155-
public void onResponse(List<Map<?, ?>> maps) {
156-
notifiedOfResultLatch.countDown();
157-
}
158-
159-
@Override
160-
public void onFailure(Exception e) {
161-
fail(e);
162-
}
163-
});
145+
}, assertNoFailureListener(r -> notifiedOfResultLatch.countDown()));
164146
assertThat(notifiedOfResultLatch.await(5, TimeUnit.SECONDS), equalTo(true));
165147
EnrichStatsAction.Response.CacheStats cacheStats = enrichCache.getStats(randomAlphaOfLength(10));
166148
assertThat(cacheStats.count(), equalTo(1L));
@@ -181,7 +163,7 @@ private SearchResponse convertToSearchResponse(List<Map<String, ?>> searchRespon
181163
}
182164
}).toArray(SearchHit[]::new);
183165
SearchHits hits = SearchHits.unpooled(hitArray, null, 0);
184-
return SearchResponseUtils.response(hits).shards(5, 4, 0).tookInMillis(randomLong()).build();
166+
return SearchResponseUtils.response(hits).shards(5, 4, 0).build();
185167
}
186168

187169
private BytesReference convertMapToJson(Map<String, ?> simpleMap) throws IOException {

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/saml/TransportSamlInvalidateSessionActionTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,18 @@ protected <Request extends ActionRequest, Response extends ActionResponse> void
201201
final SearchHit[] hits = searchFunction.apply(searchRequest);
202202
final var searchHits = new SearchHits(hits, new TotalHits(hits.length, TotalHits.Relation.EQUAL_TO), 0f);
203203
try {
204-
ActionListener.respondAndRelease(listener, (Response) SearchResponseUtils.successfulResponse(searchHits));
204+
ActionListener.respondAndRelease(
205+
listener,
206+
(Response) SearchResponseUtils.response(searchHits).scrollId("_scrollId1").build()
207+
);
205208
} finally {
206209
searchHits.decRef();
207210
}
208211
} else if (TransportSearchScrollAction.TYPE.name().equals(action.name())) {
209212
assertThat(request, instanceOf(SearchScrollRequest.class));
210213
ActionListener.respondAndRelease(
211214
listener,
212-
(Response) SearchResponseUtils.successfulResponse(SearchHits.EMPTY_WITH_TOTAL_HITS)
215+
(Response) SearchResponseUtils.response(SearchHits.EMPTY_WITH_TOTAL_HITS).scrollId("_scrollId1").build()
213216
);
214217
} else if (TransportClearScrollAction.NAME.equals(action.name())) {
215218
assertThat(request, instanceOf(ClearScrollRequest.class));

x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/pivot/PivotTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ protected <Request extends ActionRequest, Response extends ActionResponse> void
385385
listener,
386386
(Response) SearchResponseUtils.response(SearchHits.EMPTY_WITH_TOTAL_HITS)
387387
.shards(10, searchFailures.isEmpty() ? 5 : 0, 0)
388-
.shardFailures(searchFailures.toArray(ShardSearchFailure[]::new))
388+
.shardFailures(searchFailures)
389389
.build()
390390
);
391391
return;

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherServiceTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ void stopExecutor() {}
216216
SearchHits searchHits = SearchHits.unpooled(hits, new TotalHits(count, TotalHits.Relation.EQUAL_TO), 1.0f);
217217
doAnswer(invocation -> {
218218
ActionListener<SearchResponse> listener = (ActionListener<SearchResponse>) invocation.getArguments()[2];
219-
ActionListener.respondAndRelease(listener, SearchResponseUtils.successfulResponse(searchHits));
219+
ActionListener.respondAndRelease(listener, SearchResponseUtils.response(searchHits).scrollId("scrollId").build());
220220
return null;
221221
}).when(client).execute(eq(TransportSearchAction.TYPE), any(SearchRequest.class), anyActionListener());
222222

0 commit comments

Comments
 (0)