Skip to content

Commit

Permalink
Fix unit test failure and remove unused codes
Browse files Browse the repository at this point in the history
Signed-off-by: Tianli Feng <ftianli@amazon.com>
  • Loading branch information
Tianli Feng committed Jun 2, 2022
1 parent 97d0558 commit b54ea87
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,31 +268,6 @@ private static Node readNode(String nodeId, JsonParser parser, Scheme scheme) th
return new Node(publishedHost, boundHosts, name, version, new Roles(roles), unmodifiableMap(realAttributes));
}

/**
* Returns {@code defaultValue} if the attribute didn't come back,
* {@code true} or {@code false} if it did come back as
* either of those, or throws an IOException if the attribute
* came back in a strange way.
*/
private static Boolean v2RoleAttributeValue(Map<String, List<String>> attributes, String name, Boolean defaultValue)
throws IOException {
List<String> valueList = attributes.remove(name);
if (valueList == null) {
return defaultValue;
}
if (valueList.size() != 1) {
throw new IOException("expected only a single attribute value for [" + name + "] but got " + valueList);
}
switch (valueList.get(0)) {
case "true":
return true;
case "false":
return false;
default:
throw new IOException("expected [" + name + "] to be either [true] or [false] but was [" + valueList.get(0) + "]");
}
}

/**
* The supported host schemes.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void test1x() throws IOException {
node(9200, "m1", "1.0.0", "master", "ingest"),
node(9201, "m2", "1.0.0", "master", "data", "ingest"),
node(9202, "m3", "1.0.0", "master", "ingest"),
node(9203, "d1", "1.0.0", "data", "ingest", "ml"),
node(9203, "d1", "1.0.0", "data", "ingest"),
node(9204, "d2", "1.0.0", "data", "ingest"),
node(9205, "d3", "1.0.0", "data", "ingest"),
node(9206, "c1", "1.0.0", "ingest"),
Expand All @@ -105,7 +105,7 @@ public void test2x() throws IOException {
node(9200, "m1", "2.0.0", "cluster_manager", "ingest"),
node(9201, "m2", "2.0.0", "cluster_manager", "data", "ingest"),
node(9202, "m3", "2.0.0", "cluster_manager", "ingest"),
node(9203, "d1", "2.0.0", "data", "ingest", "ml"),
node(9203, "d1", "2.0.0", "data", "ingest"),
node(9204, "d2", "2.0.0", "data", "ingest"),
node(9205, "d3", "2.0.0", "data", "ingest"),
node(9206, "c1", "2.0.0", "ingest"),
Expand Down Expand Up @@ -142,12 +142,16 @@ private Node node(int port, String name, String version, String... roles) {
private Node node(int port, String name, String version, Set<String> roles) {
HttpHost host = new HttpHost("127.0.0.1", port);
Set<HttpHost> boundHosts = new HashSet<>(2);
boundHosts.add(host);
boundHosts.add(new HttpHost("[::1]", port));
boundHosts.add(host);
Map<String, List<String>> attributes = new HashMap<>();
attributes.put("dummy", singletonList("everyone_has_me"));
attributes.put("number", singletonList(name.substring(1)));
attributes.put("array", Arrays.asList(name.substring(0, 1), name.substring(1)));
attributes.put("array", singletonList(Arrays.asList(name.substring(0, 1), name.substring(1)).toString()));
if (!version.startsWith("1.0") && !version.startsWith("1.1")) {
// Shard Indexing Pressure feature is added in version 1.2.0
attributes.put("shard_indexing_pressure_enabled", singletonList(Boolean.TRUE.toString()));
}
return new Node(host, boundHosts, name, version, new Roles(new TreeSet<>(roles)), attributes);
}

Expand Down
32 changes: 16 additions & 16 deletions client/sniffer/src/test/resources/2.0.0_nodes_http.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
},
"http": {
"bound_address": [
"127.0.0.1:9200",
"[::1]:9200"
"[::1]:9200",
"127.0.0.1:9200"
],
"publish_address": "127.0.0.1:9200",
"max_content_length_in_bytes": 104857600
Expand All @@ -54,8 +54,8 @@
},
"http": {
"bound_address": [
"127.0.0.1:9201",
"[::1]:9201"
"[::1]:9201",
"127.0.0.1:9201"
],
"publish_address": "127.0.0.1:9201",
"max_content_length_in_bytes": 104857600
Expand All @@ -81,8 +81,8 @@
},
"http": {
"bound_address": [
"127.0.0.1:9202",
"[::1]:9202"
"[::1]:9202",
"127.0.0.1:9202"
],
"publish_address": "127.0.0.1:9202",
"max_content_length_in_bytes": 104857600
Expand All @@ -108,8 +108,8 @@
},
"http": {
"bound_address": [
"127.0.0.1:9203",
"[::1]:9203"
"[::1]:9203",
"127.0.0.1:9203"
],
"publish_address": "127.0.0.1:9203",
"max_content_length_in_bytes": 104857600
Expand All @@ -135,8 +135,8 @@
},
"http": {
"bound_address": [
"127.0.0.1:9204",
"[::1]:9204"
"[::1]:9204",
"127.0.0.1:9204"
],
"publish_address": "127.0.0.1:9204",
"max_content_length_in_bytes": 104857600
Expand All @@ -162,8 +162,8 @@
},
"http": {
"bound_address": [
"127.0.0.1:9205",
"[::1]:9205"
"[::1]:9205",
"127.0.0.1:9205"
],
"publish_address": "127.0.0.1:9205",
"max_content_length_in_bytes": 104857600
Expand All @@ -188,8 +188,8 @@
},
"http": {
"bound_address": [
"127.0.0.1:9206",
"[::1]:9206"
"[::1]:9206",
"127.0.0.1:9206"
],
"publish_address": "127.0.0.1:9206",
"max_content_length_in_bytes": 104857600
Expand All @@ -214,8 +214,8 @@
},
"http": {
"bound_address": [
"127.0.0.1:9207",
"[::1]:9207"
"[::1]:9207",
"127.0.0.1:9207"
],
"publish_address": "127.0.0.1:9207",
"max_content_length_in_bytes": 104857600
Expand Down
6 changes: 4 additions & 2 deletions client/sniffer/src/test/resources/create_test_nodes_info.bash
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ function do_version() {
cp -r opensearch-${version}/* ${node}
local cluster_manager=$([[ "$node" =~ ^m.* ]] && echo 'cluster_manager,' || echo '')
# 'cluster_manager' role is add in version 2.x and above, use 'master' role in 1.x
cluster_manager=$([[ ! "$cluster_manager" == '' && ${version} =~ ^1 ]] && echo 'master,' || echo ${cluster_manager})
cluster_manager=$([[ ! "$cluster_manager" == '' && ${version} =~ ^1\. ]] && echo 'master,' || echo ${cluster_manager})
local data=$([[ "$node" =~ ^d.* ]] && echo 'data,' || echo '')
# m2 is always cluster_manager and data for these test just so we have a node like that
data=$([[ "$node" == 'm2' ]] && echo 'data,' || echo ${data})
# setting name 'cluster.initial_cluster_manager_nodes' is add in version 2.x and above
local initial_cluster_manager_nodes=$([[ ${version} =~ ^1\. ]] && echo 'initial_master_nodes' || echo 'initial_cluster_manager_nodes')
local transport_port=$((http_port+100))

cat >> ${node}/config/opensearch.yml << __OPENSEARCH_YML
Expand All @@ -57,7 +59,7 @@ node.attr.number: ${node:1}
node.attr.array: [${node:0:1}, ${node:1}]
http.port: ${http_port}
transport.tcp.port: ${transport_port}
cluster.initial_master_nodes: [m1, m2, m3]
cluster.${initial_cluster_manager_nodes}: [m1, m2, m3]
discovery.seed_hosts: ['localhost:9300','localhost:9301','localhost:9302']
__OPENSEARCH_YML

Expand Down

0 comments on commit b54ea87

Please sign in to comment.