Skip to content

Commit

Permalink
Fix test failures due to unmapped field
Browse files Browse the repository at this point in the history
Fixes some query builder tests for cachability of the generated query that only
makes sense when date fields are registered in the test. In 6.8, incontrast to
newer versions, we still run these tests randomly without any registered field
mappers. In this case the test would fail. This changes those tests to get
skipped in those cases instead.
  • Loading branch information
Christoph Büscher committed Apr 2, 2020
1 parent acb4224 commit 62c1e3d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,8 @@ private static CannedBinaryTokenStream.BinaryToken[] createGiantGraphMultiTerms(
* "now" on date fields should make the query non-cachable.
*/
public void testCachingStrategiesWithNow() throws IOException {
// if we hit a date field with "now", this should diable cachability
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
// if we hit a date field with "now", this should disable cachability
MatchQueryBuilder queryBuilder = new MatchQueryBuilder(DATE_FIELD_NAME, "now");
QueryShardContext context = createShardContext();
assert context.isCacheable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,8 @@ private static IndexMetaData newIndexMeta(String name, Settings oldIndexSettings
* "now" on date fields should make the query non-cachable.
*/
public void testCachingStrategiesWithNow() throws IOException {
// if we hit a date field with "now", this should diable cachability
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
// if we hit a date field with "now", this should disable cachability
MultiMatchQueryBuilder queryBuilder = new MultiMatchQueryBuilder("now", DATE_FIELD_NAME);
QueryShardContext context = createShardContext();
assert context.isCacheable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1549,12 +1549,13 @@ private static IndexMetaData newIndexMeta(String name, Settings oldIndexSettings
* This test checks the search context cacheable flag is updated accordingly.
*/
public void testCachingStrategiesWithNow() throws IOException {
// if we hit all fields, this should contain a date field and should diable cachability
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
// if we hit all fields, this should contain a date field and should disable cachability
String query = "now " + randomAlphaOfLengthBetween(4, 10);
QueryStringQueryBuilder queryStringQueryBuilder = new QueryStringQueryBuilder(query);
assertQueryCachability(queryStringQueryBuilder, false);

// if we hit a date field with "now", this should diable cachability
// if we hit a date field with "now", this should disable cachability
queryStringQueryBuilder = new QueryStringQueryBuilder("now");
queryStringQueryBuilder.field(DATE_FIELD_NAME);
assertQueryCachability(queryStringQueryBuilder, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,12 +800,13 @@ public void testReadFrom_5_6() throws IOException {
* This test checks the search context cacheable flag is updated accordingly.
*/
public void testCachingStrategiesWithNow() throws IOException {
// if we hit all fields, this should contain a date field and should diable cachability
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
// if we hit all fields, this should contain a date field and should disable cachability
String query = "now " + randomAlphaOfLengthBetween(4, 10);
SimpleQueryStringBuilder queryBuilder = new SimpleQueryStringBuilder(query);
assertQueryCachability(queryBuilder, false);

// if we hit a date field with "now", this should diable cachability
// if we hit a date field with "now", this should disable cachability
queryBuilder = new SimpleQueryStringBuilder("now");
queryBuilder.field(DATE_FIELD_NAME);
assertQueryCachability(queryBuilder, false);
Expand Down

0 comments on commit 62c1e3d

Please sign in to comment.