Skip to content

Commit

Permalink
Add warnings handler for deprecated master terminology
Browse files Browse the repository at this point in the history
Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
  • Loading branch information
nknize committed Mar 23, 2022
1 parent 7a712d5 commit b4b190e
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,31 @@
import org.opensearch.Version;
import org.opensearch.client.Node;
import org.opensearch.client.Request;
import org.opensearch.client.RequestOptions;
import org.opensearch.client.Response;
import org.opensearch.client.ResponseException;
import org.opensearch.test.rest.OpenSearchRestTestCase;
import org.opensearch.test.rest.yaml.ObjectPath;

import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static org.apache.http.HttpStatus.SC_NOT_FOUND;

public class ExceptionIT extends OpenSearchRestTestCase {
private Set<String> assertedWarnings = new HashSet<>();

public void testOpensearchException() throws Exception {
logClusterNodes();

Request request = new Request("GET", "/no_such_index");

String expectedWarning = "[GET /_cat/master] is deprecated! Use [GET /_cat/cluster_manager] instead.";
request.setOptions(expectWarnings(expectedWarning));

for (Node node : client().getNodes()) {
try {
client().setNodes(Collections.singletonList(node));
Expand All @@ -44,10 +52,22 @@ public void testOpensearchException() throws Exception {
}
}

private RequestOptions expectWarnings(String expectedWarning) {
final RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
if (!assertedWarnings.contains(expectedWarning)) {
builder.setWarningsHandler(w -> w.contains(expectedWarning) == false || w.size() != 1);
assertedWarnings.add(expectedWarning);
}
return builder.build();
}

private void logClusterNodes() throws IOException {
ObjectPath objectPath = ObjectPath.createFromResponse(client().performRequest(new Request("GET", "_nodes")));
Map<String, ?> nodes = objectPath.evaluate("nodes");
String master = EntityUtils.toString(client().performRequest(new Request("GET", "_cat/master?h=id")).getEntity()).trim();
Request request = new Request("GET", "_cat/master?h=id");
String expectedWarning = "[GET /_cat/master] is deprecated! Use [GET /_cat/cluster_manager] instead.";
request.setOptions(expectWarnings(expectedWarning));
String master = EntityUtils.toString(client().performRequest(request).getEntity()).trim();
logger.info("cluster discovered: master id='{}'", master);
for (String id : nodes.keySet()) {
logger.info("{}: id='{}', name='{}', version={}",
Expand Down

0 comments on commit b4b190e

Please sign in to comment.