You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zh...@apache.org on 2018/05/17 09:34:47 UTC
[07/36] hbase git commit: HBASE-20564 Tighter ByteBufferKeyValue Cell
Comparator; ADDENDUM2 Add a Test
HBASE-20564 Tighter ByteBufferKeyValue Cell Comparator; ADDENDUM2 Add a Test
Run meta tests but using our new basis, the ByteBufferKeyValue
instead of the old byte array-backed KeyValue so we catch any
oddness in the Type processing or in the Comparator.
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/f4006b50
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/f4006b50
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/f4006b50
Branch: refs/heads/HBASE-19064
Commit: f4006b5039170ca1ac8adb63abbc111184e2e9ee
Parents: 6148b47
Author: Michael Stack <st...@apache.org>
Authored: Wed May 16 11:01:21 2018 -0700
Committer: Michael Stack <st...@apache.org>
Committed: Wed May 16 12:56:08 2018 -0700
----------------------------------------------------------------------
.../apache/hadoop/hbase/TestCellComparator.java | 119 +++++++++++++++++++
1 file changed, 119 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/f4006b50/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java
index 8652d82..a318515 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java
@@ -21,6 +21,10 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.Set;
+import java.util.TreeSet;
+
import org.apache.hadoop.hbase.KeyValue.Type;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
@@ -128,4 +132,119 @@ public class TestCellComparator {
assertEquals(0, comparator.compareRows(bbCell2, bbCell3));
assertTrue(comparator.compareRows(bbCell1, bbCell2) < 0);
}
+
+ /**
+ * Test meta comparisons using our new ByteBufferKeyValue Cell type, the type we use everywhere
+ * in 2.0.
+ */
+ @Test
+ public void testMetaComparisons() throws Exception {
+ long now = System.currentTimeMillis();
+
+ // Meta compares
+ Cell aaa = createByteBufferKeyValueFromKeyValue(new KeyValue(
+ Bytes.toBytes("TestScanMultipleVersions,row_0500,1236020145502"), now));
+ Cell bbb = createByteBufferKeyValueFromKeyValue(new KeyValue(
+ Bytes.toBytes("TestScanMultipleVersions,,99999999999999"), now));
+ CellComparator c = CellComparatorImpl.META_COMPARATOR;
+ assertTrue(c.compare(bbb, aaa) < 0);
+
+ Cell ccc = createByteBufferKeyValueFromKeyValue(
+ new KeyValue(Bytes.toBytes("TestScanMultipleVersions,,1236023996656"),
+ Bytes.toBytes("info"), Bytes.toBytes("regioninfo"), 1236024396271L,
+ (byte[])null));
+ assertTrue(c.compare(ccc, bbb) < 0);
+
+ Cell x = createByteBufferKeyValueFromKeyValue(
+ new KeyValue(Bytes.toBytes("TestScanMultipleVersions,row_0500,1236034574162"),
+ Bytes.toBytes("info"), Bytes.toBytes(""), 9223372036854775807L,
+ (byte[])null));
+ Cell y = createByteBufferKeyValueFromKeyValue(
+ new KeyValue(Bytes.toBytes("TestScanMultipleVersions,row_0500,1236034574162"),
+ Bytes.toBytes("info"), Bytes.toBytes("regioninfo"), 1236034574912L,
+ (byte[])null));
+ assertTrue(c.compare(x, y) < 0);
+ }
+
+ private static Cell createByteBufferKeyValueFromKeyValue(KeyValue kv) {
+ ByteBuffer bb = ByteBuffer.wrap(kv.getBuffer());
+ return new ByteBufferKeyValue(bb, 0, bb.remaining());
+ }
+
+ /**
+ * More tests using ByteBufferKeyValue copied over from TestKeyValue which uses old KVs only.
+ */
+ @Test
+ public void testMetaComparisons2() {
+ long now = System.currentTimeMillis();
+ CellComparator c = CellComparatorImpl.META_COMPARATOR;
+ assertTrue(c.compare(createByteBufferKeyValueFromKeyValue(new KeyValue(
+ Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",a,,0,1"), now)),
+ createByteBufferKeyValueFromKeyValue(new KeyValue(
+ Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",a,,0,1"), now))) == 0);
+ Cell a = createByteBufferKeyValueFromKeyValue(new KeyValue(
+ Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",a,,0,1"), now));
+ Cell b = createByteBufferKeyValueFromKeyValue(new KeyValue(
+ Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",a,,0,2"), now));
+ assertTrue(c.compare(a, b) < 0);
+ assertTrue(c.compare(createByteBufferKeyValueFromKeyValue(new KeyValue(
+ Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",a,,0,2"), now)),
+ createByteBufferKeyValueFromKeyValue(new KeyValue(
+ Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",a,,0,1"), now))) > 0);
+ assertTrue(c.compare(createByteBufferKeyValueFromKeyValue(new KeyValue(
+ Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",,1"), now)),
+ createByteBufferKeyValueFromKeyValue(new KeyValue(
+ Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",,1"), now))) == 0);
+ assertTrue(c.compare(createByteBufferKeyValueFromKeyValue(new KeyValue(
+ Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",,1"), now)),
+ createByteBufferKeyValueFromKeyValue(new KeyValue(
+ Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",,2"), now))) < 0);
+ assertTrue(c.compare(createByteBufferKeyValueFromKeyValue(new KeyValue(
+ Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",,2"), now)),
+ createByteBufferKeyValueFromKeyValue(new KeyValue(
+ Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",,1"), now))) > 0);
+ }
+
+ @Test
+ public void testBinaryKeys() throws Exception {
+ Set<Cell> set = new TreeSet<>(CellComparatorImpl.COMPARATOR);
+ final byte [] fam = Bytes.toBytes("col");
+ final byte [] qf = Bytes.toBytes("umn");
+ final byte [] nb = new byte[0];
+ Cell [] keys = {
+ createByteBufferKeyValueFromKeyValue(
+ new KeyValue(Bytes.toBytes("aaaaa,\u0000\u0000,2"), fam, qf, 2, nb)),
+ createByteBufferKeyValueFromKeyValue(
+ new KeyValue(Bytes.toBytes("aaaaa,\u0001,3"), fam, qf, 3, nb)),
+ createByteBufferKeyValueFromKeyValue(
+ new KeyValue(Bytes.toBytes("aaaaa,,1"), fam, qf, 1, nb)),
+ createByteBufferKeyValueFromKeyValue(
+ new KeyValue(Bytes.toBytes("aaaaa,\u1000,5"), fam, qf, 5, nb)),
+ createByteBufferKeyValueFromKeyValue(
+ new KeyValue(Bytes.toBytes("aaaaa,a,4"), fam, qf, 4, nb)),
+ createByteBufferKeyValueFromKeyValue(
+ new KeyValue(Bytes.toBytes("a,a,0"), fam, qf, 0, nb)),
+ };
+ // Add to set with bad comparator
+ Collections.addAll(set, keys);
+ // This will output the keys incorrectly.
+ boolean assertion = false;
+ int count = 0;
+ try {
+ for (Cell k: set) {
+ assertTrue("count=" + count + ", " + k.toString(), count++ == k.getTimestamp());
+ }
+ } catch (AssertionError e) {
+ // Expected
+ assertion = true;
+ }
+ assertTrue(assertion);
+ // Make set with good comparator
+ set = new TreeSet<>(CellComparatorImpl.META_COMPARATOR);
+ Collections.addAll(set, keys);
+ count = 0;
+ for (Cell k: set) {
+ assertTrue("count=" + count + ", " + k.toString(), count++ == k.getTimestamp());
+ }
+ }
}