You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ap...@apache.org on 2017/08/01 20:26:30 UTC

hbase git commit: HBASE-14070 Fix TestTimestampType#testPhysicalIsLikelyOfType and testHybridIsLikelyOfType

Repository: hbase
Updated Branches:
  refs/heads/HBASE-14070.HLC 45bb4f0a5 -> 0f52f68de


HBASE-14070 Fix TestTimestampType#testPhysicalIsLikelyOfType and testHybridIsLikelyOfType

-Offset date by second day of year
-Fixed instance of not properly setting ZonedDateTime in TestTimestampType#testPhysicalIsLikelyOfType
-Changed timestamp for year 2016 in TimestampType to be UTC+0 instead of UTC+8


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/0f52f68d
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/0f52f68d
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/0f52f68d

Branch: refs/heads/HBASE-14070.HLC
Commit: 0f52f68de18083ff436596ded1654f4710bb0343
Parents: 45bb4f0
Author: Amit Patel <ia...@gmail.com>
Authored: Tue Aug 1 11:54:52 2017 -0700
Committer: Apekshit Sharma <ap...@apache.org>
Committed: Tue Aug 1 13:24:34 2017 -0700

----------------------------------------------------------------------
 .../java/org/apache/hadoop/hbase/TimestampType.java  |  4 ++--
 .../org/apache/hadoop/hbase/TestTimestampType.java   | 15 +++++++++++----
 2 files changed, 13 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/0f52f68d/hbase-common/src/main/java/org/apache/hadoop/hbase/TimestampType.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/TimestampType.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/TimestampType.java
index e2e2604..2f0a229 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/TimestampType.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/TimestampType.java
@@ -149,8 +149,8 @@ public enum TimestampType {
       final long physicalTime = getPhysicalTime(timestamp);
       final long logicalTime = getLogicalTime(timestamp);
 
-      // heuristic 1: Up until year 2016 (1451635200000), lt component cannot be non-zero.
-      if (physicalTime < 1451635200000L && logicalTime != 0) {
+      // heuristic 1: Up until year 2016 (1451606400000), lt component cannot be non-zero.
+      if (physicalTime < 1451606400000L && logicalTime != 0) {
         return false;
       } else if (physicalTime < 31536000000L) {
         // heuristic 2: Even if logical time = 0, physical time after left shifting by 20 bits,

http://git-wip-us.apache.org/repos/asf/hbase/blob/0f52f68d/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimestampType.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimestampType.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimestampType.java
index b1a661b..8b7d83f 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimestampType.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimestampType.java
@@ -117,7 +117,10 @@ public class TestTimestampType {
 
     // test timestamps of Hybrid type from year 2016 to 2348 where lt > 0
     for (int year = 2016; year <= 2248; year += 1) {
-      date = date.withYear(year);
+      // Timestamps from first half of the first day of 1970 fail the HYBRID#isLikelyOfType check
+      // since the result after converting to a hybrid timestamp is very small so we offset by the
+      // second day
+      date = date.withDayOfYear(2).withYear(year);
 
       // Hybrid type ts with pt = date and lt = 123
       long ts = TimestampType.HYBRID.toTimestamp(TimeUnit.SECONDS, date.toEpochSecond(), 123);
@@ -182,12 +185,13 @@ public class TestTimestampType {
 
   @Test
   public void testPhysicalIsLikelyOfType() throws ParseException {
-    final ZonedDateTime date = LocalDateTime.of(1970, 1, 1, 1, 1).atZone(ZoneId.of("UTC"));
+    ZonedDateTime date = LocalDateTime.of(1970, 1, 1, 1, 1).atZone(ZoneId.of("UTC"));
 
     // test that timestamps from 1970 to 3K epoch are of Physical type
     for (int year = 1970; year < 3000 ;year += 10) {
       // Start date 1970 to 10000
-      date.withYear(year);
+      date = date.withYear(year);
+
       final long ts = date.toEpochSecond() * 1000;
       assertTrue("Year = " + year, TimestampType.PHYSICAL.isLikelyOfType(ts));
     }
@@ -198,7 +202,10 @@ public class TestTimestampType {
 
     // test timestamps of Hybrid type from year 1970 to 2248 are not of Physical type
     for (int year = 1970; year <= 2248; year += 1) {
-      date.withYear(year);
+      // Timestamps from first half of the first day of 1970 fail the HYBRID#isLikelyOfType check
+      // since the result after converting to a hybrid timestamp is very small so we offset by the
+      // second day
+      date = date.withDayOfYear(2).withYear(year);
       // Hybrid type ts with pt = date and lt = 0
       long ts = TimestampType.HYBRID.toTimestamp(TimeUnit.SECONDS, date.toEpochSecond(), 0);
       assertFalse(TimestampType.PHYSICAL.isLikelyOfType(ts));