[TEST] more consistent toString on cluster state, print with assertTimeout

This commit is contained in:
Shay Banon 2014-07-08 13:08:38 +02:00
parent feb81e228b
commit 6a4f61a7d2
2 changed files with 10 additions and 16 deletions

View File

@ -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<Cl
@Override
public String toString() {
StringBuilder builder = new StringBuilder("ClusterHealthResponse - status [").append(status).append("]")
.append("\ntimedOut [").append(timedOut).append("]")
.append("\nclustername [").append(clusterName).append("]")
.append("\nnumberOfNodes [").append(numberOfNodes).append("]")
.append("\nnumberOfDataNodes [").append(numberOfDataNodes).append("]")
.append("\nactiveShards [").append(activeShards).append("]")
.append("\nrelocatingShards [").append(relocatingShards).append("]")
.append("\nactivePrimaryShards [").append(activePrimaryShards).append("]")
.append("\ninitializingShards [").append(initializingShards).append("]")
.append("\nvalidationFailures ").append(validationFailures)
.append("\nindices:");
for (Map.Entry<String, ClusterIndexHealth> 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 {

View File

@ -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) {