Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toString() to MultiSearchRequest class. #12163

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add support for dependencies in plugin descriptor properties with semver range ([#11441](https://github.com/opensearch-project/OpenSearch/pull/11441))
- Add community_id ingest processor ([#12121](https://github.com/opensearch-project/OpenSearch/pull/12121))
- Introduce query level setting `index.query.max_nested_depth` limiting nested queries ([#3268](https://github.com/opensearch-project/OpenSearch/issues/3268)
- Add toString methods to MultiSearchRequest, MultiGetRequest and CreateIndexRequest ([#12163](https://github.com/opensearch-project/OpenSearch/pull/12163))

### Dependencies

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,4 +594,25 @@ public void writeTo(StreamOutput out) throws IOException {
}
waitForActiveShards.writeTo(out);
}

@Override
public String toString() {
return "CreateIndexRequest{"
+ "cause='"
+ cause
+ '\''
+ ", index='"
+ index
+ '\''
+ ", settings="
+ settings
+ ", mappings='"
+ mappings
+ '\''
+ ", aliases="
+ aliases
+ ", waitForActiveShards="
+ waitForActiveShards
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -583,4 +583,19 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder;
}

@Override
public String toString() {
return "MultiGetRequest{"
+ "preference='"
+ preference
+ '\''
+ ", realtime="
+ realtime
+ ", refresh="
+ refresh
+ ", items="
+ items
+ '}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,16 @@ public boolean shouldCancelChildrenOnCancellation() {
}
};
}

@Override
public String toString() {
return "MultiSearchRequest{"
+ "maxConcurrentSearchRequests="
+ maxConcurrentSearchRequests
+ ", requests="
+ requests
+ ", indicesOptions="
+ indicesOptions
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.Map;
import java.util.Set;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;

public class CreateIndexRequestTests extends OpenSearchTestCase {
Expand Down Expand Up @@ -150,6 +151,20 @@ public void testSettingsType() throws IOException {
assertThat(e.getMessage(), equalTo("key [settings] must be an object"));
}

public void testToString() throws IOException {
CreateIndexRequest request = new CreateIndexRequest("foo");
String mapping = JsonXContent.contentBuilder()
.startObject()
.startObject(MapperService.SINGLE_MAPPING_NAME)
.endObject()
.endObject()
.toString();
request.mapping(mapping);

assertThat(request.toString(), containsString("index='foo'"));
assertThat(request.toString(), containsString("mappings='{\"_doc\":{}}'"));
}

public static void assertMappingsEqual(Map<String, String> expected, Map<String, String> actual) throws IOException {
assertEquals(expected.keySet(), actual.keySet());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package org.opensearch.action.get;

import org.opensearch.action.get.MultiGetRequest.Item;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.common.ParsingException;
Expand Down Expand Up @@ -141,6 +142,13 @@ public void testXContentSerialization() throws IOException {
}
}

public void testToString() {
MultiGetRequest req = createTestInstance();
for (Item items : req.getItems()) {
assertThat(req.toString(), containsString(items.toString()));
}
}

private MultiGetRequest createTestInstance() {
int numItems = randomIntBetween(0, 128);
MultiGetRequest request = new MultiGetRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import static java.util.Collections.singletonList;
import static org.opensearch.search.RandomSearchRequestGenerator.randomSearchRequest;
import static org.opensearch.test.EqualsHashCodeTestUtils.checkEqualsAndHashCode;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -560,6 +561,13 @@ public void testEqualsAndHashcode() {
checkEqualsAndHashCode(createMultiSearchRequest(), MultiSearchRequestTests::copyRequest, MultiSearchRequestTests::mutate);
}

public void testToString() {
MultiSearchRequest req = createMultiSearchRequest();
for (SearchRequest subReq : req.requests()) {
assertThat(req.toString(), containsString(subReq.toString()));
}
}

private static MultiSearchRequest mutate(MultiSearchRequest searchRequest) throws IOException {
MultiSearchRequest mutation = copyRequest(searchRequest);
List<CheckedRunnable<IOException>> mutators = new ArrayList<>();
Expand Down
Loading