@Test
  @Concurrent(count=4)
  public void testToFromDouble() {
    Random rand = new Random(294729777L);
    for (int nanosPrecision = 0; nanosPrecision <= 4; ++nanosPrecision) {
      for (int i = 0; i < 10000; ++i) {
        long millis = randomMillis(MIN_FOUR_DIGIT_YEAR_MILLIS, MAX_FOUR_DIGIT_YEAR_MILLIS, rand);
        int nanos = randomNanos(rand, nanosPrecision);
        Timestamp ts = Timestamp.ofEpochMilli(millis, nanos);
        TimestampWritableV2 tsw = new TimestampWritableV2(ts);
        double asDouble = tsw.getDouble();
        int recoveredNanos =
          (int) (Math.round((asDouble - Math.floor(asDouble)) * Math.pow(10, nanosPrecision)) *
            Math.pow(10, 9 - nanosPrecision));
        assertEquals(String.format("Invalid nanosecond part recovered from %f", asDouble),
          nanos, recoveredNanos);
        assertEquals(ts, TimestampUtils.doubleToTimestamp(asDouble));
        // decimalToTimestamp should be consistent with doubleToTimestamp for this level of
        // precision.
        assertEquals(ts, TimestampUtils.decimalToTimestamp(
            HiveDecimal.create(BigDecimal.valueOf(asDouble))));
      }
    }
  }
Test timestamps that don't necessarily fit between 1970 and 2038. This depends on HIVE-4525
being fixed.
serde/src/test/org/apache/hadoop/hive/serde2/io/TestTimestampWritableV2.java