Skip to content

Commit

Permalink
[TEST] more consistent toString on cluster state, print with assertTi…
Browse files Browse the repository at this point in the history
…meout
  • Loading branch information
kimchy committed Jul 8, 2014
1 parent feb81e2 commit 6a4f61a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -234,22 +235,15 @@ public void writeTo(StreamOutput out) throws IOException {

@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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static void assertNoTimeout(ClusterHealthRequestBuilder requestBuilder) {
}

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) {
Expand Down

0 comments on commit 6a4f61a

Please sign in to comment.