[TEST] Check for total shards >= number of shards instead of ==

Requests are sent to two shard copies in case a shard is relocating.
This will show up in the the _shards header. Therefore we must check
with greaterThanOrEqualTo(..).
This commit is contained in:
Britta Weber 2015-01-23 13:25:03 +01:00
parent eeb96db76b
commit 35e507ad54
4 changed files with 9 additions and 8 deletions

View File

@ -78,14 +78,14 @@ public abstract class ActionWriteResponse extends ActionResponse {
}
/**
* @return the total number of shards the write should go to.
* @return the total number of shards the write should go to (replicas and primaries). This includes relocating shards, so this number can be higher than the number of shards.
*/
public int getTotal() {
return total;
}
/**
* @return the total number of shards the write succeeded on.
* @return the total number of shards the write succeeded on (replicas and primaries). This includes relocating shards, so this number can be higher than the number of shards.
*/
public int getSuccessful() {
return successful;

View File

@ -191,8 +191,8 @@ public class DeleteByQueryTests extends ElasticsearchIntegrationTest {
}
private void assertSyncShardInfo(ActionWriteResponse.ShardInfo shardInfo, NumShards numShards) {
assertThat(shardInfo.getTotal(), equalTo(numShards.totalNumShards));
assertThat(shardInfo.getSuccessful(), greaterThanOrEqualTo(numShards.numPrimaries));
assertThat(shardInfo.getTotal(), greaterThanOrEqualTo(numShards.totalNumShards));
assertThat(shardInfo.getSuccessful(), greaterThanOrEqualTo(numShards.totalNumShards));
assertThat(shardInfo.getPending(), equalTo(0));
assertThat(shardInfo.getFailed(), equalTo(0));
for (ActionWriteResponse.ShardInfo.Failure failure : shardInfo.getFailures()) {

View File

@ -48,6 +48,7 @@ import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.nullValue;
/**
@ -187,8 +188,8 @@ public class DocumentActionsTests extends ElasticsearchIntegrationTest {
logger.info("Delete by query");
DeleteByQueryResponse queryResponse = client().prepareDeleteByQuery().setIndices("test").setQuery(termQuery("name", "test2")).execute().actionGet();
assertThat(queryResponse.getIndex(getConcreteIndexName()).getShardInfo().getTotal(), equalTo(numShards.totalNumShards));
assertThat(queryResponse.getIndex(getConcreteIndexName()).getShardInfo().getSuccessful(), equalTo(numShards.totalNumShards));
assertThat(queryResponse.getIndex(getConcreteIndexName()).getShardInfo().getTotal(), greaterThanOrEqualTo(numShards.totalNumShards));
assertThat(queryResponse.getIndex(getConcreteIndexName()).getShardInfo().getSuccessful(), greaterThanOrEqualTo(numShards.totalNumShards));
assertThat(queryResponse.getIndex(getConcreteIndexName()).getShardInfo().getFailures().length, equalTo(0));
client().admin().indices().refresh(refreshRequest("test")).actionGet();

View File

@ -156,8 +156,8 @@ public class ShardInfoTests extends ElasticsearchIntegrationTest {
}
private void assertShardInfo(ActionWriteResponse response, int expectedTotal, int expectedSuccessful, int expectedPending) {
assertThat(response.getShardInfo().getTotal(), equalTo(expectedTotal));
assertThat(response.getShardInfo().getSuccessful(), equalTo(expectedSuccessful));
assertThat(response.getShardInfo().getTotal(), greaterThanOrEqualTo(expectedTotal));
assertThat(response.getShardInfo().getSuccessful(), greaterThanOrEqualTo(expectedSuccessful));
assertThat(response.getShardInfo().getPending(), equalTo(expectedPending));
}