Skip to content

Commit

Permalink
[TEST] Fix SimpleQueryTests.testRangeQuery assumptions.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jpountz authored and areek committed Sep 8, 2014
1 parent 572944d commit d9c8d97
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/test/java/org/elasticsearch/search/query/SimpleQueryTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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")))
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d9c8d97

Please sign in to comment.