@Test
  @Concurrent(count=4)
  @Repeating(repetition=100)
  public void testMaxSize() {
    // This many bytes are necessary to store the reversed nanoseconds.
    assertEquals(5, WritableUtils.getVIntSize(999999999));
    assertEquals(5, WritableUtils.getVIntSize(-2 - 999999999));

    // Bytes necessary to store extra bits of the second timestamp if storing a timestamp
    // before 1970 or after 2038.
    assertEquals(3, WritableUtils.getVIntSize(Short.MAX_VALUE));
    assertEquals(3, WritableUtils.getVIntSize(Short.MIN_VALUE));

    // Test that MAX_ADDITIONAL_SECONDS_BITS is really the maximum value of the
    // additional bits (beyond 31 bits) of the seconds-since-epoch part of timestamp.
    assertTrue((((long) MAX_ADDITIONAL_SECONDS_BITS) << 31) * 1000 < Long.MAX_VALUE);
    assertTrue((((double) MAX_ADDITIONAL_SECONDS_BITS + 1) * (1L << 31)) * 1000 >
      Long.MAX_VALUE);

    // This is how many bytes we need to store those additional bits as a VInt.
    assertEquals(4, WritableUtils.getVIntSize(MAX_ADDITIONAL_SECONDS_BITS));

    // Therefore, the maximum total size of a serialized timestamp is 4 + 5 + 4 = 13.
  }
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