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