@Test
  @Concurrent(count=4)
  @Repeating(repetition=100)
  public void testBinarySortable() {
    Random rand = new Random(5972977L);
    List<TimestampWritableV2> tswList = new ArrayList<TimestampWritableV2>();
    for (int i = 0; i < 50; ++i) {
      Timestamp ts = Timestamp.ofEpochMilli(rand.nextLong(), randomNanos(rand));
      tswList.add(new TimestampWritableV2(ts));
    }
    for (TimestampWritableV2 tsw1 : tswList) {
      byte[] bs1 = tsw1.getBinarySortable();
      for (TimestampWritableV2 tsw2 : tswList) {
        byte[] bs2 = tsw2.getBinarySortable();
        int binaryComparisonResult =
          normalizeComparisonResult(compareEqualLengthByteArrays(bs1, bs2));
        int comparisonResult = normalizeComparisonResult(tsw1.compareTo(tsw2));
        if (binaryComparisonResult != comparisonResult) {
          throw new AssertionError("TimestampWritables " + tsw1 + " and " + tsw2 + " compare as " +
            comparisonResult + " using compareTo but as " + binaryComparisonResult + " using " +
            "getBinarySortable");
        }
      }
    }
  }
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