Skip to content

Commit

Permalink
Fix line length for aliases and remove suppression (elastic#37455)
Browse files Browse the repository at this point in the history
  • Loading branch information
dliappis authored Jan 16, 2019
1 parent 6d99e79 commit 347cbaf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
4 changes: 0 additions & 4 deletions buildSrc/src/main/resources/checkstyle_suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
<suppress files="client[/\\]rest-high-level[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]client[/\\]documentation[/\\]WatcherDocumentationIT.java" id="SnippetLength" />
<suppress files="modules[/\\]reindex[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]client[/\\]documentation[/\\]ReindexDocumentationIT.java" id="SnippetLength" />

<!-- Hopefully temporary suppression of LineLength on files that don't pass it. We should remove these when we the
files start to pass. -->
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]aliases[/\\]IndexAliasesIT.java" checks="LineLength" />

<!-- Gradle requires inputs to be seriablizable -->
<suppress files="buildSrc[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]gradle[/\\]precommit[/\\]TestingConventionRule.java" checks="RegexpSinglelineJava" />
</suppressions>
59 changes: 40 additions & 19 deletions server/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ public void testFilteringAliases() throws Exception {
logger.info("--> making sure that filter was stored with alias [alias1] and filter [user:kimchy]");
ClusterState clusterState = admin().cluster().prepareState().get().getState();
IndexMetaData indexMd = clusterState.metaData().index("test");
assertThat(indexMd.getAliases().get("alias1").filter().string(), equalTo("{\"term\":{\"user\":{\"value\":\"kimchy\",\"boost\":1.0}}}"));
assertThat(indexMd.getAliases().get("alias1").filter().string(),
equalTo("{\"term\":{\"user\":{\"value\":\"kimchy\",\"boost\":1.0}}}"));

}

Expand Down Expand Up @@ -321,32 +322,38 @@ public void testSearchingFilteringAliasesTwoIndices() throws Exception {
logger.info("--> checking filtering alias for two indices");
SearchResponse searchResponse = client().prepareSearch("foos").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "1", "5");
assertThat(client().prepareSearch("foos").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("foos")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(2L));

logger.info("--> checking filtering alias for one index");
searchResponse = client().prepareSearch("bars").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "2");
assertThat(client().prepareSearch("bars").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch("bars")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(1L));

logger.info("--> checking filtering alias for two indices and one complete index");
searchResponse = client().prepareSearch("foos", "test1").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "1", "2", "3", "4", "5");
assertThat(client().prepareSearch("foos", "test1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(5L));
assertThat(client().prepareSearch("foos", "test1")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(5L));

logger.info("--> checking filtering alias for two indices and non-filtering alias for one index");
searchResponse = client().prepareSearch("foos", "aliasToTest1").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "1", "2", "3", "4", "5");
assertThat(client().prepareSearch("foos", "aliasToTest1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(5L));
assertThat(client().prepareSearch("foos", "aliasToTest1")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(5L));

logger.info("--> checking filtering alias for two indices and non-filtering alias for both indices");
searchResponse = client().prepareSearch("foos", "aliasToTests").setQuery(QueryBuilders.matchAllQuery()).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(8L));
assertThat(client().prepareSearch("foos", "aliasToTests").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(8L));
assertThat(client().prepareSearch("foos", "aliasToTests")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(8L));

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")).get();
assertHits(searchResponse.getHits(), "4", "8");
assertThat(client().prepareSearch("foos", "aliasToTests").setSize(0).setQuery(QueryBuilders.termQuery("name", "something")).get().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("foos", "aliasToTests")
.setSize(0).setQuery(QueryBuilders.termQuery("name", "something")).get().getHits().getTotalHits().value, equalTo(2L));
}

public void testSearchingFilteringAliasesMultipleIndices() throws Exception {
Expand Down Expand Up @@ -390,27 +397,33 @@ public void testSearchingFilteringAliasesMultipleIndices() throws Exception {
logger.info("--> checking filtering alias for multiple indices");
SearchResponse searchResponse = client().prepareSearch("filter23", "filter13").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "21", "31", "13", "33");
assertThat(client().prepareSearch("filter23", "filter13").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(4L));
assertThat(client().prepareSearch("filter23", "filter13")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(4L));

searchResponse = client().prepareSearch("filter23", "filter1").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "21", "31", "11", "12", "13");
assertThat(client().prepareSearch("filter23", "filter1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(5L));
assertThat(client().prepareSearch("filter23", "filter1")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(5L));

searchResponse = client().prepareSearch("filter13", "filter1").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "11", "12", "13", "33");
assertThat(client().prepareSearch("filter13", "filter1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(4L));
assertThat(client().prepareSearch("filter13", "filter1")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(4L));

searchResponse = client().prepareSearch("filter13", "filter1", "filter23").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "11", "12", "13", "21", "31", "33");
assertThat(client().prepareSearch("filter13", "filter1", "filter23").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(6L));
assertThat(client().prepareSearch("filter13", "filter1", "filter23")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(6L));

searchResponse = client().prepareSearch("filter23", "filter13", "test2").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "21", "22", "23", "31", "13", "33");
assertThat(client().prepareSearch("filter23", "filter13", "test2").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(6L));
assertThat(client().prepareSearch("filter23", "filter13", "test2")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(6L));

searchResponse = client().prepareSearch("filter23", "filter13", "test1", "test2").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "11", "12", "13", "21", "22", "23", "31", "33");
assertThat(client().prepareSearch("filter23", "filter13", "test1", "test2").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(8L));
assertThat(client().prepareSearch("filter23", "filter13", "test1", "test2")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(8L));
}

public void testDeletingByQueryFilteringAliases() throws Exception {
Expand Down Expand Up @@ -447,7 +460,8 @@ public void testDeletingByQueryFilteringAliases() throws Exception {
refresh();

logger.info("--> checking counts before delete");
assertThat(client().prepareSearch("bars").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch("bars")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(1L));
}

public void testDeleteAliases() throws Exception {
Expand Down Expand Up @@ -511,13 +525,17 @@ public void testWaitForAliasCreationMultipleShards() throws Exception {

public void testWaitForAliasCreationSingleShard() throws Exception {
logger.info("--> creating index [test]");
assertAcked(admin().indices().create(createIndexRequest("test").settings(Settings.builder().put("index.number_of_replicas", 0).put("index.number_of_shards", 1))).get());
assertAcked(admin().indices().create(createIndexRequest("test").settings(Settings.builder()
.put("index.number_of_replicas", 0)
.put("index.number_of_shards", 1)))
.get());

ensureGreen();

for (int i = 0; i < 10; i++) {
assertAcked(admin().indices().prepareAliases().addAlias("test", "alias" + i));
client().index(indexRequest("alias" + i).type("type1").id("1").source(source("1", "test"), XContentType.JSON)).get();
client().index(indexRequest("alias" + i).type("type1").id("1").source(source("1", "test"),
XContentType.JSON)).get();
}
}

Expand Down Expand Up @@ -579,7 +597,8 @@ public void testSameAlias() throws Exception {
assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis()));

logger.info("--> verify that filter was updated");
AliasMetaData aliasMetaData = ((AliasOrIndex.Alias) internalCluster().clusterService().state().metaData().getAliasAndIndexLookup().get("alias1")).getFirstAliasMetaData();
AliasMetaData aliasMetaData = ((AliasOrIndex.Alias) internalCluster()
.clusterService().state().metaData().getAliasAndIndexLookup().get("alias1")).getFirstAliasMetaData();
assertThat(aliasMetaData.getFilter().toString(), equalTo("{\"term\":{\"name\":{\"value\":\"bar\",\"boost\":1.0}}}"));

logger.info("--> deleting alias1");
Expand Down Expand Up @@ -905,8 +924,10 @@ public void testAddAliasWithFilterNoMapping() throws Exception {

public void testAliasFilterWithNowInRangeFilterAndQuery() throws Exception {
assertAcked(prepareCreate("my-index").addMapping("my-type", "timestamp", "type=date"));
assertAcked(admin().indices().prepareAliases().addAlias("my-index", "filter1", rangeQuery("timestamp").from("2016-12-01").to("2016-12-31")));
assertAcked(admin().indices().prepareAliases().addAlias("my-index", "filter2", rangeQuery("timestamp").from("2016-01-01").to("2016-12-31")));
assertAcked(admin().indices().prepareAliases()
.addAlias("my-index", "filter1", rangeQuery("timestamp").from("2016-12-01").to("2016-12-31")));
assertAcked(admin().indices().prepareAliases()
.addAlias("my-index", "filter2", rangeQuery("timestamp").from("2016-01-01").to("2016-12-31")));

final int numDocs = scaledRandomIntBetween(5, 52);
for (int i = 1; i <= numDocs; i++) {
Expand Down

0 comments on commit 347cbaf

Please sign in to comment.