From d9c8d974e6553ef767457e7eb7e5069a15863ece Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Mon, 11 Aug 2014 13:57:33 +0200 Subject: [PATCH] [TEST] Fix SimpleQueryTests.testRangeQuery assumptions. This test assumed that the `num` field was mapped as an integer on all shards and thus that all of them should fail when providing a timezone. However, since it used dynamic mappings, some shards might have this field not mapped, as a consequence they didn't fail. --- .../search/query/SimpleQueryTests.java | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/test/java/org/elasticsearch/search/query/SimpleQueryTests.java b/src/test/java/org/elasticsearch/search/query/SimpleQueryTests.java index ec4388070b9bc..8fa77ce5915ba 100644 --- a/src/test/java/org/elasticsearch/search/query/SimpleQueryTests.java +++ b/src/test/java/org/elasticsearch/search/query/SimpleQueryTests.java @@ -182,11 +182,11 @@ public void testConstantScoreQuery() throws Exception { constantScoreQuery(matchQuery("field1", "quick")).boost(1.0f + getRandom().nextFloat()))).get(); assertHitCount(searchResponse, 2l); assertFirstHit(searchResponse, hasScore(searchResponse.getHits().getAt(1).score())); - + client().prepareSearch("test").setQuery(constantScoreQuery(matchQuery("field1", "quick")).boost(1.0f + getRandom().nextFloat())).get(); assertHitCount(searchResponse, 2l); assertFirstHit(searchResponse, hasScore(searchResponse.getHits().getAt(1).score())); - + searchResponse = client().prepareSearch("test").setQuery( constantScoreQuery(boolQuery().must(matchAllQuery()).must( constantScoreQuery(matchQuery("field1", "quick")).boost(1.0f + (random.nextBoolean()? 0.0f : random.nextFloat()))))).get(); @@ -245,7 +245,7 @@ public void testAllDocsQueryString() throws InterruptedException, ExecutionExcep for (int i = 0; i < iters; i++) { SearchResponse searchResponse = client().prepareSearch("test").setQuery(queryString("*:*^10.0").boost(10.0f)).get(); assertHitCount(searchResponse, 2l); - + searchResponse = client().prepareSearch("test").setQuery( boolQuery().must(matchAllQuery()).must(constantScoreQuery(matchAllQuery()))).get(); assertHitCount(searchResponse, 2l); @@ -1608,7 +1608,7 @@ public void testMatchQueryWithSynonyms() throws IOException { assertHitCount(searchResponse, 1); searchResponse = client().prepareSearch("test").setQuery(matchQuery("text", "fast").operator(MatchQueryBuilder.Operator.AND)).get(); assertHitCount(searchResponse, 1); - + client().prepareIndex("test", "test", "2").setSource("text", "fast brown fox").get(); refresh(); searchResponse = client().prepareSearch("test").setQuery(matchQuery("text", "quick").operator(MatchQueryBuilder.Operator.AND)).get(); @@ -1666,7 +1666,7 @@ public void testQueryStringWithSynonyms() throws IOException { assertHitCount(searchResponse, 1); searchResponse = client().prepareSearch().setQuery(queryString("fast").defaultField("text").defaultOperator(QueryStringQueryBuilder.Operator.AND)).get(); assertHitCount(searchResponse, 1); - + client().prepareIndex("test", "test", "2").setSource("text", "fast brown fox").get(); refresh(); @@ -2348,16 +2348,17 @@ public void testRangeFilterNoCacheWithNow() throws Exception { @Test public void testRangeFilterWithTimeZone() throws Exception { assertAcked(prepareCreate("test") - .addMapping("type1", "date", "type=date")); + .addMapping("type1", "date", "type=date", "num", "type=integer")); ensureGreen(); - index("test", "type1", "1", "date", "2014-01-01", "num", 1); - index("test", "type1", "2", "date", "2013-12-31T23:00:00", "num", 2); - index("test", "type1", "3", "date", "2014-01-01T01:00:00", "num", 3); - // Now in UTC+1 - index("test", "type1", "4", "date", DateTime.now(DateTimeZone.forOffsetHours(1)).getMillis(), "num", 4); + indexRandom(true, + client().prepareIndex("test", "type1", "1").setSource("date", "2014-01-01", "num", 1), + client().prepareIndex("test", "type1", "2").setSource("date", "2013-12-31T23:00:00", "num", 2), + client().prepareIndex("test", "type1", "3").setSource("date", "2014-01-01T01:00:00", "num", 3), + // Now in UTC+1 + client().prepareIndex("test", "type1", "4").setSource("date", DateTime.now(DateTimeZone.forOffsetHours(1)).getMillis(), "num", 4)); + - refresh(); SearchResponse searchResponse = client().prepareSearch("test") .setQuery(QueryBuilders.filteredQuery(matchAllQuery(), FilterBuilders.rangeFilter("date").from("2014-01-01T00:00:00").to("2014-01-01T00:59:00"))) @@ -2445,16 +2446,15 @@ public void testRangeFilterWithTimeZone() throws Exception { @Test public void testRangeQueryWithTimeZone() throws Exception { assertAcked(prepareCreate("test") - .addMapping("type1", "date", "type=date")); + .addMapping("type1", "date", "type=date", "num", "type=integer")); ensureGreen(); - index("test", "type1", "1", "date", "2014-01-01", "num", 1); - index("test", "type1", "2", "date", "2013-12-31T23:00:00", "num", 2); - index("test", "type1", "3", "date", "2014-01-01T01:00:00", "num", 3); - // Now in UTC+1 - index("test", "type1", "4", "date", DateTime.now(DateTimeZone.forOffsetHours(1)).getMillis(), "num", 4); - - refresh(); + indexRandom(true, + client().prepareIndex("test", "type1", "1").setSource("date", "2014-01-01", "num", 1), + client().prepareIndex("test", "type1", "2").setSource("date", "2013-12-31T23:00:00", "num", 2), + client().prepareIndex("test", "type1", "3").setSource("date", "2014-01-01T01:00:00", "num", 3), + // Now in UTC+1 + client().prepareIndex("test", "type1", "4").setSource("date", DateTime.now(DateTimeZone.forOffsetHours(1)).getMillis(), "num", 4)); // Ensure all shards have our mappings, otherwise we can sometimes fail to hit the expected exceptions below, because some shards // will succeed in running a query (that returns 0 hits) instead of throwing the expected exception: