Skip to content

Commit

Permalink
Add SIMULATED_REQUEST
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Dec 15, 2023
1 parent 48e61d5 commit 10f411a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
*/
public class SearchTemplateRequest extends ActionRequest implements IndicesRequest.Replaceable, CompositeIndicesRequest, ToXContentObject {

private static SearchRequest SIMULATED_REQUEST = new SearchRequest(new String[0]);
private SearchRequest request;
private boolean simulate = false;
private boolean explain = false;
Expand Down Expand Up @@ -119,6 +120,9 @@ public boolean isSimulate() {
}

public void setSimulate(boolean simulate) {
if (simulate) {
this.request = SIMULATED_REQUEST;
}
this.simulate = simulate;
}

Expand Down Expand Up @@ -259,25 +263,16 @@ public void writeTo(StreamOutput out) throws IOException {

@Override
public String[] indices() {
if (simulate) {
return new String[0];
}
return request.indices();
}

@Override
public IndicesOptions indicesOptions() {
if (simulate) {
return SearchRequest.DEFAULT_INDICES_OPTIONS;
}
return request.indicesOptions();
}

@Override
public IndicesRequest indices(String... indices) {
if (simulate) {
return request;
}
return request.indices(indices);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,10 @@ public static SearchTemplateRequest createRandomRequest() {

public void testSimulatedSearchTemplateRequest() {
SearchTemplateRequest request = createRandomRequest();
request.setRequest(null);
request.setSimulate(true);

assertEquals(0, request.indices().length);
assertEquals(SearchRequest.DEFAULT_INDICES_OPTIONS, request.indicesOptions());
assertNull(request.indices("index1", "index2"));
assertEquals(2, request.indices("index1", "index2").indices().length);
}
}

0 comments on commit 10f411a

Please sign in to comment.