@Test
public void test() throws IOException {

    RegularTimeSeriesIndex index = RegularTimeSeriesIndex.create(Interval.parse("2015-01-01T00:00:00Z/2015-01-01T01:45:00Z"),
                                                                 Duration.ofMinutes(15));
    TimeSeriesMetadata metadata = new TimeSeriesMetadata("ts1", TimeSeriesDataType.DOUBLE, Collections.emptyMap(), index);
    UncompressedDoubleDataChunk chunk = new UncompressedDoubleDataChunk(2, new double[] {1d, 2d});
    CompressedDoubleDataChunk chunk2 = new CompressedDoubleDataChunk(5, 3, new double[] {3d, 4d}, new int[] {1, 2});
    assertEquals(TimeSeriesDataType.DOUBLE, chunk.getDataType());
    StoredDoubleTimeSeries timeSeries = new StoredDoubleTimeSeries(metadata, chunk, chunk2);
    assertSame(metadata, timeSeries.getMetadata());
    assertEquals(Arrays.asList(chunk, chunk2), timeSeries.getChunks());
    assertArrayEquals(new double[] {Double.NaN, Double.NaN, 1d, 2d, Double.NaN, 3d, 4d, 4d}, timeSeries.toArray(), 0d);
    DoublePoint[] pointsRef = {new DoublePoint(0, Instant.parse("2015-01-01T00:00:00Z").toEpochMilli(), Double.NaN),
                               new DoublePoint(2, Instant.parse("2015-01-01T00:30:00Z").toEpochMilli(), 1d),
                               new DoublePoint(3, Instant.parse("2015-01-01T00:45:00Z").toEpochMilli(), 2d),
                               new DoublePoint(4, Instant.parse("2015-01-01T01:00:00Z").toEpochMilli(), Double.NaN),
                               new DoublePoint(5, Instant.parse("2015-01-01T01:15:00Z").toEpochMilli(), 3d),
                               new DoublePoint(6, Instant.parse("2015-01-01T01:30:00Z").toEpochMilli(), 4d)};
    assertArrayEquals(pointsRef, timeSeries.stream().toArray());
    assertArrayEquals(pointsRef, Iterators.toArray(timeSeries.iterator(), DoublePoint.class));
    // json test
    String jsonRef = String.join(System.lineSeparator(),
            "{",
            "  \"metadata\" : {",
            "    \"name\" : \"ts1\",",
            "    \"dataType\" : \"DOUBLE\",",
            "    \"tags\" : [ ],",
            "    \"regularIndex\" : {",
            "      \"startTime\" : 1420070400000,",
            "      \"endTime\" : 1420076700000,",
            "      \"spacing\" : 900000",
            "    }",
            "  },",
            "  \"chunks\" : [ {",
            "    \"offset\" : 2,",
            "    \"values\" : [ 1.0, 2.0 ]",
            "  }, {",
            "    \"offset\" : 5,",
            "    \"uncompressedLength\" : 3,",
            "    \"stepValues\" : [ 3.0, 4.0 ],",
            "    \"stepLengths\" : [ 1, 2 ]",
            "  } ]",
            "}"
           );
    String json = JsonUtil.toJson(timeSeries::writeJson);
    assertEquals(jsonRef, json);
    List<TimeSeries> timeSeriesList = TimeSeries.parseJson(json);
    assertEquals(1, timeSeriesList.size());
    String json2 = JsonUtil.toJson(timeSeriesList.get(0)::writeJson);
    assertEquals(json, json2);
    // test json with object mapper
    ObjectMapper objectMapper = JsonUtil.createObjectMapper()
            .registerModule(new TimeSeriesJsonModule());
    assertEquals(timeSeries, objectMapper.readValue(objectMapper.writeValueAsString(timeSeries), DoubleTimeSeries.class));
}