Add assertion that index creation & deletion is acknowledged

This commit is contained in:
Simon Willnauer 2013-08-16 10:57:17 +02:00
parent f0914d13af
commit 459d59a04a
2 changed files with 25 additions and 5 deletions

View File

@ -24,6 +24,10 @@ import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.ActionFuture;
import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
import org.elasticsearch.action.count.CountResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.ShardSearchFailure;
@ -45,6 +49,23 @@ import static org.junit.Assert.fail;
*/
public class ElasticsearchAssertions {
public static void assertAcked(DeleteIndexRequestBuilder builder) {
assertAcked(builder.get());
}
public static void assertAcked(CreateIndexRequestBuilder builder) {
assertAcked(builder.get());
}
public static void assertAcked(DeleteIndexResponse response) {
assertThat("Delete Index failed - not acked", response.isAcknowledged(), equalTo(true));
}
public static void assertAcked(CreateIndexResponse response) {
assertThat("Create Index failed - not acked", response.isAcknowledged(), equalTo(true));
}
/*
* assertions
*/

View File

@ -26,7 +26,6 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
import org.elasticsearch.action.admin.indices.flush.FlushResponse;
import org.elasticsearch.action.admin.indices.optimize.OptimizeResponse;
@ -59,6 +58,7 @@ import java.util.*;
import java.util.concurrent.ExecutionException;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.hamcrest.Matchers.equalTo;
@ -147,8 +147,7 @@ public abstract class AbstractSharedClusterTest extends ElasticsearchTestCase {
public static void wipeIndices(String... names) {
try {
final DeleteIndexResponse actionGet = client().admin().indices().prepareDelete(names).execute().actionGet();
assertThat("Delete Index failed - not acked", actionGet.isAcknowledged(), equalTo(true));
assertAcked(client().admin().indices().prepareDelete(names));
} catch (IndexMissingException e) {
// ignore
}
@ -178,12 +177,12 @@ public abstract class AbstractSharedClusterTest extends ElasticsearchTestCase {
public void createIndex(String... names) {
for (String name : names) {
try {
prepareCreate(name).setSettings(getSettings()).execute().actionGet();
assertAcked(prepareCreate(name).setSettings(getSettings()));
continue;
} catch (IndexAlreadyExistsException ex) {
wipeIndex(name);
}
prepareCreate(name).setSettings(getSettings()).execute().actionGet();
assertAcked(prepareCreate(name).setSettings(getSettings()));
}
}