Fixes random failures of org.apache.elasticsearch.test.rest.RestIT

RestTable: ignores right padding for the last cell of a column.
This commit is contained in:
Jim Ferenczi 2015-12-08 20:52:24 +01:00
parent d866906612
commit 23aeaa88b2
5 changed files with 21 additions and 13 deletions

View File

@ -79,8 +79,9 @@ public class RestTable {
if (verbose) { if (verbose) {
for (int col = 0; col < headers.size(); col++) { for (int col = 0; col < headers.size(); col++) {
DisplayHeader header = headers.get(col); DisplayHeader header = headers.get(col);
pad(new Table.Cell(header.display, table.findHeaderByName(header.name)), width[col], request, out); boolean isLastColumn = col == lastHeader;
if (col != lastHeader) { pad(new Table.Cell(header.display, table.findHeaderByName(header.name)), width[col], request, out, isLastColumn);
if (!isLastColumn) {
out.append(" "); out.append(" ");
} }
} }
@ -89,8 +90,9 @@ public class RestTable {
for (int row = 0; row < table.getRows().size(); row++) { for (int row = 0; row < table.getRows().size(); row++) {
for (int col = 0; col < headers.size(); col++) { for (int col = 0; col < headers.size(); col++) {
DisplayHeader header = headers.get(col); DisplayHeader header = headers.get(col);
pad(table.getAsMap().get(header.name).get(row), width[col], request, out); boolean isLastColumn = col == lastHeader;
if (col != lastHeader) { pad(table.getAsMap().get(header.name).get(row), width[col], request, out, isLastColumn);
if (!isLastColumn) {
out.append(" "); out.append(" ");
} }
} }
@ -240,6 +242,10 @@ public class RestTable {
} }
public static void pad(Table.Cell cell, int width, RestRequest request, UTF8StreamWriter out) throws IOException { public static void pad(Table.Cell cell, int width, RestRequest request, UTF8StreamWriter out) throws IOException {
pad(cell, width, request, out, false);
}
public static void pad(Table.Cell cell, int width, RestRequest request, UTF8StreamWriter out, boolean isLast) throws IOException {
String sValue = renderValue(request, cell.value); String sValue = renderValue(request, cell.value);
int length = sValue == null ? 0 : sValue.length(); int length = sValue == null ? 0 : sValue.length();
byte leftOver = (byte) (width - length); byte leftOver = (byte) (width - length);
@ -258,8 +264,11 @@ public class RestTable {
if (sValue != null) { if (sValue != null) {
out.append(sValue); out.append(sValue);
} }
for (byte i = 0; i < leftOver; i++) { // Ignores the leftover spaces if the cell is the last of the column.
out.append(" "); if (!isLast) {
for (byte i = 0; i < leftOver; i++) {
out.append(" ");
}
} }
} }
} }

View File

@ -185,6 +185,6 @@
- match: - match:
$body: | $body: |
/^ /^
index \s+ alias \s+ \n index \s+ alias \n
test \s+ test_1 \n test \s+ test_1 \n
$/ $/

View File

@ -156,7 +156,7 @@
disk.percent \s+ disk.percent \s+
host \s+ host \s+
ip \s+ ip \s+
node \s+ node
\n \n
( \s* #allow leading spaces to account for right-justified text ( \s* #allow leading spaces to account for right-justified text
@ -199,7 +199,7 @@
$body: | $body: |
/^ /^
disk.percent \s+ disk.percent \s+
node \s+ node
\n \n
( (
\s+\d* \s+ \s+\d* \s+

View File

@ -19,7 +19,7 @@
- match: - match:
$body: | $body: |
/# epoch timestamp count /# epoch timestamp count
^ \d+ \s \d{2}:\d{2}:\d{2} \s 0 \n $/ ^ \d+ \s \d{2}:\d{2}:\d{2} \s 0 \n$/
- do: - do:
index: index:
@ -72,5 +72,4 @@
- match: - match:
$body: | $body: |
/^ epoch \s+ timestamp \s+ count \n /^ epoch \s+ timestamp \s+ count \n
\d+ \s+ \d{2}:\d{2}:\d{2} \s+ \d+ \s+ \n $/ \d+ \s+ \d{2}:\d{2}:\d{2} \s+ \d+ \n $/

View File

@ -15,7 +15,7 @@
- match: - match:
$body: | $body: |
/^ host \s+ ip \s+ heap\.percent \s+ ram\.percent \s+ cpu \s+ load \s+ node\.role \s+ master \s+ name \s+ \n /^ host \s+ ip \s+ heap\.percent \s+ ram\.percent \s+ cpu \s+ load \s+ node\.role \s+ master \s+ name \n
(\S+ \s+ (\d{1,3}\.){3}\d{1,3} \s+ \d+ \s+ \d* \s+ \d* \s+ (-)?\d*(\.\d+)? \s+ [-dc] \s+ [-*mx] \s+ (\S+\s?)+ \n)+ $/ (\S+ \s+ (\d{1,3}\.){3}\d{1,3} \s+ \d+ \s+ \d* \s+ \d* \s+ (-)?\d*(\.\d+)? \s+ [-dc] \s+ [-*mx] \s+ (\S+\s?)+ \n)+ $/
- do: - do: