Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import static org.hamcrest.Matchers.containsString;
Expand Down Expand Up @@ -86,10 +89,21 @@ public void testRangeQuery() throws Exception {
);
}

private static String dateTimeString(long epochMillis, int increment, ChronoUnit precision) {
var dateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(epochMillis), ZoneOffset.UTC)
.plus(increment, precision)
.truncatedTo(precision);
return switch (precision) {
case MILLIS -> DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ROOT).format(dateTime);
case SECONDS -> DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT).format(dateTime);
case MINUTES -> DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'", Locale.ROOT).format(dateTime);
default -> dateTime.toString();
};
}

/**
* test the queries are correct if from/to are adjacent and the range is exclusive of those values
*/
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/86284")
public void testRangeQueryIntersectsAdjacentValues() throws Exception {
SearchExecutionContext context = createContext();
ShapeRelation relation = randomFrom(ShapeRelation.values());
Expand All @@ -105,8 +119,9 @@ public void testRangeQueryIntersectsAdjacentValues() throws Exception {
}
case DATE -> {
long fromValue = randomInt();
from = ZonedDateTime.ofInstant(Instant.ofEpochMilli(fromValue), ZoneOffset.UTC);
to = ZonedDateTime.ofInstant(Instant.ofEpochMilli(fromValue + 1), ZoneOffset.UTC);
var precision = randomFrom(ChronoUnit.MILLIS, ChronoUnit.SECONDS, ChronoUnit.MINUTES);
from = dateTimeString(fromValue, 0, precision);
to = dateTimeString(fromValue, 1, precision);
}
case INTEGER -> {
int fromValue = randomInt();
Expand Down Expand Up @@ -143,7 +158,6 @@ public void testRangeQueryIntersectsAdjacentValues() throws Exception {
/**
* check that we catch cases where the user specifies larger "from" than "to" value, not counting the include upper/lower settings
*/
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/86284")
public void testFromLargerToErrors() throws Exception {
SearchExecutionContext context = createContext();
RangeFieldType ft = createDefaultFieldType();
Expand All @@ -159,8 +173,9 @@ public void testFromLargerToErrors() throws Exception {
}
case DATE: {
long fromValue = randomInt();
from = ZonedDateTime.ofInstant(Instant.ofEpochMilli(fromValue), ZoneOffset.UTC);
to = ZonedDateTime.ofInstant(Instant.ofEpochMilli(fromValue - 1), ZoneOffset.UTC);
var precision = randomFrom(ChronoUnit.MILLIS, ChronoUnit.SECONDS, ChronoUnit.MINUTES);
from = dateTimeString(fromValue, 0, precision);
to = dateTimeString(fromValue, -1, precision);
break;
}
case INTEGER: {
Expand Down