Check if Alias Creation was acknoledge in tests.

if there is a failure during alias creation the tests don't fail with the
correct exception. This commit simplifies the debugging asserting on the ack
flag.
This commit is contained in:
Simon Willnauer 2013-06-13 15:52:33 +02:00
parent a654c3d103
commit 4e4529f3dc
1 changed files with 32 additions and 56 deletions

View File

@ -19,10 +19,11 @@
package org.elasticsearch.test.integration.routing; package org.elasticsearch.test.integration.routing;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.ElasticSearchException; import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.RoutingMissingException; import org.elasticsearch.action.RoutingMissingException;
import org.elasticsearch.client.Requests; import org.elasticsearch.client.Requests;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.test.integration.AbstractSharedClusterTest; import org.elasticsearch.test.integration.AbstractSharedClusterTest;
@ -43,9 +44,9 @@ public class AliasRoutingTests extends AbstractSharedClusterTest {
@Test @Test
public void testAliasCrudRouting() throws Exception { public void testAliasCrudRouting() throws Exception {
createIndex("test"); createIndex("test");
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); ensureGreen();
IndicesAliasesResponse res = run(admin().indices().prepareAliases().addAliasAction(newAddAliasAction("test", "alias0").routing("0")));
client().admin().indices().prepareAliases().addAliasAction(newAddAliasAction("test", "alias0").routing("0")).execute().actionGet(); assertThat(res.isAcknowledged(), equalTo(true));
logger.info("--> indexing with id [1], and routing [0] using alias"); logger.info("--> indexing with id [1], and routing [0] using alias");
client().prepareIndex("alias0", "type1", "1").setSource("field", "value1").setRefresh(true).execute().actionGet(); client().prepareIndex("alias0", "type1", "1").setSource("field", "value1").setRefresh(true).execute().actionGet();
@ -124,15 +125,13 @@ public class AliasRoutingTests extends AbstractSharedClusterTest {
@Test @Test
public void testAliasSearchRouting() throws Exception { public void testAliasSearchRouting() throws Exception {
createIndex("test"); createIndex("test");
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); ensureGreen();
IndicesAliasesResponse res = run(admin().indices().prepareAliases()
client().admin().indices().prepareAliases()
.addAliasAction(newAddAliasAction("test", "alias")) .addAliasAction(newAddAliasAction("test", "alias"))
.addAliasAction(newAddAliasAction("test", "alias0").routing("0")) .addAliasAction(newAddAliasAction("test", "alias0").routing("0"))
.addAliasAction(newAddAliasAction("test", "alias1").routing("1")) .addAliasAction(newAddAliasAction("test", "alias1").routing("1"))
.addAliasAction(newAddAliasAction("test", "alias01").searchRouting("0,1")) .addAliasAction(newAddAliasAction("test", "alias01").searchRouting("0,1")));
.execute().actionGet(); assertThat(res.isAcknowledged(), equalTo(true));
logger.info("--> indexing with id [1], and routing [0] using alias"); logger.info("--> indexing with id [1], and routing [0] using alias");
client().prepareIndex("alias0", "type1", "1").setSource("field", "value1").setRefresh(true).execute().actionGet(); client().prepareIndex("alias0", "type1", "1").setSource("field", "value1").setRefresh(true).execute().actionGet();
@ -223,18 +222,16 @@ public class AliasRoutingTests extends AbstractSharedClusterTest {
public void testAliasSearchRoutingWithTwoIndices() throws Exception { public void testAliasSearchRoutingWithTwoIndices() throws Exception {
createIndex("test-a"); createIndex("test-a");
createIndex("test-b"); createIndex("test-b");
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); ensureGreen();
IndicesAliasesResponse res = run(admin().indices().prepareAliases()
client().admin().indices().prepareAliases()
.addAliasAction(newAddAliasAction("test-a", "alias-a0").routing("0")) .addAliasAction(newAddAliasAction("test-a", "alias-a0").routing("0"))
.addAliasAction(newAddAliasAction("test-a", "alias-a1").routing("1")) .addAliasAction(newAddAliasAction("test-a", "alias-a1").routing("1"))
.addAliasAction(newAddAliasAction("test-b", "alias-b0").routing("0")) .addAliasAction(newAddAliasAction("test-b", "alias-b0").routing("0"))
.addAliasAction(newAddAliasAction("test-b", "alias-b1").routing("1")) .addAliasAction(newAddAliasAction("test-b", "alias-b1").routing("1"))
.addAliasAction(newAddAliasAction("test-a", "alias-ab").searchRouting("0")) .addAliasAction(newAddAliasAction("test-a", "alias-ab").searchRouting("0"))
.addAliasAction(newAddAliasAction("test-b", "alias-ab").searchRouting("1")) .addAliasAction(newAddAliasAction("test-b", "alias-ab").searchRouting("1")));
.execute().actionGet(); assertThat(res.isAcknowledged(), equalTo(true));
ensureGreen(); // wait for events again to make sure we got the aliases on all nodes
logger.info("--> indexing with id [1], and routing [0] using alias to test-a"); logger.info("--> indexing with id [1], and routing [0] using alias to test-a");
client().prepareIndex("alias-a0", "type1", "1").setSource("field", "value1").setRefresh(true).execute().actionGet(); client().prepareIndex("alias-a0", "type1", "1").setSource("field", "value1").setRefresh(true).execute().actionGet();
logger.info("--> verifying get with no routing, should not find anything"); logger.info("--> verifying get with no routing, should not find anything");
@ -279,19 +276,11 @@ public class AliasRoutingTests extends AbstractSharedClusterTest {
@Test @Test
public void testAliasSearchRoutingWithConcreteAndAliasedIndices() throws Exception { public void testAliasSearchRoutingWithConcreteAndAliasedIndices() throws Exception {
try { createIndex("index", "index_2");
client().admin().indices().prepareDelete("index").execute().actionGet(); ensureGreen();
client().admin().indices().prepareDelete("index_2").execute().actionGet(); IndicesAliasesResponse res = run(admin().indices().prepareAliases()
} catch (Exception e) { .addAliasAction(newAddAliasAction("index", "index_1").routing("1")));
// ignore assertThat(res.isAcknowledged(), equalTo(true));
}
client().admin().indices().prepareCreate("index").execute().actionGet();
client().admin().indices().prepareCreate("index_2").execute().actionGet();
client().admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
client().admin().indices().prepareAliases()
.addAliasAction(newAddAliasAction("index", "index_1").routing("1"))
.execute().actionGet();
logger.info("--> indexing on index_1 which is an alias for index with routing [1]"); logger.info("--> indexing on index_1 which is an alias for index with routing [1]");
client().prepareIndex("index_1", "type1", "1").setSource("field", "value1").setRefresh(true).execute().actionGet(); client().prepareIndex("index_1", "type1", "1").setSource("field", "value1").setRefresh(true).execute().actionGet();
@ -307,16 +296,11 @@ public class AliasRoutingTests extends AbstractSharedClusterTest {
@Test @Test
public void testRequiredRoutingMappingWithAlias() throws Exception { public void testRequiredRoutingMappingWithAlias() throws Exception {
try { run(prepareCreate("test").addMapping(
client().admin().indices().prepareDelete("test").execute().actionGet(); "type1",
} catch (Exception e) { XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("_routing").field("required", true)
// ignore .endObject().endObject().endObject()));
} ensureGreen();
client().admin().indices().prepareCreate("test")
.addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("_routing").field("required", true).endObject().endObject().endObject())
.execute().actionGet();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
logger.info("--> indexing with id [1], and routing [0]"); logger.info("--> indexing with id [1], and routing [0]");
client().prepareIndex("test", "type1", "1").setRouting("0").setSource("field", "value1").setRefresh(true).execute().actionGet(); client().prepareIndex("test", "type1", "1").setRouting("0").setSource("field", "value1").setRefresh(true).execute().actionGet();
logger.info("--> verifying get with no routing, should not find anything"); logger.info("--> verifying get with no routing, should not find anything");
@ -356,19 +340,12 @@ public class AliasRoutingTests extends AbstractSharedClusterTest {
@Test @Test
public void testIndexingAliasesOverTime() throws Exception { public void testIndexingAliasesOverTime() throws Exception {
try { createIndex("test");
client().admin().indices().prepareDelete("test").execute().actionGet(); ensureGreen();
} catch (Exception e) {
// ignore
}
client().admin().indices().prepareCreate("test").execute().actionGet();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
logger.info("--> creating alias with routing [3]"); logger.info("--> creating alias with routing [3]");
client().admin().indices().prepareAliases() IndicesAliasesResponse res = run(admin().indices().prepareAliases()
.addAliasAction(newAddAliasAction("test", "alias").routing("3")) .addAliasAction(newAddAliasAction("test", "alias").routing("3")));
.execute().actionGet(); assertThat(res.isAcknowledged(), equalTo(true));
logger.info("--> indexing with id [0], and routing [3]"); logger.info("--> indexing with id [0], and routing [3]");
client().prepareIndex("alias", "type1", "0").setSource("field", "value1").setRefresh(true).execute().actionGet(); client().prepareIndex("alias", "type1", "0").setSource("field", "value1").setRefresh(true).execute().actionGet();
@ -382,9 +359,9 @@ public class AliasRoutingTests extends AbstractSharedClusterTest {
} }
logger.info("--> creating alias with routing [4]"); logger.info("--> creating alias with routing [4]");
client().admin().indices().prepareAliases() res = run(admin().indices().prepareAliases()
.addAliasAction(newAddAliasAction("test", "alias").routing("4")) .addAliasAction(newAddAliasAction("test", "alias").routing("4")));
.execute().actionGet(); assertThat(res.isAcknowledged(), equalTo(true));
logger.info("--> verifying search with wrong routing should not find"); logger.info("--> verifying search with wrong routing should not find");
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
@ -408,7 +385,6 @@ public class AliasRoutingTests extends AbstractSharedClusterTest {
assertThat(client().prepareSearch("alias").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l)); assertThat(client().prepareSearch("alias").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
assertThat(client().prepareCount("alias").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(2l)); assertThat(client().prepareCount("alias").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(2l));
} }
} }
} }