[TEST] Improved IndexAliasesTests

more assertAcked, removed TODO and needless sleep
This commit is contained in:
Luca Cavanna 2014-01-27 13:38:16 +01:00
parent c1c2d343c4
commit c4edf15633
1 changed files with 192 additions and 261 deletions

View File

@ -20,7 +20,6 @@
package org.elasticsearch.aliases; package org.elasticsearch.aliases;
import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.alias.exists.AliasesExistResponse; import org.elasticsearch.action.admin.indices.alias.exists.AliasesExistResponse;
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse;
import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.index.IndexResponse;
@ -51,10 +50,12 @@ import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static com.google.common.collect.Sets.newHashSet; import static com.google.common.collect.Sets.newHashSet;
import static org.elasticsearch.client.Requests.*; import static org.elasticsearch.client.Requests.createIndexRequest;
import static org.elasticsearch.client.Requests.indexRequest;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.index.query.FilterBuilders.termFilter; import static org.elasticsearch.index.query.FilterBuilders.termFilter;
import static org.elasticsearch.test.hamcrest.CollectionAssertions.hasKey; import static org.elasticsearch.test.hamcrest.CollectionAssertions.hasKey;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
/** /**
@ -64,36 +65,25 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
@Test @Test
public void testAliases() throws Exception { public void testAliases() throws Exception {
logger.info("--> creating index [test]"); logger.info("--> creating index [test]");
createIndex("test"); createIndex("test");
ensureGreen(); ensureGreen();
//
// try {
// logger.info("--> indexing against [alias1], should fail");
// client().index(indexRequest("alias1").type("type1").id("1").source(source("1", "test"))).actionGet();
// fail("index [alias1] should not exists");
// } catch (IndexMissingException e) {
// assertThat(e.index().name(), equalTo("alias1"));
// }
// TODO this is bogus and should have a dedicated test
logger.info("--> aliasing index [test] with [alias1]"); logger.info("--> aliasing index [test] with [alias1]");
admin().indices().prepareAliases().addAlias("test", "alias1").execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test", "alias1"));
logger.info("--> indexing against [alias1], should work now"); logger.info("--> indexing against [alias1], should work now");
IndexResponse indexResponse = client().index(indexRequest("alias1").type("type1").id("1").source(source("1", "test"))).actionGet(); IndexResponse indexResponse = client().index(indexRequest("alias1").type("type1").id("1").source(source("1", "test"))).actionGet();
assertThat(indexResponse.getIndex(), equalTo("test")); assertThat(indexResponse.getIndex(), equalTo("test"));
logger.info("--> creating index [test]"); logger.info("--> creating index [test_x]");
admin().indices().create(createIndexRequest("test_x")).actionGet(); createIndex("test_x");
ensureGreen(); ensureGreen();
logger.info("--> remove [alias1], Aliasing index [test_x] with [alias1]"); logger.info("--> remove [alias1], Aliasing index [test_x] with [alias1]");
admin().indices().aliases(indexAliasesRequest().removeAlias("test", "alias1").addAlias("alias1", "test_x")).actionGet(); assertAcked(admin().indices().prepareAliases().removeAlias("test", "alias1").addAlias("test_x", "alias1"));
Thread.sleep(300);
logger.info("--> indexing against [alias1], should work against [test_x]"); logger.info("--> indexing against [alias1], should work against [test_x]");
indexResponse = client().index(indexRequest("alias1").type("type1").id("1").source(source("1", "test"))).actionGet(); indexResponse = client().index(indexRequest("alias1").type("type1").id("1").source(source("1", "test"))).actionGet();
@ -102,7 +92,6 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
@Test @Test
public void testFailedFilter() throws Exception { public void testFailedFilter() throws Exception {
logger.info("--> creating index [test]"); logger.info("--> creating index [test]");
createIndex("test"); createIndex("test");
@ -110,7 +99,7 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
try { try {
logger.info("--> aliasing index [test] with [alias1] and filter [t]"); logger.info("--> aliasing index [test] with [alias1] and filter [t]");
admin().indices().prepareAliases().addAlias("test", "alias1", "{ t }").execute().actionGet(); admin().indices().prepareAliases().addAlias("test", "alias1", "{ t }").get();
fail(); fail();
} catch (Exception e) { } catch (Exception e) {
// all is well // all is well
@ -119,7 +108,6 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
@Test @Test
public void testFilteringAliases() throws Exception { public void testFilteringAliases() throws Exception {
logger.info("--> creating index [test]"); logger.info("--> creating index [test]");
createIndex("test"); createIndex("test");
@ -127,11 +115,11 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
logger.info("--> aliasing index [test] with [alias1] and filter [user:kimchy]"); logger.info("--> aliasing index [test] with [alias1] and filter [user:kimchy]");
FilterBuilder filter = termFilter("user", "kimchy"); FilterBuilder filter = termFilter("user", "kimchy");
admin().indices().prepareAliases().addAlias("test", "alias1", filter).execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test", "alias1", filter));
// For now just making sure that filter was stored with the alias // For now just making sure that filter was stored with the alias
logger.info("--> making sure that filter was stored with alias [alias1] and filter [user:kimchy]"); logger.info("--> making sure that filter was stored with alias [alias1] and filter [user:kimchy]");
ClusterState clusterState = admin().cluster().prepareState().execute().actionGet().getState(); ClusterState clusterState = admin().cluster().prepareState().get().getState();
IndexMetaData indexMd = clusterState.metaData().index("test"); IndexMetaData indexMd = clusterState.metaData().index("test");
assertThat(indexMd.aliases().get("alias1").filter().string(), equalTo("{\"term\":{\"user\":\"kimchy\"}}")); assertThat(indexMd.aliases().get("alias1").filter().string(), equalTo("{\"term\":{\"user\":\"kimchy\"}}"));
@ -144,25 +132,22 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
ensureGreen(); ensureGreen();
logger.info("--> aliasing index [test] with [alias1] and empty filter"); logger.info("--> aliasing index [test] with [alias1] and empty filter");
IndicesAliasesResponse indicesAliasesResponse = admin().indices().prepareAliases().addAlias("test", "alias1", "{}").get(); assertAcked(admin().indices().prepareAliases().addAlias("test", "alias1", "{}"));
//just checking that the empty doesn't lead to issues
assertThat(indicesAliasesResponse.isAcknowledged(), equalTo(true));
} }
@Test @Test
public void testSearchingFilteringAliasesSingleIndex() throws Exception { public void testSearchingFilteringAliasesSingleIndex() throws Exception {
logger.info("--> creating index [test]"); logger.info("--> creating index [test]");
createIndex("test"); createIndex("test");
ensureGreen(); ensureGreen();
logger.info("--> adding filtering aliases to index [test]"); logger.info("--> adding filtering aliases to index [test]");
admin().indices().prepareAliases().addAlias("test", "alias1").execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test", "alias1"));
admin().indices().prepareAliases().addAlias("test", "alias2").execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test", "alias2"));
admin().indices().prepareAliases().addAlias("test", "foos", termFilter("name", "foo")).execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test", "foos", termFilter("name", "foo")));
admin().indices().prepareAliases().addAlias("test", "bars", termFilter("name", "bar")).execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test", "bars", termFilter("name", "bar")));
admin().indices().prepareAliases().addAlias("test", "tests", termFilter("name", "test")).execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test", "tests", termFilter("name", "test")));
logger.info("--> indexing against [test]"); logger.info("--> indexing against [test]");
client().index(indexRequest("test").type("type1").id("1").source(source("1", "foo test")).refresh(true)).actionGet(); client().index(indexRequest("test").type("type1").id("1").source(source("1", "foo test")).refresh(true)).actionGet();
@ -171,246 +156,240 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
client().index(indexRequest("test").type("type1").id("4").source(source("4", "something else")).refresh(true)).actionGet(); client().index(indexRequest("test").type("type1").id("4").source(source("4", "something else")).refresh(true)).actionGet();
logger.info("--> checking single filtering alias search"); logger.info("--> checking single filtering alias search");
SearchResponse searchResponse = client().prepareSearch("foos").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); SearchResponse searchResponse = client().prepareSearch("foos").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "1"); assertHits(searchResponse.getHits(), "1");
logger.info("--> checking single filtering alias wildcard search"); logger.info("--> checking single filtering alias wildcard search");
searchResponse = client().prepareSearch("fo*").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); searchResponse = client().prepareSearch("fo*").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "1"); assertHits(searchResponse.getHits(), "1");
searchResponse = client().prepareSearch("tests").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); searchResponse = client().prepareSearch("tests").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "1", "2", "3"); assertHits(searchResponse.getHits(), "1", "2", "3");
logger.info("--> checking single filtering alias search with sort"); logger.info("--> checking single filtering alias search with sort");
searchResponse = client().prepareSearch("tests").setQuery(QueryBuilders.matchAllQuery()).addSort("_uid", SortOrder.ASC).execute().actionGet(); searchResponse = client().prepareSearch("tests").setQuery(QueryBuilders.matchAllQuery()).addSort("_uid", SortOrder.ASC).get();
assertHits(searchResponse.getHits(), "1", "2", "3"); assertHits(searchResponse.getHits(), "1", "2", "3");
logger.info("--> checking single filtering alias search with global facets"); logger.info("--> checking single filtering alias search with global facets");
searchResponse = client().prepareSearch("tests").setQuery(QueryBuilders.matchQuery("name", "bar")) searchResponse = client().prepareSearch("tests").setQuery(QueryBuilders.matchQuery("name", "bar"))
.addFacet(FacetBuilders.termsFacet("test").field("name").global(true)) .addFacet(FacetBuilders.termsFacet("test").field("name").global(true))
.execute().actionGet(); .get();
assertThat(((TermsFacet) searchResponse.getFacets().facet("test")).getEntries().size(), equalTo(4)); assertThat(((TermsFacet) searchResponse.getFacets().facet("test")).getEntries().size(), equalTo(4));
logger.info("--> checking single filtering alias search with global facets and sort"); logger.info("--> checking single filtering alias search with global facets and sort");
searchResponse = client().prepareSearch("tests").setQuery(QueryBuilders.matchQuery("name", "bar")) searchResponse = client().prepareSearch("tests").setQuery(QueryBuilders.matchQuery("name", "bar"))
.addFacet(FacetBuilders.termsFacet("test").field("name").global(true)) .addFacet(FacetBuilders.termsFacet("test").field("name").global(true))
.addSort("_uid", SortOrder.ASC).execute().actionGet(); .addSort("_uid", SortOrder.ASC).get();
assertThat(((TermsFacet) searchResponse.getFacets().facet("test")).getEntries().size(), equalTo(4)); assertThat(((TermsFacet) searchResponse.getFacets().facet("test")).getEntries().size(), equalTo(4));
logger.info("--> checking single filtering alias search with non-global facets"); logger.info("--> checking single filtering alias search with non-global facets");
searchResponse = client().prepareSearch("tests").setQuery(QueryBuilders.matchQuery("name", "bar")) searchResponse = client().prepareSearch("tests").setQuery(QueryBuilders.matchQuery("name", "bar"))
.addFacet(FacetBuilders.termsFacet("test").field("name").global(false)) .addFacet(FacetBuilders.termsFacet("test").field("name").global(false))
.addSort("_uid", SortOrder.ASC).execute().actionGet(); .addSort("_uid", SortOrder.ASC).get();
assertThat(((TermsFacet) searchResponse.getFacets().facet("test")).getEntries().size(), equalTo(2)); assertThat(((TermsFacet) searchResponse.getFacets().facet("test")).getEntries().size(), equalTo(2));
searchResponse = client().prepareSearch("foos", "bars").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); searchResponse = client().prepareSearch("foos", "bars").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "1", "2"); assertHits(searchResponse.getHits(), "1", "2");
logger.info("--> checking single non-filtering alias search"); logger.info("--> checking single non-filtering alias search");
searchResponse = client().prepareSearch("alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); searchResponse = client().prepareSearch("alias1").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "1", "2", "3", "4"); assertHits(searchResponse.getHits(), "1", "2", "3", "4");
logger.info("--> checking non-filtering alias and filtering alias search"); logger.info("--> checking non-filtering alias and filtering alias search");
searchResponse = client().prepareSearch("alias1", "foos").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); searchResponse = client().prepareSearch("alias1", "foos").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "1", "2", "3", "4"); assertHits(searchResponse.getHits(), "1", "2", "3", "4");
logger.info("--> checking index and filtering alias search"); logger.info("--> checking index and filtering alias search");
searchResponse = client().prepareSearch("test", "foos").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); searchResponse = client().prepareSearch("test", "foos").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "1", "2", "3", "4"); assertHits(searchResponse.getHits(), "1", "2", "3", "4");
logger.info("--> checking index and alias wildcard search"); logger.info("--> checking index and alias wildcard search");
searchResponse = client().prepareSearch("te*", "fo*").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); searchResponse = client().prepareSearch("te*", "fo*").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "1", "2", "3", "4"); assertHits(searchResponse.getHits(), "1", "2", "3", "4");
} }
@Test @Test
public void testSearchingFilteringAliasesTwoIndices() throws Exception { public void testSearchingFilteringAliasesTwoIndices() throws Exception {
logger.info("--> creating index [test1]"); logger.info("--> creating index [test1]");
admin().indices().create(createIndexRequest("test1")).actionGet(); createIndex("test1");
logger.info("--> creating index [test2]"); logger.info("--> creating index [test2]");
admin().indices().create(createIndexRequest("test2")).actionGet(); createIndex("test2");
ensureGreen(); ensureGreen();
logger.info("--> adding filtering aliases to index [test1]"); logger.info("--> adding filtering aliases to index [test1]");
admin().indices().prepareAliases().addAlias("test1", "aliasToTest1").execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test1", "aliasToTest1"));
admin().indices().prepareAliases().addAlias("test1", "aliasToTests").execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test1", "aliasToTests"));
admin().indices().prepareAliases().addAlias("test1", "foos", termFilter("name", "foo")).execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test1", "foos", termFilter("name", "foo")));
admin().indices().prepareAliases().addAlias("test1", "bars", termFilter("name", "bar")).execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test1", "bars", termFilter("name", "bar")));
logger.info("--> adding filtering aliases to index [test2]"); logger.info("--> adding filtering aliases to index [test2]");
admin().indices().prepareAliases().addAlias("test2", "aliasToTest2").execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test2", "aliasToTest2"));
admin().indices().prepareAliases().addAlias("test2", "aliasToTests").execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test2", "aliasToTests"));
admin().indices().prepareAliases().addAlias("test2", "foos", termFilter("name", "foo")).execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test2", "foos", termFilter("name", "foo")));
logger.info("--> indexing against [test1]"); logger.info("--> indexing against [test1]");
client().index(indexRequest("test1").type("type1").id("1").source(source("1", "foo test")).refresh(true)).actionGet(); client().index(indexRequest("test1").type("type1").id("1").source(source("1", "foo test"))).get();
client().index(indexRequest("test1").type("type1").id("2").source(source("2", "bar test")).refresh(true)).actionGet(); client().index(indexRequest("test1").type("type1").id("2").source(source("2", "bar test"))).get();
client().index(indexRequest("test1").type("type1").id("3").source(source("3", "baz test")).refresh(true)).actionGet(); client().index(indexRequest("test1").type("type1").id("3").source(source("3", "baz test"))).get();
client().index(indexRequest("test1").type("type1").id("4").source(source("4", "something else")).refresh(true)).actionGet(); client().index(indexRequest("test1").type("type1").id("4").source(source("4", "something else"))).get();
logger.info("--> indexing against [test2]"); logger.info("--> indexing against [test2]");
client().index(indexRequest("test2").type("type1").id("5").source(source("5", "foo test")).refresh(true)).actionGet(); client().index(indexRequest("test2").type("type1").id("5").source(source("5", "foo test"))).get();
client().index(indexRequest("test2").type("type1").id("6").source(source("6", "bar test")).refresh(true)).actionGet(); client().index(indexRequest("test2").type("type1").id("6").source(source("6", "bar test"))).get();
client().index(indexRequest("test2").type("type1").id("7").source(source("7", "baz test")).refresh(true)).actionGet(); client().index(indexRequest("test2").type("type1").id("7").source(source("7", "baz test"))).get();
client().index(indexRequest("test2").type("type1").id("8").source(source("8", "something else")).refresh(true)).actionGet(); client().index(indexRequest("test2").type("type1").id("8").source(source("8", "something else"))).get();
refresh();
logger.info("--> checking filtering alias for two indices"); logger.info("--> checking filtering alias for two indices");
SearchResponse searchResponse = client().prepareSearch("foos").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); SearchResponse searchResponse = client().prepareSearch("foos").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "1", "5"); assertHits(searchResponse.getHits(), "1", "5");
assertThat(client().prepareCount("foos").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(2L)); assertThat(client().prepareCount("foos").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(2L));
logger.info("--> checking filtering alias for one index"); logger.info("--> checking filtering alias for one index");
searchResponse = client().prepareSearch("bars").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); searchResponse = client().prepareSearch("bars").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "2"); assertHits(searchResponse.getHits(), "2");
assertThat(client().prepareCount("bars").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(1L)); assertThat(client().prepareCount("bars").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(1L));
logger.info("--> checking filtering alias for two indices and one complete index"); logger.info("--> checking filtering alias for two indices and one complete index");
searchResponse = client().prepareSearch("foos", "test1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); searchResponse = client().prepareSearch("foos", "test1").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "1", "2", "3", "4", "5"); assertHits(searchResponse.getHits(), "1", "2", "3", "4", "5");
assertThat(client().prepareCount("foos", "test1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(5L)); assertThat(client().prepareCount("foos", "test1").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(5L));
logger.info("--> checking filtering alias for two indices and non-filtering alias for one index"); logger.info("--> checking filtering alias for two indices and non-filtering alias for one index");
searchResponse = client().prepareSearch("foos", "aliasToTest1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); searchResponse = client().prepareSearch("foos", "aliasToTest1").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "1", "2", "3", "4", "5"); assertHits(searchResponse.getHits(), "1", "2", "3", "4", "5");
assertThat(client().prepareCount("foos", "aliasToTest1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(5L)); assertThat(client().prepareCount("foos", "aliasToTest1").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(5L));
logger.info("--> checking filtering alias for two indices and non-filtering alias for both indices"); logger.info("--> checking filtering alias for two indices and non-filtering alias for both indices");
searchResponse = client().prepareSearch("foos", "aliasToTests").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); searchResponse = client().prepareSearch("foos", "aliasToTests").setQuery(QueryBuilders.matchAllQuery()).get();
assertThat(searchResponse.getHits().totalHits(), equalTo(8L)); assertThat(searchResponse.getHits().totalHits(), equalTo(8L));
assertThat(client().prepareCount("foos", "aliasToTests").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(8L)); assertThat(client().prepareCount("foos", "aliasToTests").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(8L));
logger.info("--> checking filtering alias for two indices and non-filtering alias for both indices"); logger.info("--> checking filtering alias for two indices and non-filtering alias for both indices");
searchResponse = client().prepareSearch("foos", "aliasToTests").setQuery(QueryBuilders.termQuery("name", "something")).execute().actionGet(); searchResponse = client().prepareSearch("foos", "aliasToTests").setQuery(QueryBuilders.termQuery("name", "something")).get();
assertHits(searchResponse.getHits(), "4", "8"); assertHits(searchResponse.getHits(), "4", "8");
assertThat(client().prepareCount("foos", "aliasToTests").setQuery(QueryBuilders.termQuery("name", "something")).execute().actionGet().getCount(), equalTo(2L)); assertThat(client().prepareCount("foos", "aliasToTests").setQuery(QueryBuilders.termQuery("name", "something")).get().getCount(), equalTo(2L));
} }
@Test @Test
public void testSearchingFilteringAliasesMultipleIndices() throws Exception { public void testSearchingFilteringAliasesMultipleIndices() throws Exception {
logger.info("--> creating indices"); logger.info("--> creating indices");
admin().indices().create(createIndexRequest("test1")).actionGet(); createIndex("test1", "test2", "test3");
admin().indices().create(createIndexRequest("test2")).actionGet();
admin().indices().create(createIndexRequest("test3")).actionGet();
ensureGreen(); ensureGreen();
logger.info("--> adding aliases to indices"); logger.info("--> adding aliases to indices");
admin().indices().prepareAliases().addAlias("test1", "alias12").execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test1", "alias12"));
admin().indices().prepareAliases().addAlias("test2", "alias12").execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test2", "alias12"));
logger.info("--> adding filtering aliases to indices"); logger.info("--> adding filtering aliases to indices");
admin().indices().prepareAliases().addAlias("test1", "filter1", termFilter("name", "test1")).execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test1", "filter1", termFilter("name", "test1")));
admin().indices().prepareAliases().addAlias("test2", "filter23", termFilter("name", "foo")).execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test2", "filter23", termFilter("name", "foo")));
admin().indices().prepareAliases().addAlias("test3", "filter23", termFilter("name", "foo")).execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test3", "filter23", termFilter("name", "foo")));
admin().indices().prepareAliases().addAlias("test1", "filter13", termFilter("name", "baz")).execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test1", "filter13", termFilter("name", "baz")));
admin().indices().prepareAliases().addAlias("test3", "filter13", termFilter("name", "baz")).execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test3", "filter13", termFilter("name", "baz")));
logger.info("--> indexing against [test1]"); logger.info("--> indexing against [test1]");
client().index(indexRequest("test1").type("type1").id("11").source(source("11", "foo test1")).refresh(true)).actionGet(); client().index(indexRequest("test1").type("type1").id("11").source(source("11", "foo test1"))).get();
client().index(indexRequest("test1").type("type1").id("12").source(source("12", "bar test1")).refresh(true)).actionGet(); client().index(indexRequest("test1").type("type1").id("12").source(source("12", "bar test1"))).get();
client().index(indexRequest("test1").type("type1").id("13").source(source("13", "baz test1")).refresh(true)).actionGet(); client().index(indexRequest("test1").type("type1").id("13").source(source("13", "baz test1"))).get();
client().index(indexRequest("test2").type("type1").id("21").source(source("21", "foo test2")).refresh(true)).actionGet(); client().index(indexRequest("test2").type("type1").id("21").source(source("21", "foo test2"))).get();
client().index(indexRequest("test2").type("type1").id("22").source(source("22", "bar test2")).refresh(true)).actionGet(); client().index(indexRequest("test2").type("type1").id("22").source(source("22", "bar test2"))).get();
client().index(indexRequest("test2").type("type1").id("23").source(source("23", "baz test2")).refresh(true)).actionGet(); client().index(indexRequest("test2").type("type1").id("23").source(source("23", "baz test2"))).get();
client().index(indexRequest("test3").type("type1").id("31").source(source("31", "foo test3")).refresh(true)).actionGet(); client().index(indexRequest("test3").type("type1").id("31").source(source("31", "foo test3"))).get();
client().index(indexRequest("test3").type("type1").id("32").source(source("32", "bar test3")).refresh(true)).actionGet(); client().index(indexRequest("test3").type("type1").id("32").source(source("32", "bar test3"))).get();
client().index(indexRequest("test3").type("type1").id("33").source(source("33", "baz test3")).refresh(true)).actionGet(); client().index(indexRequest("test3").type("type1").id("33").source(source("33", "baz test3"))).get();
refresh();
logger.info("--> checking filtering alias for multiple indices"); logger.info("--> checking filtering alias for multiple indices");
SearchResponse searchResponse = client().prepareSearch("filter23", "filter13").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); SearchResponse searchResponse = client().prepareSearch("filter23", "filter13").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "21", "31", "13", "33"); assertHits(searchResponse.getHits(), "21", "31", "13", "33");
assertThat(client().prepareCount("filter23", "filter13").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(4L)); assertThat(client().prepareCount("filter23", "filter13").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(4L));
searchResponse = client().prepareSearch("filter23", "filter1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); searchResponse = client().prepareSearch("filter23", "filter1").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "21", "31", "11", "12", "13"); assertHits(searchResponse.getHits(), "21", "31", "11", "12", "13");
assertThat(client().prepareCount("filter23", "filter1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(5L)); assertThat(client().prepareCount("filter23", "filter1").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(5L));
searchResponse = client().prepareSearch("filter13", "filter1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); searchResponse = client().prepareSearch("filter13", "filter1").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "11", "12", "13", "33"); assertHits(searchResponse.getHits(), "11", "12", "13", "33");
assertThat(client().prepareCount("filter13", "filter1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(4L)); assertThat(client().prepareCount("filter13", "filter1").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(4L));
searchResponse = client().prepareSearch("filter13", "filter1", "filter23").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); searchResponse = client().prepareSearch("filter13", "filter1", "filter23").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "11", "12", "13", "21", "31", "33"); assertHits(searchResponse.getHits(), "11", "12", "13", "21", "31", "33");
assertThat(client().prepareCount("filter13", "filter1", "filter23").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(6L)); assertThat(client().prepareCount("filter13", "filter1", "filter23").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(6L));
searchResponse = client().prepareSearch("filter23", "filter13", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); searchResponse = client().prepareSearch("filter23", "filter13", "test2").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "21", "22", "23", "31", "13", "33"); assertHits(searchResponse.getHits(), "21", "22", "23", "31", "13", "33");
assertThat(client().prepareCount("filter23", "filter13", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(6L)); assertThat(client().prepareCount("filter23", "filter13", "test2").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(6L));
searchResponse = client().prepareSearch("filter23", "filter13", "test1", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); searchResponse = client().prepareSearch("filter23", "filter13", "test1", "test2").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "11", "12", "13", "21", "22", "23", "31", "33"); assertHits(searchResponse.getHits(), "11", "12", "13", "21", "22", "23", "31", "33");
assertThat(client().prepareCount("filter23", "filter13", "test1", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(8L)); assertThat(client().prepareCount("filter23", "filter13", "test1", "test2").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(8L));
} }
@Test @Test
public void testDeletingByQueryFilteringAliases() throws Exception { public void testDeletingByQueryFilteringAliases() throws Exception {
logger.info("--> creating index [test1] and [test2");
logger.info("--> creating index [test1]"); createIndex("test1", "test2");
admin().indices().create(createIndexRequest("test1")).actionGet();
logger.info("--> creating index [test2]");
admin().indices().create(createIndexRequest("test2")).actionGet();
ensureGreen(); ensureGreen();
logger.info("--> adding filtering aliases to index [test1]"); logger.info("--> adding filtering aliases to index [test1]");
admin().indices().prepareAliases().addAlias("test1", "aliasToTest1").execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test1", "aliasToTest1"));
admin().indices().prepareAliases().addAlias("test1", "aliasToTests").execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test1", "aliasToTests"));
admin().indices().prepareAliases().addAlias("test1", "foos", termFilter("name", "foo")).execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test1", "foos", termFilter("name", "foo")));
admin().indices().prepareAliases().addAlias("test1", "bars", termFilter("name", "bar")).execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test1", "bars", termFilter("name", "bar")));
admin().indices().prepareAliases().addAlias("test1", "tests", termFilter("name", "test")).execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test1", "tests", termFilter("name", "test")));
logger.info("--> adding filtering aliases to index [test2]"); logger.info("--> adding filtering aliases to index [test2]");
admin().indices().prepareAliases().addAlias("test2", "aliasToTest2").execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test2", "aliasToTest2"));
admin().indices().prepareAliases().addAlias("test2", "aliasToTests").execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test2", "aliasToTests"));
admin().indices().prepareAliases().addAlias("test2", "foos", termFilter("name", "foo")).execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test2", "foos", termFilter("name", "foo")));
admin().indices().prepareAliases().addAlias("test2", "tests", termFilter("name", "test")).execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test2", "tests", termFilter("name", "test")));
logger.info("--> indexing against [test1]"); logger.info("--> indexing against [test1]");
client().index(indexRequest("test1").type("type1").id("1").source(source("1", "foo test")).refresh(true)).actionGet(); client().index(indexRequest("test1").type("type1").id("1").source(source("1", "foo test"))).get();
client().index(indexRequest("test1").type("type1").id("2").source(source("2", "bar test")).refresh(true)).actionGet(); client().index(indexRequest("test1").type("type1").id("2").source(source("2", "bar test"))).get();
client().index(indexRequest("test1").type("type1").id("3").source(source("3", "baz test")).refresh(true)).actionGet(); client().index(indexRequest("test1").type("type1").id("3").source(source("3", "baz test"))).get();
client().index(indexRequest("test1").type("type1").id("4").source(source("4", "something else")).refresh(true)).actionGet(); client().index(indexRequest("test1").type("type1").id("4").source(source("4", "something else"))).get();
logger.info("--> indexing against [test2]"); logger.info("--> indexing against [test2]");
client().index(indexRequest("test2").type("type1").id("5").source(source("5", "foo test")).refresh(true)).actionGet(); client().index(indexRequest("test2").type("type1").id("5").source(source("5", "foo test"))).get();
client().index(indexRequest("test2").type("type1").id("6").source(source("6", "bar test")).refresh(true)).actionGet(); client().index(indexRequest("test2").type("type1").id("6").source(source("6", "bar test"))).get();
client().index(indexRequest("test2").type("type1").id("7").source(source("7", "baz test")).refresh(true)).actionGet(); client().index(indexRequest("test2").type("type1").id("7").source(source("7", "baz test"))).get();
client().index(indexRequest("test2").type("type1").id("8").source(source("8", "something else")).refresh(true)).actionGet(); client().index(indexRequest("test2").type("type1").id("8").source(source("8", "something else"))).get();
refresh();
logger.info("--> checking counts before delete"); logger.info("--> checking counts before delete");
assertThat(client().prepareCount("bars").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(1L)); assertThat(client().prepareCount("bars").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(1L));
logger.info("--> delete by query from a single alias"); logger.info("--> delete by query from a single alias");
client().prepareDeleteByQuery("bars").setQuery(QueryBuilders.termQuery("name", "test")).execute().actionGet(); client().prepareDeleteByQuery("bars").setQuery(QueryBuilders.termQuery("name", "test")).get();
admin().indices().prepareRefresh().execute().actionGet();
logger.info("--> verify that only one record was deleted"); logger.info("--> verify that only one record was deleted");
assertThat(client().prepareCount("test1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(3L)); assertThat(client().prepareCount("test1").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(3L));
logger.info("--> delete by query from an aliases pointing to two indices"); logger.info("--> delete by query from an aliases pointing to two indices");
client().prepareDeleteByQuery("foos").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); client().prepareDeleteByQuery("foos").setQuery(QueryBuilders.matchAllQuery()).get();
admin().indices().prepareRefresh().execute().actionGet();
logger.info("--> verify that proper records were deleted"); logger.info("--> verify that proper records were deleted");
SearchResponse searchResponse = client().prepareSearch("aliasToTests").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); SearchResponse searchResponse = client().prepareSearch("aliasToTests").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "3", "4", "6", "7", "8"); assertHits(searchResponse.getHits(), "3", "4", "6", "7", "8");
logger.info("--> delete by query from an aliases and an index"); logger.info("--> delete by query from an aliases and an index");
client().prepareDeleteByQuery("tests", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); client().prepareDeleteByQuery("tests", "test2").setQuery(QueryBuilders.matchAllQuery()).get();
admin().indices().prepareRefresh().execute().actionGet();
logger.info("--> verify that proper records were deleted"); logger.info("--> verify that proper records were deleted");
searchResponse = client().prepareSearch("aliasToTests").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); searchResponse = client().prepareSearch("aliasToTests").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "4"); assertHits(searchResponse.getHits(), "4");
} }
@ -418,65 +397,57 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
@Test @Test
public void testDeleteAliases() throws Exception { public void testDeleteAliases() throws Exception {
logger.info("--> creating index [test1] and [test2]");
logger.info("--> creating index [test1]"); createIndex("test1", "test2");
admin().indices().create(createIndexRequest("test1")).actionGet();
logger.info("--> creating index [test2]");
admin().indices().create(createIndexRequest("test2")).actionGet();
ensureGreen(); ensureGreen();
logger.info("--> adding filtering aliases to index [test1]"); logger.info("--> adding filtering aliases to index [test1]");
admin().indices().prepareAliases().addAlias("test1", "aliasToTest1").execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test1", "aliasToTest1")
admin().indices().prepareAliases().addAlias("test1", "aliasToTests").execute().actionGet(); .addAlias("test1", "aliasToTests")
admin().indices().prepareAliases().addAlias("test1", "foos", termFilter("name", "foo")).execute().actionGet(); .addAlias("test1", "foos", termFilter("name", "foo"))
admin().indices().prepareAliases().addAlias("test1", "bars", termFilter("name", "bar")).execute().actionGet(); .addAlias("test1", "bars", termFilter("name", "bar"))
admin().indices().prepareAliases().addAlias("test1", "tests", termFilter("name", "test")).execute().actionGet(); .addAlias("test1", "tests", termFilter("name", "test")));
logger.info("--> adding filtering aliases to index [test2]"); logger.info("--> adding filtering aliases to index [test2]");
admin().indices().prepareAliases().addAlias("test2", "aliasToTest2").execute().actionGet(); assertAcked(admin().indices().prepareAliases().addAlias("test2", "aliasToTest2")
admin().indices().prepareAliases().addAlias("test2", "aliasToTests").execute().actionGet(); .addAlias("test2", "aliasToTests")
admin().indices().prepareAliases().addAlias("test2", "foos", termFilter("name", "foo")).execute().actionGet(); .addAlias("test2", "foos", termFilter("name", "foo"))
admin().indices().prepareAliases().addAlias("test2", "tests", termFilter("name", "test")).execute().actionGet(); .addAlias("test2", "tests", termFilter("name", "test")));
String[] indices = {"test1", "test2"}; String[] indices = {"test1", "test2"};
String[] aliases = {"aliasToTest1", "foos", "bars", "tests", "aliasToTest2", "aliasToTests"}; String[] aliases = {"aliasToTest1", "foos", "bars", "tests", "aliasToTest2", "aliasToTests"};
admin().indices().prepareAliases().removeAlias(indices, aliases).execute().actionGet(); admin().indices().prepareAliases().removeAlias(indices, aliases).get();
AliasesExistResponse response = admin().indices().prepareAliasesExist(aliases).execute().actionGet(); AliasesExistResponse response = admin().indices().prepareAliasesExist(aliases).get();
assertThat(response.exists(), equalTo(false)); assertThat(response.exists(), equalTo(false));
} }
@Test @Test
public void testWaitForAliasCreationMultipleShards() throws Exception { public void testWaitForAliasCreationMultipleShards() throws Exception {
logger.info("--> creating index [test]"); logger.info("--> creating index [test]");
createIndex("test"); createIndex("test");
ensureGreen(); ensureGreen();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
assertThat(admin().indices().prepareAliases().addAlias("test", "alias" + i).execute().actionGet().isAcknowledged(), equalTo(true)); assertAcked(admin().indices().prepareAliases().addAlias("test", "alias" + i));
client().index(indexRequest("alias" + i).type("type1").id("1").source(source("1", "test")).refresh(true)).actionGet(); client().index(indexRequest("alias" + i).type("type1").id("1").source(source("1", "test"))).get();
} }
} }
@Test @Test
public void testWaitForAliasCreationSingleShard() throws Exception { public void testWaitForAliasCreationSingleShard() throws Exception {
logger.info("--> creating index [test]"); logger.info("--> creating index [test]");
admin().indices().create(createIndexRequest("test").settings(settingsBuilder().put("index.numberOfReplicas", 0).put("index.numberOfShards", 1))).actionGet(); assertAcked(admin().indices().create(createIndexRequest("test").settings(settingsBuilder().put("index.numberOfReplicas", 0).put("index.numberOfShards", 1))).get());
ensureGreen(); ensureGreen();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
assertThat(admin().indices().prepareAliases().addAlias("test", "alias" + i).execute().actionGet().isAcknowledged(), equalTo(true)); assertAcked(admin().indices().prepareAliases().addAlias("test", "alias" + i));
client().index(indexRequest("alias" + i).type("type1").id("1").source(source("1", "test")).refresh(true)).actionGet(); client().index(indexRequest("alias" + i).type("type1").id("1").source(source("1", "test"))).get();
} }
} }
@ -484,7 +455,6 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
public void testWaitForAliasSimultaneousUpdate() throws Exception { public void testWaitForAliasSimultaneousUpdate() throws Exception {
final int aliasCount = 10; final int aliasCount = 10;
logger.info("--> creating index [test]"); logger.info("--> creating index [test]");
createIndex("test"); createIndex("test");
@ -496,8 +466,8 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
executor.submit(new Runnable() { executor.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
assertThat(admin().indices().prepareAliases().addAlias("test", aliasName).execute().actionGet().isAcknowledged(), equalTo(true)); assertAcked(admin().indices().prepareAliases().addAlias("test", aliasName));
client().index(indexRequest(aliasName).type("type1").id("1").source(source("1", "test")).refresh(true)).actionGet(); client().index(indexRequest(aliasName).type("type1").id("1").source(source("1", "test"))).actionGet();
} }
}); });
} }
@ -519,27 +489,27 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
ensureGreen(); ensureGreen();
logger.info("--> creating alias1 "); logger.info("--> creating alias1 ");
assertThat(admin().indices().prepareAliases().addAlias("test", "alias1").execute().actionGet().isAcknowledged(), equalTo(true)); assertAcked((admin().indices().prepareAliases().addAlias("test", "alias1")));
TimeValue timeout = TimeValue.timeValueSeconds(2); TimeValue timeout = TimeValue.timeValueSeconds(2);
logger.info("--> recreating alias1 "); logger.info("--> recreating alias1 ");
StopWatch stopWatch = new StopWatch(); StopWatch stopWatch = new StopWatch();
stopWatch.start(); stopWatch.start();
assertThat(admin().indices().prepareAliases().addAlias("test", "alias1").setTimeout(timeout).execute().actionGet().isAcknowledged(), equalTo(true)); assertAcked((admin().indices().prepareAliases().addAlias("test", "alias1").setTimeout(timeout)));
assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis())); assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis()));
logger.info("--> modifying alias1 to have a filter"); logger.info("--> modifying alias1 to have a filter");
stopWatch.start(); stopWatch.start();
assertThat(admin().indices().prepareAliases().addAlias("test", "alias1", termFilter("name", "foo")).setTimeout(timeout).execute().actionGet().isAcknowledged(), equalTo(true)); assertAcked((admin().indices().prepareAliases().addAlias("test", "alias1", termFilter("name", "foo")).setTimeout(timeout)));
assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis())); assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis()));
logger.info("--> recreating alias1 with the same filter"); logger.info("--> recreating alias1 with the same filter");
stopWatch.start(); stopWatch.start();
assertThat(admin().indices().prepareAliases().addAlias("test", "alias1", termFilter("name", "foo")).setTimeout(timeout).execute().actionGet().isAcknowledged(), equalTo(true)); assertAcked((admin().indices().prepareAliases().addAlias("test", "alias1", termFilter("name", "foo")).setTimeout(timeout)));
assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis())); assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis()));
logger.info("--> recreating alias1 with a different filter"); logger.info("--> recreating alias1 with a different filter");
stopWatch.start(); stopWatch.start();
assertThat(admin().indices().prepareAliases().addAlias("test", "alias1", termFilter("name", "bar")).setTimeout(timeout).execute().actionGet().isAcknowledged(), equalTo(true)); assertAcked((admin().indices().prepareAliases().addAlias("test", "alias1", termFilter("name", "bar")).setTimeout(timeout)));
assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis())); assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis()));
logger.info("--> verify that filter was updated"); logger.info("--> verify that filter was updated");
@ -548,7 +518,7 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
logger.info("--> deleting alias1"); logger.info("--> deleting alias1");
stopWatch.start(); stopWatch.start();
assertThat(admin().indices().prepareAliases().removeAlias("test", "alias1").setTimeout(timeout).execute().actionGet().isAcknowledged(), equalTo(true)); assertAcked((admin().indices().prepareAliases().removeAlias("test", "alias1").setTimeout(timeout)));
assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis())); assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis()));
@ -560,7 +530,7 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
createIndex("test"); createIndex("test");
ensureGreen(); ensureGreen();
logger.info("--> deleting alias1 which does not exist"); logger.info("--> deleting alias1 which does not exist");
assertThat(admin().indices().prepareAliases().removeAlias("test", "alias1").execute().actionGet().isAcknowledged(), equalTo(true)); assertAcked((admin().indices().prepareAliases().removeAlias("test", "alias1")));
} }
@Test @Test
@ -570,36 +540,19 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
.put("index.number_of_replicas", 0) .put("index.number_of_replicas", 0)
.build(); .build();
logger.info("--> creating indices [foobar, test, test123, foobarbaz, bazbar]"); logger.info("--> creating indices [foobar, test, test123, foobarbaz, bazbar]");
admin().indices().prepareCreate("foobar") assertAcked(prepareCreate("foobar").setSettings(indexSettings));
.setSettings(indexSettings) assertAcked(prepareCreate("test").setSettings(indexSettings));
.execute().actionGet(); assertAcked(prepareCreate("test123").setSettings(indexSettings));
admin().indices().prepareCreate("test") assertAcked(prepareCreate("foobarbaz").setSettings(indexSettings));
.setSettings(indexSettings) assertAcked(prepareCreate("bazbar").setSettings(indexSettings));
.execute().actionGet();
admin().indices().prepareCreate("test123")
.setSettings(indexSettings)
.execute().actionGet();
admin().indices().prepareCreate("foobarbaz")
.setSettings(indexSettings)
.execute().actionGet();
admin().indices().prepareCreate("bazbar")
.setSettings(indexSettings)
.execute().actionGet();
ensureGreen(); ensureGreen();
logger.info("--> creating aliases [alias1, alias2]"); logger.info("--> creating aliases [alias1, alias2]");
admin().indices().prepareAliases() assertAcked(admin().indices().prepareAliases().addAlias("foobar", "alias1").addAlias("foobar", "alias2"));
.addAlias("foobar", "alias1")
.execute().actionGet();
IndicesAliasesResponse indicesAliasesResponse = admin().indices().prepareAliases()
.addAlias("foobar", "alias2")
.execute().actionGet();
assertThat(indicesAliasesResponse.isAcknowledged(), equalTo(true));
logger.info("--> getting alias1"); logger.info("--> getting alias1");
GetAliasesResponse getResponse = admin().indices().prepareGetAliases("alias1").execute().actionGet(); GetAliasesResponse getResponse = admin().indices().prepareGetAliases("alias1").get();
assertThat(getResponse, notNullValue()); assertThat(getResponse, notNullValue());
assertThat(getResponse.getAliases().size(), equalTo(1)); assertThat(getResponse.getAliases().size(), equalTo(1));
assertThat(getResponse.getAliases().get("foobar").size(), equalTo(1)); assertThat(getResponse.getAliases().get("foobar").size(), equalTo(1));
@ -608,11 +561,11 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue()); assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue()); assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue()); assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
AliasesExistResponse existsResponse = admin().indices().prepareAliasesExist("alias1").execute().actionGet(); AliasesExistResponse existsResponse = admin().indices().prepareAliasesExist("alias1").get();
assertThat(existsResponse.exists(), equalTo(true)); assertThat(existsResponse.exists(), equalTo(true));
logger.info("--> getting all aliases that start with alias*"); logger.info("--> getting all aliases that start with alias*");
getResponse = admin().indices().prepareGetAliases("alias*").execute().actionGet(); getResponse = admin().indices().prepareGetAliases("alias*").get();
assertThat(getResponse, notNullValue()); assertThat(getResponse, notNullValue());
assertThat(getResponse.getAliases().size(), equalTo(1)); assertThat(getResponse.getAliases().size(), equalTo(1));
assertThat(getResponse.getAliases().get("foobar").size(), equalTo(2)); assertThat(getResponse.getAliases().get("foobar").size(), equalTo(2));
@ -626,24 +579,21 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
assertThat(getResponse.getAliases().get("foobar").get(1).getFilter(), nullValue()); assertThat(getResponse.getAliases().get("foobar").get(1).getFilter(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(1).getIndexRouting(), nullValue()); assertThat(getResponse.getAliases().get("foobar").get(1).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(1).getSearchRouting(), nullValue()); assertThat(getResponse.getAliases().get("foobar").get(1).getSearchRouting(), nullValue());
existsResponse = admin().indices().prepareAliasesExist("alias*").execute().actionGet(); existsResponse = admin().indices().prepareAliasesExist("alias*").get();
assertThat(existsResponse.exists(), equalTo(true)); assertThat(existsResponse.exists(), equalTo(true));
logger.info("--> creating aliases [bar, baz, foo]"); logger.info("--> creating aliases [bar, baz, foo]");
admin().indices().prepareAliases() assertAcked(admin().indices().prepareAliases()
.addAlias("bazbar", "bar") .addAlias("bazbar", "bar")
.addAlias("bazbar", "bac", termFilter("field", "value")) .addAlias("bazbar", "bac", termFilter("field", "value"))
.addAlias("foobar", "foo") .addAlias("foobar", "foo"));
.execute().actionGet();
indicesAliasesResponse = admin().indices().prepareAliases() assertAcked(admin().indices().prepareAliases()
.addAliasAction(new AliasAction(AliasAction.Type.ADD, "foobar", "bac").routing("bla")) .addAliasAction(new AliasAction(AliasAction.Type.ADD, "foobar", "bac").routing("bla")));
.execute().actionGet();
assertThat(indicesAliasesResponse.isAcknowledged(), equalTo(true));
logger.info("--> getting bar and baz for index bazbar"); logger.info("--> getting bar and baz for index bazbar");
getResponse = admin().indices().prepareGetAliases("bar", "bac").addIndices("bazbar").execute().actionGet(); getResponse = admin().indices().prepareGetAliases("bar", "bac").addIndices("bazbar").get();
assertThat(getResponse, notNullValue()); assertThat(getResponse, notNullValue());
assertThat(getResponse.getAliases().size(), equalTo(1)); assertThat(getResponse.getAliases().size(), equalTo(1));
assertThat(getResponse.getAliases().get("bazbar").size(), equalTo(2)); assertThat(getResponse.getAliases().get("bazbar").size(), equalTo(2));
@ -660,11 +610,11 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
assertThat(getResponse.getAliases().get("bazbar").get(1).getIndexRouting(), nullValue()); assertThat(getResponse.getAliases().get("bazbar").get(1).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("bazbar").get(1).getSearchRouting(), nullValue()); assertThat(getResponse.getAliases().get("bazbar").get(1).getSearchRouting(), nullValue());
existsResponse = admin().indices().prepareAliasesExist("bar", "bac") existsResponse = admin().indices().prepareAliasesExist("bar", "bac")
.addIndices("bazbar").execute().actionGet(); .addIndices("bazbar").get();
assertThat(existsResponse.exists(), equalTo(true)); assertThat(existsResponse.exists(), equalTo(true));
logger.info("--> getting *b* for index baz*"); logger.info("--> getting *b* for index baz*");
getResponse = admin().indices().prepareGetAliases("*b*").addIndices("baz*").execute().actionGet(); getResponse = admin().indices().prepareGetAliases("*b*").addIndices("baz*").get();
assertThat(getResponse, notNullValue()); assertThat(getResponse, notNullValue());
assertThat(getResponse.getAliases().size(), equalTo(1)); assertThat(getResponse.getAliases().size(), equalTo(1));
assertThat(getResponse.getAliases().get("bazbar").size(), equalTo(2)); assertThat(getResponse.getAliases().get("bazbar").size(), equalTo(2));
@ -681,11 +631,11 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
assertThat(getResponse.getAliases().get("bazbar").get(1).getIndexRouting(), nullValue()); assertThat(getResponse.getAliases().get("bazbar").get(1).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("bazbar").get(1).getSearchRouting(), nullValue()); assertThat(getResponse.getAliases().get("bazbar").get(1).getSearchRouting(), nullValue());
existsResponse = admin().indices().prepareAliasesExist("*b*") existsResponse = admin().indices().prepareAliasesExist("*b*")
.addIndices("baz*").execute().actionGet(); .addIndices("baz*").get();
assertThat(existsResponse.exists(), equalTo(true)); assertThat(existsResponse.exists(), equalTo(true));
logger.info("--> getting *b* for index *bar"); logger.info("--> getting *b* for index *bar");
getResponse = admin().indices().prepareGetAliases("b*").addIndices("*bar").execute().actionGet(); getResponse = admin().indices().prepareGetAliases("b*").addIndices("*bar").get();
assertThat(getResponse, notNullValue()); assertThat(getResponse, notNullValue());
assertThat(getResponse.getAliases().size(), equalTo(2)); assertThat(getResponse.getAliases().size(), equalTo(2));
assertThat(getResponse.getAliases().get("bazbar").size(), equalTo(2)); assertThat(getResponse.getAliases().get("bazbar").size(), equalTo(2));
@ -707,11 +657,11 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), equalTo("bla")); assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), equalTo("bla"));
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), equalTo("bla")); assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), equalTo("bla"));
existsResponse = admin().indices().prepareAliasesExist("b*") existsResponse = admin().indices().prepareAliasesExist("b*")
.addIndices("*bar").execute().actionGet(); .addIndices("*bar").get();
assertThat(existsResponse.exists(), equalTo(true)); assertThat(existsResponse.exists(), equalTo(true));
logger.info("--> getting f* for index *bar"); logger.info("--> getting f* for index *bar");
getResponse = admin().indices().prepareGetAliases("f*").addIndices("*bar").execute().actionGet(); getResponse = admin().indices().prepareGetAliases("f*").addIndices("*bar").get();
assertThat(getResponse, notNullValue()); assertThat(getResponse, notNullValue());
assertThat(getResponse.getAliases().size(), equalTo(1)); assertThat(getResponse.getAliases().size(), equalTo(1));
assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue()); assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue());
@ -720,12 +670,12 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue()); assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue()); assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
existsResponse = admin().indices().prepareAliasesExist("f*") existsResponse = admin().indices().prepareAliasesExist("f*")
.addIndices("*bar").execute().actionGet(); .addIndices("*bar").get();
assertThat(existsResponse.exists(), equalTo(true)); assertThat(existsResponse.exists(), equalTo(true));
// alias at work // alias at work
logger.info("--> getting f* for index *bac"); logger.info("--> getting f* for index *bac");
getResponse = admin().indices().prepareGetAliases("foo").addIndices("*bac").execute().actionGet(); getResponse = admin().indices().prepareGetAliases("foo").addIndices("*bac").get();
assertThat(getResponse, notNullValue()); assertThat(getResponse, notNullValue());
assertThat(getResponse.getAliases().size(), equalTo(1)); assertThat(getResponse.getAliases().size(), equalTo(1));
assertThat(getResponse.getAliases().get("foobar").size(), equalTo(1)); assertThat(getResponse.getAliases().get("foobar").size(), equalTo(1));
@ -735,11 +685,11 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue()); assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue()); assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
existsResponse = admin().indices().prepareAliasesExist("foo") existsResponse = admin().indices().prepareAliasesExist("foo")
.addIndices("*bac").execute().actionGet(); .addIndices("*bac").get();
assertThat(existsResponse.exists(), equalTo(true)); assertThat(existsResponse.exists(), equalTo(true));
logger.info("--> getting foo for index foobar"); logger.info("--> getting foo for index foobar");
getResponse = admin().indices().prepareGetAliases("foo").addIndices("foobar").execute().actionGet(); getResponse = admin().indices().prepareGetAliases("foo").addIndices("foobar").get();
assertThat(getResponse, notNullValue()); assertThat(getResponse, notNullValue());
assertThat(getResponse.getAliases().size(), equalTo(1)); assertThat(getResponse.getAliases().size(), equalTo(1));
assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue()); assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue());
@ -748,65 +698,53 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue()); assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue()); assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
existsResponse = admin().indices().prepareAliasesExist("foo") existsResponse = admin().indices().prepareAliasesExist("foo")
.addIndices("foobar").execute().actionGet(); .addIndices("foobar").get();
assertThat(existsResponse.exists(), equalTo(true)); assertThat(existsResponse.exists(), equalTo(true));
// alias at work again // alias at work again
logger.info("--> getting * for index *bac"); logger.info("--> getting * for index *bac");
getResponse = admin().indices().prepareGetAliases("*").addIndices("*bac").execute().actionGet(); getResponse = admin().indices().prepareGetAliases("*").addIndices("*bac").get();
assertThat(getResponse, notNullValue()); assertThat(getResponse, notNullValue());
assertThat(getResponse.getAliases().size(), equalTo(2)); assertThat(getResponse.getAliases().size(), equalTo(2));
assertThat(getResponse.getAliases().get("foobar").size(), equalTo(4)); assertThat(getResponse.getAliases().get("foobar").size(), equalTo(4));
assertThat(getResponse.getAliases().get("bazbar").size(), equalTo(2)); assertThat(getResponse.getAliases().get("bazbar").size(), equalTo(2));
existsResponse = admin().indices().prepareAliasesExist("*") existsResponse = admin().indices().prepareAliasesExist("*")
.addIndices("*bac").execute().actionGet(); .addIndices("*bac").get();
assertThat(existsResponse.exists(), equalTo(true)); assertThat(existsResponse.exists(), equalTo(true));
indicesAliasesResponse = admin().indices().prepareAliases() assertAcked(admin().indices().prepareAliases()
.removeAlias("foobar", "foo") .removeAlias("foobar", "foo"));
.execute().actionGet();
assertThat(indicesAliasesResponse.isAcknowledged(), equalTo(true));
getResponse = admin().indices().prepareGetAliases("foo").addIndices("foobar").execute().actionGet(); getResponse = admin().indices().prepareGetAliases("foo").addIndices("foobar").get();
assertThat(getResponse.getAliases().isEmpty(), equalTo(true)); assertThat(getResponse.getAliases().isEmpty(), equalTo(true));
existsResponse = admin().indices().prepareAliasesExist("foo") existsResponse = admin().indices().prepareAliasesExist("foo").addIndices("foobar").get();
.addIndices("foobar").execute().actionGet();
assertThat(existsResponse.exists(), equalTo(false)); assertThat(existsResponse.exists(), equalTo(false));
} }
@Test(expected = IndexMissingException.class) @Test(expected = IndexMissingException.class)
public void testAddAliasNullIndex() { public void testAddAliasNullIndex() {
admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction(null, "alias1")).get();
admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction(null, "alias1"))
.execute().actionGet();
} }
@Test(expected = ActionRequestValidationException.class) @Test(expected = ActionRequestValidationException.class)
public void testAddAliasEmptyIndex() { public void testAddAliasEmptyIndex() {
admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction("", "alias1")).get();
admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction("", "alias1"))
.execute().actionGet();
} }
@Test(expected = ActionRequestValidationException.class) @Test(expected = ActionRequestValidationException.class)
public void testAddAliasNullAlias() { public void testAddAliasNullAlias() {
admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction("index1", null)).get();
admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction("index1", null))
.execute().actionGet();
} }
@Test(expected = ActionRequestValidationException.class) @Test(expected = ActionRequestValidationException.class)
public void testAddAliasEmptyAlias() { public void testAddAliasEmptyAlias() {
admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction("index1", "")).get();
admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction("index1", ""))
.execute().actionGet();
} }
@Test @Test
public void testAddAliasNullAliasNullIndex() { public void testAddAliasNullAliasNullIndex() {
try { try {
admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction(null, null)) admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction(null, null)).get();
.execute().actionGet();
assertTrue("Should throw " + ActionRequestValidationException.class.getSimpleName(), false); assertTrue("Should throw " + ActionRequestValidationException.class.getSimpleName(), false);
} catch (ActionRequestValidationException e) { } catch (ActionRequestValidationException e) {
assertThat(e.validationErrors(), notNullValue()); assertThat(e.validationErrors(), notNullValue());
@ -817,8 +755,7 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
@Test @Test
public void testAddAliasEmptyAliasEmptyIndex() { public void testAddAliasEmptyAliasEmptyIndex() {
try { try {
admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction("", "")) admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction("", "")).get();
.execute().actionGet();
assertTrue("Should throw " + ActionRequestValidationException.class.getSimpleName(), false); assertTrue("Should throw " + ActionRequestValidationException.class.getSimpleName(), false);
} catch (ActionRequestValidationException e) { } catch (ActionRequestValidationException e) {
assertThat(e.validationErrors(), notNullValue()); assertThat(e.validationErrors(), notNullValue());
@ -828,34 +765,29 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
@Test(expected = ActionRequestValidationException.class) @Test(expected = ActionRequestValidationException.class)
public void tesRemoveAliasNullIndex() { public void tesRemoveAliasNullIndex() {
admin().indices().prepareAliases().addAliasAction(AliasAction.newRemoveAliasAction(null, "alias1")) admin().indices().prepareAliases().addAliasAction(AliasAction.newRemoveAliasAction(null, "alias1")).get();
.execute().actionGet();
} }
@Test(expected = ActionRequestValidationException.class) @Test(expected = ActionRequestValidationException.class)
public void tesRemoveAliasEmptyIndex() { public void tesRemoveAliasEmptyIndex() {
admin().indices().prepareAliases().addAliasAction(AliasAction.newRemoveAliasAction("", "alias1")) admin().indices().prepareAliases().addAliasAction(AliasAction.newRemoveAliasAction("", "alias1")).get();
.execute().actionGet();
} }
@Test(expected = ActionRequestValidationException.class) @Test(expected = ActionRequestValidationException.class)
public void tesRemoveAliasNullAlias() { public void tesRemoveAliasNullAlias() {
admin().indices().prepareAliases().addAliasAction(AliasAction.newRemoveAliasAction("index1", null)) admin().indices().prepareAliases().addAliasAction(AliasAction.newRemoveAliasAction("index1", null)).get();
.execute().actionGet();
} }
@Test(expected = ActionRequestValidationException.class) @Test(expected = ActionRequestValidationException.class)
public void tesRemoveAliasEmptyAlias() { public void tesRemoveAliasEmptyAlias() {
admin().indices().prepareAliases().addAliasAction(AliasAction.newRemoveAliasAction("index1", "")) admin().indices().prepareAliases().addAliasAction(AliasAction.newRemoveAliasAction("index1", "")).get();
.execute().actionGet();
} }
@Test @Test
public void testRemoveAliasNullAliasNullIndex() { public void testRemoveAliasNullAliasNullIndex() {
try { try {
admin().indices().prepareAliases().addAliasAction(AliasAction.newRemoveAliasAction(null, null)) admin().indices().prepareAliases().addAliasAction(AliasAction.newRemoveAliasAction(null, null)).get();
.execute().actionGet(); fail("Should throw " + ActionRequestValidationException.class.getSimpleName());
assertTrue("Should throw " + ActionRequestValidationException.class.getSimpleName(), false);
} catch (ActionRequestValidationException e) { } catch (ActionRequestValidationException e) {
assertThat(e.validationErrors(), notNullValue()); assertThat(e.validationErrors(), notNullValue());
assertThat(e.validationErrors().size(), equalTo(2)); assertThat(e.validationErrors().size(), equalTo(2));
@ -865,9 +797,8 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
@Test @Test
public void testRemoveAliasEmptyAliasEmptyIndex() { public void testRemoveAliasEmptyAliasEmptyIndex() {
try { try {
admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction("", "")) admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction("", "")).get();
.execute().actionGet(); fail("Should throw " + ActionRequestValidationException.class.getSimpleName());
assertTrue("Should throw " + ActionRequestValidationException.class.getSimpleName(), false);
} catch (ActionRequestValidationException e) { } catch (ActionRequestValidationException e) {
assertThat(e.validationErrors(), notNullValue()); assertThat(e.validationErrors(), notNullValue());
assertThat(e.validationErrors().size(), equalTo(2)); assertThat(e.validationErrors().size(), equalTo(2));
@ -881,7 +812,7 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
ensureYellow(); ensureYellow();
admin().indices().prepareAliases().addAlias("index1", "alias1").addAlias("index2", "alias2").get(); assertAcked(admin().indices().prepareAliases().addAlias("index1", "alias1").addAlias("index2", "alias2"));
GetAliasesResponse response = admin().indices().prepareGetAliases().get(); GetAliasesResponse response = admin().indices().prepareGetAliases().get();
assertThat(response.getAliases(), hasKey("index1")); assertThat(response.getAliases(), hasKey("index1"));