From 6a4f61a7d2d2555716c18d3252225fd6df04d330 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Tue, 8 Jul 2014 13:08:38 +0200 Subject: [PATCH] [TEST] more consistent toString on cluster state, print with assertTimeout --- .../cluster/health/ClusterHealthResponse.java | 24 +++++++------------ .../hamcrest/ElasticsearchAssertions.java | 2 +- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java b/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java index 56f594d9807..0347ab431ae 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java @@ -31,6 +31,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; +import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.rest.RestStatus; import java.io.IOException; @@ -234,22 +235,15 @@ public class ClusterHealthResponse extends ActionResponse implements Iterable indexEntry : indices.entrySet()) { - builder.append(" [").append(indexEntry.getKey()).append("][").append(indexEntry.getValue().status).append("]"); + try { + XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint(); + builder.startObject(); + toXContent(builder, EMPTY_PARAMS); + builder.endObject(); + return builder.string(); + } catch (IOException e) { + return "{ \"error\" : \"" + e.getMessage() + "\"}"; } - return builder.toString(); } static final class Fields { diff --git a/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java b/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java index 95a06822e66..ed7e41a8c44 100644 --- a/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java +++ b/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java @@ -94,7 +94,7 @@ public class ElasticsearchAssertions { } public static void assertNoTimeout(ClusterHealthResponse response) { - assertThat("ClusterHealthResponse has timed out - returned status: [" + response.getStatus() + "]", response.isTimedOut(), is(false)); + assertThat("ClusterHealthResponse has timed out - returned: [" + response + "]", response.isTimedOut(), is(false)); } public static void assertAcked(AcknowledgedResponse response) {