From 459d59a04ad4eb1671bac50a6faf3a7ad372d0e4 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Fri, 16 Aug 2013 10:57:17 +0200 Subject: [PATCH] Add assertion that index creation & deletion is acknowledged --- .../hamcrest/ElasticsearchAssertions.java | 21 +++++++++++++++++++ .../AbstractSharedClusterTest.java | 9 ++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java b/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java index f655a5e3086..f1d9155da96 100644 --- a/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java +++ b/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java @@ -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; @@ -44,6 +48,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 diff --git a/src/test/java/org/elasticsearch/test/integration/AbstractSharedClusterTest.java b/src/test/java/org/elasticsearch/test/integration/AbstractSharedClusterTest.java index 9d9518c46a8..04f279399ab 100644 --- a/src/test/java/org/elasticsearch/test/integration/AbstractSharedClusterTest.java +++ b/src/test/java/org/elasticsearch/test/integration/AbstractSharedClusterTest.java @@ -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())); } }