41
41
import java .time .Instant ;
42
42
import java .time .ZoneOffset ;
43
43
import java .time .ZonedDateTime ;
44
+ import java .time .format .DateTimeFormatter ;
45
+ import java .time .temporal .ChronoUnit ;
44
46
import java .util .Collections ;
45
47
import java .util .List ;
48
+ import java .util .Locale ;
46
49
import java .util .Map ;
47
50
48
51
import static org .hamcrest .Matchers .containsString ;
@@ -86,10 +89,21 @@ public void testRangeQuery() throws Exception {
86
89
);
87
90
}
88
91
92
+ private static String dateTimeString (long epochMillis , int increment , ChronoUnit precision ) {
93
+ var dateTime = ZonedDateTime .ofInstant (Instant .ofEpochMilli (epochMillis ), ZoneOffset .UTC )
94
+ .plus (increment , precision )
95
+ .truncatedTo (precision );
96
+ return switch (precision ) {
97
+ case MILLIS -> DateTimeFormatter .ofPattern ("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" , Locale .ROOT ).format (dateTime );
98
+ case SECONDS -> DateTimeFormatter .ofPattern ("yyyy-MM-dd'T'HH:mm:ss'Z'" , Locale .ROOT ).format (dateTime );
99
+ case MINUTES -> DateTimeFormatter .ofPattern ("yyyy-MM-dd'T'HH:mm'Z'" , Locale .ROOT ).format (dateTime );
100
+ default -> dateTime .toString ();
101
+ };
102
+ }
103
+
89
104
/**
90
105
* test the queries are correct if from/to are adjacent and the range is exclusive of those values
91
106
*/
92
- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/86284" )
93
107
public void testRangeQueryIntersectsAdjacentValues () throws Exception {
94
108
SearchExecutionContext context = createContext ();
95
109
ShapeRelation relation = randomFrom (ShapeRelation .values ());
@@ -105,8 +119,9 @@ public void testRangeQueryIntersectsAdjacentValues() throws Exception {
105
119
}
106
120
case DATE -> {
107
121
long fromValue = randomInt ();
108
- from = ZonedDateTime .ofInstant (Instant .ofEpochMilli (fromValue ), ZoneOffset .UTC );
109
- to = ZonedDateTime .ofInstant (Instant .ofEpochMilli (fromValue + 1 ), ZoneOffset .UTC );
122
+ var precision = randomFrom (ChronoUnit .MILLIS , ChronoUnit .SECONDS , ChronoUnit .MINUTES );
123
+ from = dateTimeString (fromValue , 0 , precision );
124
+ to = dateTimeString (fromValue , 1 , precision );
110
125
}
111
126
case INTEGER -> {
112
127
int fromValue = randomInt ();
@@ -143,7 +158,6 @@ public void testRangeQueryIntersectsAdjacentValues() throws Exception {
143
158
/**
144
159
* check that we catch cases where the user specifies larger "from" than "to" value, not counting the include upper/lower settings
145
160
*/
146
- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/86284" )
147
161
public void testFromLargerToErrors () throws Exception {
148
162
SearchExecutionContext context = createContext ();
149
163
RangeFieldType ft = createDefaultFieldType ();
@@ -159,8 +173,9 @@ public void testFromLargerToErrors() throws Exception {
159
173
}
160
174
case DATE : {
161
175
long fromValue = randomInt ();
162
- from = ZonedDateTime .ofInstant (Instant .ofEpochMilli (fromValue ), ZoneOffset .UTC );
163
- to = ZonedDateTime .ofInstant (Instant .ofEpochMilli (fromValue - 1 ), ZoneOffset .UTC );
176
+ var precision = randomFrom (ChronoUnit .MILLIS , ChronoUnit .SECONDS , ChronoUnit .MINUTES );
177
+ from = dateTimeString (fromValue , 0 , precision );
178
+ to = dateTimeString (fromValue , -1 , precision );
164
179
break ;
165
180
}
166
181
case INTEGER : {
0 commit comments