|
27 | 27 | import org.elasticsearch.common.lucene.BytesRefs;
|
28 | 28 | import org.elasticsearch.common.unit.TimeValue;
|
29 | 29 | import org.elasticsearch.common.util.PageCacheRecycler;
|
| 30 | +import org.elasticsearch.script.JodaCompatibleZonedDateTime; |
30 | 31 | import org.elasticsearch.test.ESTestCase;
|
| 32 | +import org.joda.time.DateTime; |
31 | 33 | import org.joda.time.DateTimeZone;
|
32 | 34 |
|
33 | 35 | import java.io.EOFException;
|
34 | 36 | import java.io.IOException;
|
| 37 | +import java.time.ZoneId; |
35 | 38 | import java.util.ArrayList;
|
36 | 39 | import java.util.Collections;
|
37 | 40 | import java.util.HashMap;
|
|
49 | 52 | import static org.hamcrest.Matchers.endsWith;
|
50 | 53 | import static org.hamcrest.Matchers.equalTo;
|
51 | 54 | import static org.hamcrest.Matchers.hasSize;
|
| 55 | +import static org.hamcrest.Matchers.instanceOf; |
52 | 56 | import static org.hamcrest.Matchers.is;
|
53 | 57 | import static org.hamcrest.Matchers.nullValue;
|
54 | 58 |
|
@@ -303,6 +307,7 @@ public void testSimpleStreams() throws Exception {
|
303 | 307 | out.writeTimeZone(DateTimeZone.forID("CET"));
|
304 | 308 | out.writeOptionalTimeZone(DateTimeZone.getDefault());
|
305 | 309 | out.writeOptionalTimeZone(null);
|
| 310 | + out.writeGenericValue(new DateTime(123456, DateTimeZone.forID("America/Los_Angeles"))); |
306 | 311 | final byte[] bytes = BytesReference.toBytes(out.bytes());
|
307 | 312 | StreamInput in = StreamInput.wrap(BytesReference.toBytes(out.bytes()));
|
308 | 313 | assertEquals(in.available(), bytes.length);
|
@@ -335,6 +340,11 @@ public void testSimpleStreams() throws Exception {
|
335 | 340 | assertEquals(DateTimeZone.forID("CET"), in.readTimeZone());
|
336 | 341 | assertEquals(DateTimeZone.getDefault(), in.readOptionalTimeZone());
|
337 | 342 | assertNull(in.readOptionalTimeZone());
|
| 343 | + Object dt = in.readGenericValue(); |
| 344 | + assertThat(dt, instanceOf(JodaCompatibleZonedDateTime.class)); |
| 345 | + JodaCompatibleZonedDateTime jdt = (JodaCompatibleZonedDateTime) dt; |
| 346 | + assertThat(jdt.getZonedDateTime().toInstant().toEpochMilli(), equalTo(123456L)); |
| 347 | + assertThat(jdt.getZonedDateTime().getZone(), equalTo(ZoneId.of("America/Los_Angeles"))); |
338 | 348 | assertEquals(0, in.available());
|
339 | 349 | in.close();
|
340 | 350 | out.close();
|
|
0 commit comments