Fix line length in org.elasticsearch.routing (#37253)

Remove the line length suppression for this package and fix offending
lines

relates: #34884
This commit is contained in:
Przemyslaw Gomulka 2019-01-10 15:23:34 +01:00 committed by GitHub
parent df488720e0
commit c812e6aea6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 588 additions and 126 deletions

View File

@ -53,8 +53,6 @@
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]node[/\\]Node.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]aliases[/\\]IndexAliasesIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]monitor[/\\]jvm[/\\]JvmGcMonitorServiceSettingsTests.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]routing[/\\]AliasRoutingIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]routing[/\\]SimpleRoutingIT.java" checks="LineLength" />
<!-- Gradle requires inputs to be seriablizable -->
<suppress files="buildSrc[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]gradle[/\\]precommit[/\\]TestingConventionRule.java" checks="RegexpSinglelineJava" />

View File

@ -71,7 +71,12 @@ public class AliasRoutingIT extends ESIntegTestCase {
.execute().actionGet();
for (int i = 0; i < 5; i++) {
assertThat(client().prepareGet("alias0", "type1", "1").execute().actionGet().isExists(), equalTo(true));
assertThat(client().prepareGet("alias0", "type1", "1").execute().actionGet().getSourceAsMap().get("field").toString(), equalTo("value2"));
assertThat(client().prepareGet("alias0", "type1", "1")
.execute()
.actionGet()
.getSourceAsMap()
.get("field")
.toString(), equalTo("value2"));
}
@ -126,23 +131,80 @@ public class AliasRoutingIT extends ESIntegTestCase {
logger.info("--> search with no routing, should fine one");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch()
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(1L));
}
logger.info("--> search with wrong routing, should not find");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch().setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(0L));
assertThat(client().prepareSearch().setSize(0).setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(0L));
assertThat(client().prepareSearch("alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(0L));
assertThat(client().prepareSearch("alias1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(0L));
assertThat(client().prepareSearch()
.setRouting("1")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(0L));
assertThat(client().prepareSearch()
.setSize(0)
.setRouting("1")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(0L));
assertThat(client().prepareSearch("alias1")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(0L));
assertThat(client().prepareSearch("alias1")
.setSize(0)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(0L));
}
logger.info("--> search with correct routing, should find");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch().setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch().setSize(0).setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch("alias0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch("alias0").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch()
.setRouting("0")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch()
.setSize(0)
.setRouting("0")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch("alias0")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch("alias0")
.setSize(0)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(1L));
}
logger.info("--> indexing with id [2], and routing [1] using alias");
@ -150,50 +212,166 @@ public class AliasRoutingIT extends ESIntegTestCase {
logger.info("--> search with no routing, should fine two");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch()
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch()
.setSize(0)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(2L));
}
logger.info("--> search with 0 routing, should find one");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch().setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch().setSize(0).setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch("alias0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch("alias0").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch()
.setRouting("0")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch()
.setSize(0)
.setRouting("0")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch("alias0")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch("alias0")
.setSize(0)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(1L));
}
logger.info("--> search with 1 routing, should find one");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch().setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch().setSize(0).setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch("alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch("alias1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch()
.setRouting("1")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch()
.setSize(0)
.setRouting("1")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch("alias1")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch("alias1")
.setSize(0)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(1L));
}
logger.info("--> search with 0,1 indexRoutings , should find two");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch().setRouting("0", "1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch().setSize(0).setRouting("0", "1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("alias01").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("alias01").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch()
.setRouting("0", "1")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch()
.setSize(0)
.setRouting("0", "1")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("alias01")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("alias01")
.setSize(0)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(2L));
}
logger.info("--> search with two routing aliases , should find two");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch("alias0", "alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("alias0", "alias1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("alias0", "alias1")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("alias0", "alias1")
.setSize(0)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(2L));
}
logger.info("--> search with alias0, alias1 and alias01, should find two");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch("alias0", "alias1", "alias01").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("alias0", "alias1", "alias01").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("alias0", "alias1", "alias01")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("alias0", "alias1", "alias01")
.setSize(0)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(2L));
}
logger.info("--> search with test, alias0 and alias1, should find two");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch("test", "alias0", "alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("test", "alias0", "alias1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("test", "alias0", "alias1")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("test", "alias0", "alias1")
.setSize(0)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(2L));
}
}
@ -242,20 +420,53 @@ public class AliasRoutingIT extends ESIntegTestCase {
logger.info("--> search with alias-a1,alias-b0, should not find");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch("alias-a1", "alias-b0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(0L));
assertThat(client().prepareSearch("alias-a1", "alias-b0").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(0L));
assertThat(client().prepareSearch("alias-a1", "alias-b0")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(0L));
assertThat(client().prepareSearch("alias-a1", "alias-b0")
.setSize(0)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(0L));
}
logger.info("--> search with alias-ab, should find two");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch("alias-ab").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("alias-ab").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("alias-ab")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("alias-ab")
.setSize(0)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(2L));
}
logger.info("--> search with alias-a0,alias-b1 should find two");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch("alias-a0", "alias-b1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("alias-a0", "alias-b1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("alias-a0", "alias-b1")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("alias-a0", "alias-b1")
.setSize(0)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(2L));
}
}
@ -279,7 +490,12 @@ public class AliasRoutingIT extends ESIntegTestCase {
logger.info("--> search all on index_* should find two");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch("index_*").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("index_*")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(2L));
}
}
@ -301,7 +517,12 @@ public class AliasRoutingIT extends ESIntegTestCase {
logger.info("--> indexing on index_2 which is a concrete index");
client().prepareIndex("index_2", "type2", "2").setSource("field", "value2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();
SearchResponse searchResponse = client().prepareSearch("index_*").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(1).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
SearchResponse searchResponse = client().prepareSearch("index_*")
.setSearchType(SearchType.QUERY_THEN_FETCH)
.setSize(1)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet();
logger.info("--> search all on index_* should find two");
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L));
@ -324,8 +545,19 @@ public class AliasRoutingIT extends ESIntegTestCase {
logger.info("--> verifying get and search with routing, should find");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareGet("test", "type1", "0").setRouting("3").execute().actionGet().isExists(), equalTo(true));
assertThat(client().prepareSearch("alias").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch("alias").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch("alias")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch("alias")
.setSize(0)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(1L));
}
logger.info("--> creating alias with routing [4]");
@ -334,8 +566,19 @@ public class AliasRoutingIT extends ESIntegTestCase {
logger.info("--> verifying search with wrong routing should not find");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch("alias").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(0L));
assertThat(client().prepareSearch("alias").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(0L));
assertThat(client().prepareSearch("alias")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(0L));
assertThat(client().prepareSearch("alias")
.setSize(0)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(0L));
}
logger.info("--> creating alias with search routing [3,4] and index routing 4");
@ -350,8 +593,19 @@ public class AliasRoutingIT extends ESIntegTestCase {
for (int i = 0; i < 5; i++) {
assertThat(client().prepareGet("test", "type1", "0").setRouting("3").execute().actionGet().isExists(), equalTo(true));
assertThat(client().prepareGet("test", "type1", "1").setRouting("4").execute().actionGet().isExists(), equalTo(true));
assertThat(client().prepareSearch("alias").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("alias").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("alias")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("alias")
.setSize(0)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits().value, equalTo(2L));
}
}

View File

@ -78,7 +78,10 @@ public class SimpleRoutingIT extends ESIntegTestCase {
ensureGreen();
String routingValue = findNonMatchingRoutingValue("test", "1");
logger.info("--> indexing with id [1], and routing [{}]", routingValue);
client().prepareIndex("test", "type1", "1").setRouting(routingValue).setSource("field", "value1").setRefreshPolicy(RefreshPolicy.IMMEDIATE)
client().prepareIndex("test", "type1", "1")
.setRouting(routingValue)
.setSource("field", "value1")
.setRefreshPolicy(RefreshPolicy.IMMEDIATE)
.get();
logger.info("--> verifying get with no routing, should not find anything");
for (int i = 0; i < 5; i++) {
@ -86,25 +89,40 @@ public class SimpleRoutingIT extends ESIntegTestCase {
}
logger.info("--> verifying get with routing, should find");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareGet("test", "type1", "1").setRouting(routingValue).execute().actionGet().isExists(), equalTo(true));
assertThat(client().prepareGet("test", "type1", "1")
.setRouting(routingValue)
.execute()
.actionGet()
.isExists(), equalTo(true));
}
logger.info("--> deleting with no routing, should not delete anything");
client().prepareDelete("test", "type1", "1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();
for (int i = 0; i < 5; i++) {
assertThat(client().prepareGet("test", "type1", "1").execute().actionGet().isExists(), equalTo(false));
assertThat(client().prepareGet("test", "type1", "1").setRouting(routingValue).execute().actionGet().isExists(), equalTo(true));
assertThat(client().prepareGet("test", "type1", "1")
.setRouting(routingValue)
.execute()
.actionGet()
.isExists(), equalTo(true));
}
logger.info("--> deleting with routing, should delete");
client().prepareDelete("test", "type1", "1").setRouting(routingValue).setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();
for (int i = 0; i < 5; i++) {
assertThat(client().prepareGet("test", "type1", "1").execute().actionGet().isExists(), equalTo(false));
assertThat(client().prepareGet("test", "type1", "1").setRouting(routingValue).execute().actionGet().isExists(), equalTo(false));
assertThat(client().prepareGet("test", "type1", "1")
.setRouting(routingValue)
.execute()
.actionGet()
.isExists(), equalTo(false));
}
logger.info("--> indexing with id [1], and routing [0]");
client().prepareIndex("test", "type1", "1").setRouting(routingValue).setSource("field", "value1").setRefreshPolicy(RefreshPolicy.IMMEDIATE)
client().prepareIndex("test", "type1", "1")
.setRouting(routingValue)
.setSource("field", "value1")
.setRefreshPolicy(RefreshPolicy.IMMEDIATE)
.get();
logger.info("--> verifying get with no routing, should not find anything");
for (int i = 0; i < 5; i++) {
@ -112,7 +130,11 @@ public class SimpleRoutingIT extends ESIntegTestCase {
}
logger.info("--> verifying get with routing, should find");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareGet("test", "type1", "1").setRouting(routingValue).execute().actionGet().isExists(), equalTo(true));
assertThat(client().prepareGet("test", "type1", "1")
.setRouting(routingValue)
.execute()
.actionGet()
.isExists(), equalTo(true));
}
}
@ -122,7 +144,10 @@ public class SimpleRoutingIT extends ESIntegTestCase {
String routingValue = findNonMatchingRoutingValue("test", "1");
logger.info("--> indexing with id [1], and routing [{}]", routingValue);
client().prepareIndex("test", "type1", "1").setRouting(routingValue).setSource("field", "value1").setRefreshPolicy(RefreshPolicy.IMMEDIATE)
client().prepareIndex("test", "type1", "1")
.setRouting(routingValue)
.setSource("field", "value1")
.setRefreshPolicy(RefreshPolicy.IMMEDIATE)
.get();
logger.info("--> verifying get with no routing, should not find anything");
for (int i = 0; i < 5; i++) {
@ -130,65 +155,193 @@ public class SimpleRoutingIT extends ESIntegTestCase {
}
logger.info("--> verifying get with routing, should find");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareGet("test", "type1", "1").setRouting(routingValue).execute().actionGet().isExists(), equalTo(true));
assertThat(client().prepareGet("test", "type1", "1")
.setRouting(routingValue)
.execute()
.actionGet()
.isExists(), equalTo(true));
}
logger.info("--> search with no routing, should fine one");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch()
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits()
.value, equalTo(1L));
}
logger.info("--> search with wrong routing, should not find");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch().setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(0L));
assertThat(client().prepareSearch().setSize(0).setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(0L));
assertThat(client().prepareSearch()
.setRouting("1")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits()
.value, equalTo(0L));
assertThat(client().prepareSearch()
.setSize(0)
.setRouting("1")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits()
.value, equalTo(0L));
}
logger.info("--> search with correct routing, should find");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch().setRouting(routingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch().setSize(0).setRouting(routingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch()
.setRouting(routingValue)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits()
.value, equalTo(1L));
assertThat(client().prepareSearch()
.setSize(0)
.setRouting(routingValue)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits()
.value, equalTo(1L));
}
String secondRoutingValue = "1";
logger.info("--> indexing with id [{}], and routing [{}]", routingValue, secondRoutingValue);
client().prepareIndex("test", "type1", routingValue).setRouting(secondRoutingValue).setSource("field", "value1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();
client().prepareIndex("test", "type1", routingValue)
.setRouting(secondRoutingValue)
.setSource("field", "value1")
.setRefreshPolicy(RefreshPolicy.IMMEDIATE)
.get();
logger.info("--> search with no routing, should fine two");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch()
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits()
.value, equalTo(2L));
assertThat(client().prepareSearch()
.setSize(0)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits()
.value, equalTo(2L));
}
logger.info("--> search with {} routing, should find one", routingValue);
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch().setRouting(routingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch().setSize(0).setRouting(routingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch()
.setRouting(routingValue)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits()
.value, equalTo(1L));
assertThat(client().prepareSearch()
.setSize(0)
.setRouting(routingValue)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits()
.value, equalTo(1L));
}
logger.info("--> search with {} routing, should find one", secondRoutingValue);
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch().setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch().setSize(0).setRouting(secondRoutingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch()
.setRouting("1")
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits()
.value, equalTo(1L));
assertThat(client().prepareSearch()
.setSize(0)
.setRouting(secondRoutingValue)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits()
.value, equalTo(1L));
}
logger.info("--> search with {},{} indexRoutings , should find two", routingValue, "1");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch().setRouting(routingValue, secondRoutingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch().setSize(0).setRouting(routingValue, secondRoutingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch()
.setRouting(routingValue, secondRoutingValue)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits()
.value, equalTo(2L));
assertThat(client().prepareSearch()
.setSize(0)
.setRouting(routingValue, secondRoutingValue)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits()
.value, equalTo(2L));
}
logger.info("--> search with {},{},{} indexRoutings , should find two", routingValue, secondRoutingValue, routingValue);
for (int i = 0; i < 5; i++) {
assertThat(client().prepareSearch().setRouting(routingValue, secondRoutingValue, routingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch().setSize(0).setRouting(routingValue, secondRoutingValue,routingValue).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch()
.setRouting(routingValue, secondRoutingValue, routingValue)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits()
.value, equalTo(2L));
assertThat(client().prepareSearch()
.setSize(0)
.setRouting(routingValue, secondRoutingValue, routingValue)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet()
.getHits()
.getTotalHits()
.value, equalTo(2L));
}
}
public void testRequiredRoutingCrudApis() throws Exception {
client().admin().indices().prepareCreate("test").addAlias(new Alias("alias"))
.addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("_routing").field("required", true).endObject().endObject().endObject())
.execute().actionGet();
client().admin()
.indices()
.prepareCreate("test")
.addAlias(new Alias("alias"))
.addMapping("type1", XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("_routing")
.field("required", true)
.endObject()
.endObject()
.endObject())
.execute()
.actionGet();
ensureGreen();
String routingValue = findNonMatchingRoutingValue("test", "1");
@ -207,7 +360,12 @@ public class SimpleRoutingIT extends ESIntegTestCase {
logger.info("--> verifying get with routing, should find");
for (int i = 0; i < 5; i++) {
assertThat(client().prepareGet(indexOrAlias(), "type1", "1").setRouting(routingValue).execute().actionGet().isExists(), equalTo(true));
assertThat(client()
.prepareGet(indexOrAlias(), "type1", "1")
.setRouting(routingValue)
.execute()
.actionGet()
.isExists(), equalTo(true));
}
logger.info("--> deleting with no routing, should fail");
@ -226,17 +384,28 @@ public class SimpleRoutingIT extends ESIntegTestCase {
assertThat(e.status(), equalTo(RestStatus.BAD_REQUEST));
assertThat(e.getMessage(), equalTo("routing is required for [test]/[type1]/[1]"));
}
assertThat(client().prepareGet(indexOrAlias(), "type1", "1").setRouting(routingValue).execute().actionGet().isExists(), equalTo(true));
assertThat(client()
.prepareGet(indexOrAlias(), "type1", "1")
.setRouting(routingValue)
.execute()
.actionGet()
.isExists(), equalTo(true));
}
try {
client().prepareUpdate(indexOrAlias(), "type1", "1").setDoc(Requests.INDEX_CONTENT_TYPE, "field", "value2").execute().actionGet();
client().prepareUpdate(indexOrAlias(), "type1", "1")
.setDoc(Requests.INDEX_CONTENT_TYPE, "field", "value2")
.execute()
.actionGet();
fail("update with missing routing when routing is required should fail");
} catch (ElasticsearchException e) {
assertThat(e.unwrapCause(), instanceOf(RoutingMissingException.class));
}
client().prepareUpdate(indexOrAlias(), "type1", "1").setRouting(routingValue).setDoc(Requests.INDEX_CONTENT_TYPE, "field", "value2").get();
client().prepareUpdate(indexOrAlias(), "type1", "1")
.setRouting(routingValue)
.setDoc(Requests.INDEX_CONTENT_TYPE, "field", "value2")
.get();
client().admin().indices().prepareRefresh().execute().actionGet();
for (int i = 0; i < 5; i++) {
@ -262,7 +431,12 @@ public class SimpleRoutingIT extends ESIntegTestCase {
assertThat(e.status(), equalTo(RestStatus.BAD_REQUEST));
assertThat(e.getMessage(), equalTo("routing is required for [test]/[type1]/[1]"));
}
assertThat(client().prepareGet(indexOrAlias(), "type1", "1").setRouting(routingValue).execute().actionGet().isExists(), equalTo(false));
assertThat(client()
.prepareGet(indexOrAlias(), "type1", "1")
.setRouting(routingValue)
.execute()
.actionGet()
.isExists(), equalTo(false));
}
}
@ -275,8 +449,14 @@ public class SimpleRoutingIT extends ESIntegTestCase {
.execute().actionGet();
ensureGreen();
{
BulkResponse bulkResponse = client().prepareBulk().add(Requests.indexRequest(indexOrAlias()).type("type1").id("1")
.source(Requests.INDEX_CONTENT_TYPE, "field", "value")).execute().actionGet();
BulkResponse bulkResponse = client()
.prepareBulk()
.add(Requests.indexRequest(indexOrAlias())
.type("type1")
.id("1")
.source(Requests.INDEX_CONTENT_TYPE, "field", "value"))
.execute()
.actionGet();
assertThat(bulkResponse.getItems().length, equalTo(1));
assertThat(bulkResponse.hasFailures(), equalTo(true));
@ -290,8 +470,15 @@ public class SimpleRoutingIT extends ESIntegTestCase {
}
{
BulkResponse bulkResponse = client().prepareBulk().add(Requests.indexRequest(indexOrAlias()).type("type1").id("1").routing("0")
.source(Requests.INDEX_CONTENT_TYPE, "field", "value")).execute().actionGet();
BulkResponse bulkResponse = client()
.prepareBulk()
.add(Requests.indexRequest(indexOrAlias())
.type("type1")
.id("1")
.routing("0")
.source(Requests.INDEX_CONTENT_TYPE, "field", "value"))
.execute()
.actionGet();
assertThat(bulkResponse.hasFailures(), equalTo(false));
}
@ -343,10 +530,20 @@ public class SimpleRoutingIT extends ESIntegTestCase {
public void testRequiredRoutingMappingVariousAPIs() throws Exception {
client().admin().indices().prepareCreate("test").addAlias(new Alias("alias"))
.addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("_routing").field("required", true).endObject().endObject().endObject())
.execute().actionGet();
client().admin()
.indices()
.prepareCreate("test")
.addAlias(new Alias("alias"))
.addMapping("type1", XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("_routing")
.field("required", true)
.endObject()
.endObject()
.endObject())
.execute()
.actionGet();
ensureGreen();
String routingValue = findNonMatchingRoutingValue("test", "1");
logger.info("--> indexing with id [1], and routing [{}]", routingValue);
@ -356,7 +553,11 @@ public class SimpleRoutingIT extends ESIntegTestCase {
.setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();
logger.info("--> verifying get with id [1] with routing [0], should succeed");
assertThat(client().prepareGet(indexOrAlias(), "type1", "1").setRouting(routingValue).execute().actionGet().isExists(), equalTo(true));
assertThat(client().prepareGet(indexOrAlias(), "type1", "1")
.setRouting(routingValue)
.execute()
.actionGet()
.isExists(), equalTo(true));
logger.info("--> verifying get with id [1], with no routing, should fail");
try {
@ -383,7 +584,9 @@ public class SimpleRoutingIT extends ESIntegTestCase {
}
logger.info("--> verifying term vector with id [1], with routing [0], should succeed");
TermVectorsResponse termVectorsResponse = client().prepareTermVectors(indexOrAlias(), "type1", "1").setRouting(routingValue).get();
TermVectorsResponse termVectorsResponse = client().prepareTermVectors(indexOrAlias(), "type1", "1")
.setRouting(routingValue)
.get();
assertThat(termVectorsResponse.isExists(), equalTo(true));
assertThat(termVectorsResponse.getId(), equalTo("1"));
@ -429,8 +632,11 @@ public class SimpleRoutingIT extends ESIntegTestCase {
assertThat(multiGetResponse.getResponses()[1].getFailure().getMessage(), equalTo("routing is required for [test]/[type1]/[2]"));
MultiTermVectorsResponse multiTermVectorsResponse = client().prepareMultiTermVectors()
.add(new TermVectorsRequest(indexOrAlias(), "type1", "1").routing(routingValue))
.add(new TermVectorsRequest(indexOrAlias(), "type1", "2").routing(routingValue)).get();
.add(new TermVectorsRequest(indexOrAlias(), "type1", "1")
.routing(routingValue))
.add(new TermVectorsRequest(indexOrAlias(), "type1", "2")
.routing(routingValue))
.get();
assertThat(multiTermVectorsResponse.getResponses().length, equalTo(2));
assertThat(multiTermVectorsResponse.getResponses()[0].getId(), equalTo("1"));
assertThat(multiTermVectorsResponse.getResponses()[0].isFailed(), equalTo(false));
@ -447,12 +653,16 @@ public class SimpleRoutingIT extends ESIntegTestCase {
assertThat(multiTermVectorsResponse.getResponses().length, equalTo(2));
assertThat(multiTermVectorsResponse.getResponses()[0].getId(), equalTo("1"));
assertThat(multiTermVectorsResponse.getResponses()[0].isFailed(), equalTo(true));
assertThat(multiTermVectorsResponse.getResponses()[0].getFailure().getCause().getMessage(), equalTo("routing is required for [test]/[type1]/[1]"));
assertThat(multiTermVectorsResponse.getResponses()[0].getFailure()
.getCause()
.getMessage(), equalTo("routing is required for [test]/[type1]/[1]"));
assertThat(multiTermVectorsResponse.getResponses()[0].getResponse(), nullValue());
assertThat(multiTermVectorsResponse.getResponses()[1].getId(), equalTo("2"));
assertThat(multiTermVectorsResponse.getResponses()[1].isFailed(), equalTo(true));
assertThat(multiTermVectorsResponse.getResponses()[1].getResponse(), nullValue());
assertThat(multiTermVectorsResponse.getResponses()[1].getFailure().getCause().getMessage(), equalTo("routing is required for [test]/[type1]/[2]"));
assertThat(multiTermVectorsResponse.getResponses()[1].getFailure()
.getCause()
.getMessage(), equalTo("routing is required for [test]/[type1]/[2]"));
}
private static String indexOrAlias() {