From 9d5e7895080cd186f8cea327f4fa43445476bee6 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Wed, 27 May 2015 17:38:31 +0200 Subject: [PATCH] Cat API: Do not rely on hashmap for sorted entries The tests for the recently added added wildcard feature were relying on order of the hashmap being used, which could be different. The implementation now ensures, that the header fields are parsed in the order they have been added. --- rest-api-spec/test/cat.thread_pool/10_basic.yaml | 2 +- .../org/elasticsearch/rest/action/support/RestTable.java | 9 ++++----- .../elasticsearch/rest/action/support/RestTableTest.java | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/rest-api-spec/test/cat.thread_pool/10_basic.yaml b/rest-api-spec/test/cat.thread_pool/10_basic.yaml index 37994201191..283e353b7a3 100755 --- a/rest-api-spec/test/cat.thread_pool/10_basic.yaml +++ b/rest-api-spec/test/cat.thread_pool/10_basic.yaml @@ -36,7 +36,7 @@ - match: $body: | - /^ bulk.max \s+ bulk.min \s+ \n + /^ bulk.min \s+ bulk.max \s+ \n (\s+ \d+ \s+ \d+ \s+ \n)+ $/ #(\s+ \d+ \s+ \d+ \n)+ $/ diff --git a/src/main/java/org/elasticsearch/rest/action/support/RestTable.java b/src/main/java/org/elasticsearch/rest/action/support/RestTable.java index 0b5b44112f4..3e6eb713529 100644 --- a/src/main/java/org/elasticsearch/rest/action/support/RestTable.java +++ b/src/main/java/org/elasticsearch/rest/action/support/RestTable.java @@ -157,16 +157,15 @@ public class RestTable { private static Set expandHeadersFromRequest(Table table, RestRequest request) { Set headers = new LinkedHashSet<>(table.getHeaders().size()); - Map headerMap = table.getHeaderMap(); // check headers and aliases for (String header : Strings.splitStringByCommaToArray(request.param("h"))) { if (Regex.isSimpleMatchPattern(header)) { - for (Map.Entry configuredHeaderEntry : headerMap.entrySet()) { - String configuredHeader = configuredHeaderEntry.getKey(); + for (Table.Cell tableHeaderCell : table.getHeaders()) { + String configuredHeader = tableHeaderCell.value.toString(); if (Regex.simpleMatch(header, configuredHeader)) { headers.add(configuredHeader); - } else if (configuredHeaderEntry.getValue().attr.containsKey("alias")) { - String[] aliases = Strings.splitStringByCommaToArray(configuredHeaderEntry.getValue().attr.get("alias")); + } else if (tableHeaderCell.attr.containsKey("alias")) { + String[] aliases = Strings.splitStringByCommaToArray(tableHeaderCell.attr.get("alias")); for (String alias : aliases) { if (Regex.simpleMatch(header, alias)) { headers.add(configuredHeader); diff --git a/src/test/java/org/elasticsearch/rest/action/support/RestTableTest.java b/src/test/java/org/elasticsearch/rest/action/support/RestTableTest.java index bdf0a07cbf5..3faa0ea3673 100644 --- a/src/test/java/org/elasticsearch/rest/action/support/RestTableTest.java +++ b/src/test/java/org/elasticsearch/rest/action/support/RestTableTest.java @@ -57,7 +57,7 @@ public class RestTableTest extends ElasticsearchTestCase { List headers = buildDisplayHeaders(table, restRequest); List headerNames = getHeaderNames(headers); - assertThat(headerNames, containsInAnyOrder("bulk.foo", "bulk.bar", "aliasedBulk", "aliasedSecondBulk")); + assertThat(headerNames, contains("bulk.foo", "bulk.bar", "aliasedBulk", "aliasedSecondBulk")); assertThat(headerNames, not(hasItem("unmatched"))); } @@ -67,7 +67,7 @@ public class RestTableTest extends ElasticsearchTestCase { List headers = buildDisplayHeaders(table, restRequest); List headerNames = getHeaderNames(headers); - assertThat(headerNames, containsInAnyOrder("bulk.foo", "bulk.bar", "aliasedBulk", "aliasedSecondBulk")); + assertThat(headerNames, contains("bulk.foo", "bulk.bar", "aliasedBulk", "aliasedSecondBulk")); assertThat(headerNames, not(hasItem("unmatched"))); }