Skip to content

Commit

Permalink
Fix remaining tests that set indices on PIT request
Browse files Browse the repository at this point in the history
  • Loading branch information
jimczi committed Dec 11, 2023
1 parent aea7785 commit 3317b31
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,18 @@ public void testRetryPointInTime() throws Exception {
).keepAlive(TimeValue.timeValueMinutes(2));
final String pitId = client().execute(TransportOpenPointInTimeAction.TYPE, openRequest).actionGet().getPointInTimeId();
try {
assertNoFailuresAndResponse(
prepareSearch().setIndices(indexName).setPreference(null).setPointInTime(new PointInTimeBuilder(pitId)),
resp -> {
assertThat(resp.pointInTimeId(), equalTo(pitId));
assertHitCount(resp, docCount);
}
);
assertNoFailuresAndResponse(prepareSearch().setPointInTime(new PointInTimeBuilder(pitId)), resp -> {
assertThat(resp.pointInTimeId(), equalTo(pitId));
assertHitCount(resp, docCount);
});
final Set<String> allocatedNodes = internalCluster().nodesInclude(indexName);
for (String allocatedNode : allocatedNodes) {
internalCluster().restartNode(allocatedNode);
}
ensureGreen(indexName);
assertNoFailuresAndResponse(
prepareSearch().setIndices(indexName)
.setQuery(new RangeQueryBuilder("created_date").gte("2011-01-01").lte("2011-12-12"))
prepareSearch().setQuery(new RangeQueryBuilder("created_date").gte("2011-01-01").lte("2011-12-12"))
.setSearchType(SearchType.QUERY_THEN_FETCH)
.setPreference(null)
.setPreFilterShardSize(between(1, 10))
.setAllowPartialSearchResults(true)
.setPointInTime(new PointInTimeBuilder(pitId)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,6 @@ void doSearch(Tuple<String, SearchRequest> namedSearchRequest, ActionListener<Se
listener.onResponse(null);
return;
}
logger.info("searchRequest: [{}]", originalRequest);

final SearchRequest searchRequest;
PointInTimeBuilder pit = originalRequest.pointInTimeBuilder();
Expand All @@ -536,6 +535,7 @@ void doSearch(Tuple<String, SearchRequest> namedSearchRequest, ActionListener<Se
} else {
searchRequest = originalRequest;
}
logger.trace("searchRequest: [{}]", searchRequest);

ClientHelper.executeWithHeadersAsync(
transformConfig.getHeaders(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@

import java.time.Clock;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -420,8 +419,9 @@ public void testHandlePitIndexNotFound() throws InterruptedException {
try (var threadPool = createThreadPool()) {
final var client = new PitMockClient(threadPool, true);
ClientTransformIndexer indexer = createTestIndexer(new ParentTaskAssigningClient(client, new TaskId("dummy-node:123456")));
SearchRequest searchRequest = new SearchRequest("deleted-index");
searchRequest.source().pointInTimeBuilder(new PointInTimeBuilder("the_pit_id"));
SearchRequest searchRequest = new SearchRequest("deleted-index").source(
new SearchSourceBuilder().pointInTimeBuilder(new PointInTimeBuilder("the_pit_id_on_deleted_index"))
);
Tuple<String, SearchRequest> namedSearchRequest = new Tuple<>("test-handle-pit-index-not-found", searchRequest);
this.<SearchResponse>assertAsync(listener -> indexer.doSearch(namedSearchRequest, listener), response -> {
// if the pit got deleted, we know it retried
Expand All @@ -433,8 +433,9 @@ public void testHandlePitIndexNotFound() throws InterruptedException {
try (var threadPool = createThreadPool()) {
final var client = new PitMockClient(threadPool, true);
ClientTransformIndexer indexer = createTestIndexer(new ParentTaskAssigningClient(client, new TaskId("dummy-node:123456")));
SearchRequest searchRequest = new SearchRequest("essential-deleted-index");
searchRequest.source().pointInTimeBuilder(new PointInTimeBuilder("the_pit_id"));
SearchRequest searchRequest = new SearchRequest("essential-deleted-index").source(
new SearchSourceBuilder().pointInTimeBuilder(new PointInTimeBuilder("the_pit_id_essential-deleted-index"))
);
Tuple<String, SearchRequest> namedSearchRequest = new Tuple<>("test-handle-pit-index-not-found", searchRequest);
indexer.doSearch(namedSearchRequest, ActionListener.wrap(r -> fail("expected a failure, got response"), e -> {
assertTrue(e instanceof IndexNotFoundException);
Expand Down Expand Up @@ -521,14 +522,16 @@ protected <Request extends ActionRequest, Response extends ActionResponse> void
listener.onResponse((Response) response);
return;
} else if (request instanceof SearchRequest searchRequest) {

// if pit is used and deleted-index is given throw index not found
if (searchRequest.pointInTimeBuilder() != null && Arrays.binarySearch(searchRequest.indices(), "deleted-index") >= 0) {
if (searchRequest.pointInTimeBuilder() != null
&& searchRequest.pointInTimeBuilder().getEncodedId().equals("the_pit_id_on_deleted_index")) {
listener.onFailure(new IndexNotFoundException("deleted-index"));
return;
}

if (Arrays.binarySearch(searchRequest.indices(), "essential-deleted-index") >= 0) {
if ((searchRequest.pointInTimeBuilder() != null
&& searchRequest.pointInTimeBuilder().getEncodedId().equals("the_pit_id_essential-deleted-index"))
|| searchRequest.indices()[0].equals("essential-deleted-index")) {
listener.onFailure(new IndexNotFoundException("essential-deleted-index"));
return;
}
Expand Down Expand Up @@ -564,7 +567,6 @@ protected <Request extends ActionRequest, Response extends ActionResponse> void
}
return;
}

super.doExecute(action, request, listener);
}
}
Expand Down

0 comments on commit 3317b31

Please sign in to comment.