HBASE-14985 TimeRange constructors should set allTime when appropriate (Geoffrey Jacoby)
This commit is contained in:
parent
8964573394
commit
ff9c92e168
|
@ -36,8 +36,10 @@ import org.apache.hadoop.hbase.util.Bytes;
|
||||||
@InterfaceAudience.Public
|
@InterfaceAudience.Public
|
||||||
@InterfaceStability.Stable
|
@InterfaceStability.Stable
|
||||||
public class TimeRange {
|
public class TimeRange {
|
||||||
private long minStamp = 0L;
|
private static final long MIN_TIME = 0L;
|
||||||
private long maxStamp = Long.MAX_VALUE;
|
private static final long MAX_TIME = Long.MAX_VALUE;
|
||||||
|
private long minStamp = MIN_TIME;
|
||||||
|
private long maxStamp = MAX_TIME;
|
||||||
private boolean allTime = false;
|
private boolean allTime = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,6 +56,9 @@ public class TimeRange {
|
||||||
*/
|
*/
|
||||||
public TimeRange(long minStamp) {
|
public TimeRange(long minStamp) {
|
||||||
this.minStamp = minStamp;
|
this.minStamp = minStamp;
|
||||||
|
if (this.minStamp == MIN_TIME){
|
||||||
|
this.allTime = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,6 +85,9 @@ public class TimeRange {
|
||||||
}
|
}
|
||||||
this.minStamp = minStamp;
|
this.minStamp = minStamp;
|
||||||
this.maxStamp = maxStamp;
|
this.maxStamp = maxStamp;
|
||||||
|
if (this.minStamp == MIN_TIME && this.maxStamp == MAX_TIME){
|
||||||
|
this.allTime = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase.regionserver;
|
package org.apache.hadoop.hbase.regionserver;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.io.TimeRange;
|
import org.apache.hadoop.hbase.io.TimeRange;
|
||||||
|
@ -25,6 +27,8 @@ import org.apache.hadoop.hbase.testclassification.RegionServerTests;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
@Category({RegionServerTests.class, SmallTests.class})
|
@Category({RegionServerTests.class, SmallTests.class})
|
||||||
public class TestTimeRangeTracker {
|
public class TestTimeRangeTracker {
|
||||||
@Test
|
@Test
|
||||||
|
@ -81,6 +85,39 @@ public class TestTimeRangeTracker {
|
||||||
assertTrue(trr.getMinimumTimestamp() == 0);
|
assertTrue(trr.getMinimumTimestamp() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRangeConstruction() throws IOException {
|
||||||
|
TimeRange defaultRange = new TimeRange();
|
||||||
|
assertEquals(0L, defaultRange.getMin());
|
||||||
|
assertEquals(Long.MAX_VALUE, defaultRange.getMax());
|
||||||
|
assertTrue(defaultRange.isAllTime());
|
||||||
|
|
||||||
|
TimeRange oneArgRange = new TimeRange(0L);
|
||||||
|
assertEquals(0L, oneArgRange.getMin());
|
||||||
|
assertEquals(Long.MAX_VALUE, oneArgRange.getMax());
|
||||||
|
assertTrue(oneArgRange.isAllTime());
|
||||||
|
|
||||||
|
TimeRange oneArgRange2 = new TimeRange(1);
|
||||||
|
assertEquals(1, oneArgRange2.getMin());
|
||||||
|
assertEquals(Long.MAX_VALUE, oneArgRange2.getMax());
|
||||||
|
assertFalse(oneArgRange2.isAllTime());
|
||||||
|
|
||||||
|
TimeRange twoArgRange = new TimeRange(0L, Long.MAX_VALUE);
|
||||||
|
assertEquals(0L, twoArgRange.getMin());
|
||||||
|
assertEquals(Long.MAX_VALUE, twoArgRange.getMax());
|
||||||
|
assertTrue(twoArgRange.isAllTime());
|
||||||
|
|
||||||
|
TimeRange twoArgRange2 = new TimeRange(0L, Long.MAX_VALUE - 1);
|
||||||
|
assertEquals(0L, twoArgRange2.getMin());
|
||||||
|
assertEquals(Long.MAX_VALUE - 1, twoArgRange2.getMax());
|
||||||
|
assertFalse(twoArgRange2.isAllTime());
|
||||||
|
|
||||||
|
TimeRange twoArgRange3 = new TimeRange(1, Long.MAX_VALUE);
|
||||||
|
assertEquals(1, twoArgRange3.getMin());
|
||||||
|
assertEquals(Long.MAX_VALUE, twoArgRange3.getMax());
|
||||||
|
assertFalse(twoArgRange3.isAllTime());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bit of code to test concurrent access on this class.
|
* Bit of code to test concurrent access on this class.
|
||||||
* @param args
|
* @param args
|
||||||
|
|
Loading…
Reference in New Issue