Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix IndexResponse#toString to print out shards info #20562

Merged
merged 1 commit into from
Sep 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.elasticsearch.action.index;

import org.elasticsearch.action.DocWriteResponse;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.rest.RestStatus;
Expand Down Expand Up @@ -56,7 +57,7 @@ public String toString() {
builder.append(",id=").append(getId());
builder.append(",version=").append(getVersion());
builder.append(",result=").append(getResult().getLowercase());
builder.append(",shards=").append(getShardInfo());
builder.append(",shards=").append(Strings.toString(getShardInfo(), true));
return builder.append("]").toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@

import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.action.support.replication.ReplicationResponse;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.ESTestCase;

import java.util.Arrays;
Expand Down Expand Up @@ -150,4 +153,34 @@ public void testAutoGenIdTimestampIsSet() {
request.process(null, true, "index");
assertEquals(IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, request.getAutoGeneratedTimestamp());
}

public void testIndexResponse() {
ShardId shardId = new ShardId(randomAsciiOfLengthBetween(3, 10), randomAsciiOfLengthBetween(3, 10), randomIntBetween(0, 1000));
String type = randomAsciiOfLengthBetween(3, 10);
String id = randomAsciiOfLengthBetween(3, 10);
long version = randomLong();
boolean created = randomBoolean();
IndexResponse indexResponse = new IndexResponse(shardId, type, id, version, created);
int total = randomIntBetween(1, 10);
int successful = randomIntBetween(1, 10);
ReplicationResponse.ShardInfo shardInfo = new ReplicationResponse.ShardInfo(total, successful);
indexResponse.setShardInfo(shardInfo);
boolean forcedRefresh = false;
if (randomBoolean()) {
forcedRefresh = randomBoolean();
indexResponse.setForcedRefresh(forcedRefresh);
}
assertEquals(type, indexResponse.getType());
assertEquals(id, indexResponse.getId());
assertEquals(version, indexResponse.getVersion());
assertEquals(shardId, indexResponse.getShardId());
assertEquals(created ? RestStatus.CREATED : RestStatus.OK, indexResponse.status());
assertEquals(total, indexResponse.getShardInfo().getTotal());
assertEquals(successful, indexResponse.getShardInfo().getSuccessful());
assertEquals(forcedRefresh, indexResponse.forcedRefresh());
assertEquals("IndexResponse[index=" + shardId.getIndexName() + ",type=" + type + ",id="+ id +
",version=" + version + ",result=" + (created ? "created" : "updated") +
",shards={\"_shards\":{\"total\":" + total + ",\"successful\":" + successful + ",\"failed\":0}}]",
indexResponse.toString());
}
}