Search in sources :

Example 1 with Dates

use of org.elasticsearch.index.fielddata.ScriptDocValues.Dates in project elasticsearch by elastic.

the class ScriptDocValuesDatesTests method test.

public void test() {
    long[][] values = new long[between(3, 10)][];
    ReadableDateTime[][] expectedDates = new ReadableDateTime[values.length][];
    for (int d = 0; d < values.length; d++) {
        values[d] = new long[randomBoolean() ? randomBoolean() ? 0 : 1 : between(2, 100)];
        expectedDates[d] = new ReadableDateTime[values[d].length];
        for (int i = 0; i < values[d].length; i++) {
            expectedDates[d][i] = new DateTime(randomNonNegativeLong(), DateTimeZone.UTC);
            values[d][i] = expectedDates[d][i].getMillis();
        }
    }
    Dates dates = wrap(values);
    for (int round = 0; round < 10; round++) {
        int d = between(0, values.length - 1);
        dates.setNextDocId(d);
        assertEquals(expectedDates[d].length > 0 ? expectedDates[d][0] : new DateTime(0, DateTimeZone.UTC), dates.getValue());
        assertEquals(values[d].length, dates.size());
        for (int i = 0; i < values[d].length; i++) {
            assertEquals(expectedDates[d][i], dates.get(i));
        }
        Exception e = expectThrows(UnsupportedOperationException.class, () -> dates.add(new DateTime()));
        assertEquals("doc values are unmodifiable", e.getMessage());
    }
}
Also used : ReadableDateTime(org.joda.time.ReadableDateTime) Dates(org.elasticsearch.index.fielddata.ScriptDocValues.Dates) ReadableDateTime(org.joda.time.ReadableDateTime) DateTime(org.joda.time.DateTime)

Aggregations

Dates (org.elasticsearch.index.fielddata.ScriptDocValues.Dates)1 DateTime (org.joda.time.DateTime)1 ReadableDateTime (org.joda.time.ReadableDateTime)1