13
13
import static org .mockito .Mockito .when ;
14
14
15
15
import java .io .IOException ;
16
+ import java .time .ZoneOffset ;
17
+ import java .time .ZonedDateTime ;
18
+ import java .time .format .DateTimeFormatter ;
16
19
import java .util .Collections ;
17
20
import java .util .HashMap ;
18
21
import java .util .List ;
22
+ import java .util .Locale ;
19
23
import java .util .Map ;
20
24
import org .apache .lucene .search .TotalHits ;
21
- import org .joda .time .DateTime ;
22
- import org .joda .time .DateTimeZone ;
23
- import org .joda .time .format .DateTimeFormat ;
24
- import org .joda .time .format .DateTimeFormatter ;
25
25
import org .junit .Before ;
26
26
import org .opensearch .action .search .SearchRequest ;
27
27
import org .opensearch .action .search .SearchResponse ;
41
41
* Granular tests for the {@link LocalIndexReaderTests} class.
42
42
*/
43
43
public class LocalIndexReaderTests extends OpenSearchTestCase {
44
- private final DateTimeFormatter format = DateTimeFormat . forPattern ("YYYY.MM.dd" );
44
+ private final DateTimeFormatter format = DateTimeFormatter . ofPattern ("YYYY.MM.dd" , Locale . ROOT );
45
45
private final Client client = mock (Client .class );
46
46
private final NamedXContentRegistry namedXContentRegistry = mock (NamedXContentRegistry .class );
47
47
private LocalIndexReader localIndexReader ;
@@ -55,7 +55,7 @@ public void setup() {
55
55
public void testReadRecords () {
56
56
ActionFuture <SearchResponse > responseActionFuture = mock (ActionFuture .class );
57
57
Map <String , Object > sourceMap = new HashMap <>();
58
- sourceMap .put ("timestamp" , DateTime .now (DateTimeZone .UTC ).getMillis ());
58
+ sourceMap .put ("timestamp" , ZonedDateTime .now (ZoneOffset .UTC ).toInstant (). toEpochMilli ());
59
59
sourceMap .put ("indices" , Collections .singletonList ("my-index-0" ));
60
60
sourceMap .put ("source" , Map .of ());
61
61
sourceMap .put ("labels" , Map .of ());
@@ -83,7 +83,7 @@ public void testReadRecords() {
83
83
when (searchResponse .getHits ()).thenReturn (searchHits );
84
84
when (responseActionFuture .actionGet ()).thenReturn (searchResponse );
85
85
when (client .search (any (SearchRequest .class ))).thenReturn (responseActionFuture );
86
- String time = DateTime .now (DateTimeZone .UTC ).toString ( );
86
+ String time = ZonedDateTime .now (ZoneOffset .UTC ).format ( DateTimeFormatter . ISO_DATE_TIME );
87
87
List <SearchQueryRecord > records = List .of ();
88
88
try {
89
89
records = localIndexReader .read (time , time );
@@ -103,7 +103,7 @@ public void testClose() {
103
103
}
104
104
105
105
public void testGetAndSetIndexPattern () {
106
- DateTimeFormatter newFormatter = mock ( DateTimeFormatter .class );
106
+ final DateTimeFormatter newFormatter = DateTimeFormatter .ofPattern ( "YYYY-MM-dd" , Locale . ROOT );
107
107
localIndexReader .setIndexPattern (newFormatter );
108
108
assert (localIndexReader .getIndexPattern () == newFormatter );
109
109
}
0 commit comments