HBASE-20136 TestKeyValue misses ClassRule and Category annotations

This commit is contained in:
tedyu 2018-03-06 08:34:49 -08:00
parent 1384da7137
commit b7fb2df154
1 changed files with 38 additions and 9 deletions

View File

@ -18,7 +18,11 @@
*/ */
package org.apache.hadoop.hbase; package org.apache.hadoop.hbase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -31,16 +35,23 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.ByteBufferUtils; import org.apache.hadoop.hbase.util.ByteBufferUtils;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import junit.framework.TestCase; @Category(SmallTests.class)
public class TestKeyValue {
public class TestKeyValue extends TestCase { @ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestKeyValue.class);
private static final Logger LOG = LoggerFactory.getLogger(TestKeyValue.class); private static final Logger LOG = LoggerFactory.getLogger(TestKeyValue.class);
@Test
public void testColumnCompare() throws Exception { public void testColumnCompare() throws Exception {
final byte [] a = Bytes.toBytes("aaa"); final byte [] a = Bytes.toBytes("aaa");
byte [] family1 = Bytes.toBytes("abc"); byte [] family1 = Bytes.toBytes("abc");
@ -64,6 +75,7 @@ public class TestKeyValue extends TestCase {
* Test a corner case when the family qualifier is a prefix of the * Test a corner case when the family qualifier is a prefix of the
* column qualifier. * column qualifier.
*/ */
@Test
public void testColumnCompare_prefix() throws Exception { public void testColumnCompare_prefix() throws Exception {
final byte [] a = Bytes.toBytes("aaa"); final byte [] a = Bytes.toBytes("aaa");
byte [] family1 = Bytes.toBytes("abc"); byte [] family1 = Bytes.toBytes("abc");
@ -75,14 +87,16 @@ public class TestKeyValue extends TestCase {
assertFalse(CellUtil.matchingColumn(aaa, family2, qualifier2)); assertFalse(CellUtil.matchingColumn(aaa, family2, qualifier2));
} }
@Test
public void testBasics() throws Exception { public void testBasics() throws Exception {
LOG.info("LOWKEY: " + KeyValue.LOWESTKEY.toString()); LOG.info("LOWKEY: " + KeyValue.LOWESTKEY.toString());
check(Bytes.toBytes(getName()), String name = "testBasics";
Bytes.toBytes(getName()), Bytes.toBytes(getName()), 1, check(Bytes.toBytes(name),
Bytes.toBytes(getName())); Bytes.toBytes(name), Bytes.toBytes(name), 1,
Bytes.toBytes(name));
// Test empty value and empty column -- both should work. (not empty fam) // Test empty value and empty column -- both should work. (not empty fam)
check(Bytes.toBytes(getName()), Bytes.toBytes(getName()), null, 1, null); check(Bytes.toBytes(name), Bytes.toBytes(name), null, 1, null);
check(HConstants.EMPTY_BYTE_ARRAY, Bytes.toBytes(getName()), null, 1, null); check(HConstants.EMPTY_BYTE_ARRAY, Bytes.toBytes(name), null, 1, null);
// empty qual is equivalent to null qual // empty qual is equivalent to null qual
assertEquals( assertEquals(
new KeyValue(Bytes.toBytes("rk"), Bytes.toBytes("fam"), null, 1, (byte[]) null), new KeyValue(Bytes.toBytes("rk"), Bytes.toBytes("fam"), null, 1, (byte[]) null),
@ -100,6 +114,7 @@ public class TestKeyValue extends TestCase {
LOG.info(kv.toString()); LOG.info(kv.toString());
} }
@Test
public void testPlainCompare() throws Exception { public void testPlainCompare() throws Exception {
final byte [] a = Bytes.toBytes("aaa"); final byte [] a = Bytes.toBytes("aaa");
final byte [] b = Bytes.toBytes("bbb"); final byte [] b = Bytes.toBytes("bbb");
@ -127,6 +142,7 @@ public class TestKeyValue extends TestCase {
assertTrue(CellComparatorImpl.COMPARATOR.compare(aaa, aaa) == 0); assertTrue(CellComparatorImpl.COMPARATOR.compare(aaa, aaa) == 0);
} }
@Test
public void testMoreComparisons() throws Exception { public void testMoreComparisons() throws Exception {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
@ -155,6 +171,7 @@ public class TestKeyValue extends TestCase {
metacomparisons(CellComparatorImpl.META_COMPARATOR); metacomparisons(CellComparatorImpl.META_COMPARATOR);
} }
@Test
public void testMetaComparatorTableKeysWithCommaOk() { public void testMetaComparatorTableKeysWithCommaOk() {
CellComparator c = CellComparatorImpl.META_COMPARATOR; CellComparator c = CellComparatorImpl.META_COMPARATOR;
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
@ -170,6 +187,7 @@ public class TestKeyValue extends TestCase {
* See HBASE-832 * See HBASE-832
* @throws IOException * @throws IOException
*/ */
@Test
public void testKeyValueBorderCases() throws IOException { public void testKeyValueBorderCases() throws IOException {
// % sorts before , so if we don't do special comparator, rowB would // % sorts before , so if we don't do special comparator, rowB would
// come before rowA. // come before rowA.
@ -220,6 +238,7 @@ public class TestKeyValue extends TestCase {
Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",,1"), now)) > 0); Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",,1"), now)) > 0);
} }
@Test
public void testBinaryKeys() throws Exception { public void testBinaryKeys() throws Exception {
Set<KeyValue> set = new TreeSet<>(CellComparatorImpl.COMPARATOR); Set<KeyValue> set = new TreeSet<>(CellComparatorImpl.COMPARATOR);
final byte [] fam = Bytes.toBytes("col"); final byte [] fam = Bytes.toBytes("col");
@ -241,7 +260,7 @@ public class TestKeyValue extends TestCase {
for (KeyValue k: set) { for (KeyValue k: set) {
assertTrue(count++ == k.getTimestamp()); assertTrue(count++ == k.getTimestamp());
} }
} catch (junit.framework.AssertionFailedError e) { } catch (java.lang.AssertionError e) {
// Expected // Expected
assertion = true; assertion = true;
} }
@ -255,6 +274,7 @@ public class TestKeyValue extends TestCase {
} }
} }
@Test
public void testStackedUpKeyValue() { public void testStackedUpKeyValue() {
// Test multiple KeyValues in a single blob. // Test multiple KeyValues in a single blob.
@ -286,6 +306,7 @@ public class TestKeyValue extends TestCase {
assertTrue(cmp > 0); assertTrue(cmp > 0);
} }
@Test
public void testCompareWithoutRow() { public void testCompareWithoutRow() {
final CellComparator c = CellComparatorImpl.COMPARATOR; final CellComparator c = CellComparatorImpl.COMPARATOR;
byte[] row = Bytes.toBytes("row"); byte[] row = Bytes.toBytes("row");
@ -333,6 +354,7 @@ public class TestKeyValue extends TestCase {
assertKVLessWithoutRow(c, commonLength + 6, kv0_1, kv0_2); assertKVLessWithoutRow(c, commonLength + 6, kv0_1, kv0_2);
} }
@Test
public void testFirstLastOnRow() { public void testFirstLastOnRow() {
final CellComparator c = CellComparatorImpl.COMPARATOR; final CellComparator c = CellComparatorImpl.COMPARATOR;
long ts = 1; long ts = 1;
@ -379,6 +401,7 @@ public class TestKeyValue extends TestCase {
assertKVLess(c, firstOnRowABufferFamQual, lastOnRowA); assertKVLess(c, firstOnRowABufferFamQual, lastOnRowA);
} }
@Test
public void testCreateKeyOnly() throws Exception { public void testCreateKeyOnly() throws Exception {
long ts = 1; long ts = 1;
byte [] value = Bytes.toBytes("a real value"); byte [] value = Bytes.toBytes("a real value");
@ -400,6 +423,7 @@ public class TestKeyValue extends TestCase {
} }
} }
@Test
public void testCreateKeyValueFromKey() { public void testCreateKeyValueFromKey() {
KeyValue kv = new KeyValue(Bytes.toBytes("myRow"), Bytes.toBytes("myCF"), KeyValue kv = new KeyValue(Bytes.toBytes("myRow"), Bytes.toBytes("myCF"),
Bytes.toBytes("myQualifier"), 12345L, Bytes.toBytes("myValue")); Bytes.toBytes("myQualifier"), 12345L, Bytes.toBytes("myValue"));
@ -423,6 +447,7 @@ public class TestKeyValue extends TestCase {
* Tests that getTimestamp() does always return the proper timestamp, even after updating it. * Tests that getTimestamp() does always return the proper timestamp, even after updating it.
* See HBASE-6265. * See HBASE-6265.
*/ */
@Test
public void testGetTimestamp() { public void testGetTimestamp() {
KeyValue kv = new KeyValue(Bytes.toBytes("myRow"), Bytes.toBytes("myCF"), KeyValue kv = new KeyValue(Bytes.toBytes("myRow"), Bytes.toBytes("myCF"),
Bytes.toBytes("myQualifier"), HConstants.LATEST_TIMESTAMP, Bytes.toBytes("myQualifier"), HConstants.LATEST_TIMESTAMP,
@ -434,6 +459,7 @@ public class TestKeyValue extends TestCase {
assertEquals(12345L, time2); assertEquals(12345L, time2);
} }
@Test
public void testKVsWithTags() { public void testKVsWithTags() {
byte[] row = Bytes.toBytes("myRow"); byte[] row = Bytes.toBytes("myRow");
byte[] cf = Bytes.toBytes("myCF"); byte[] cf = Bytes.toBytes("myCF");
@ -497,6 +523,7 @@ public class TestKeyValue extends TestCase {
assertFalse(tagItr.hasNext()); assertFalse(tagItr.hasNext());
} }
@Test
public void testMetaKeyComparator() { public void testMetaKeyComparator() {
CellComparator c = CellComparatorImpl.META_COMPARATOR; CellComparator c = CellComparatorImpl.META_COMPARATOR;
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
@ -542,6 +569,7 @@ public class TestKeyValue extends TestCase {
assertTrue(c.compare(a, b) < 0); assertTrue(c.compare(a, b) < 0);
} }
@Test
public void testEqualsAndHashCode() throws Exception { public void testEqualsAndHashCode() throws Exception {
KeyValue kvA1 = new KeyValue(Bytes.toBytes("key"), Bytes.toBytes("cf"), KeyValue kvA1 = new KeyValue(Bytes.toBytes("key"), Bytes.toBytes("cf"),
Bytes.toBytes("qualA"), Bytes.toBytes("1")); Bytes.toBytes("qualA"), Bytes.toBytes("1"));
@ -560,6 +588,7 @@ public class TestKeyValue extends TestCase {
} }
@Test
public void testKeyValueSerialization() throws Exception { public void testKeyValueSerialization() throws Exception {
KeyValue kvA1 = new KeyValue(Bytes.toBytes("key"), Bytes.toBytes("cf"), Bytes.toBytes("qualA"), KeyValue kvA1 = new KeyValue(Bytes.toBytes("key"), Bytes.toBytes("cf"), Bytes.toBytes("qualA"),
Bytes.toBytes("1")); Bytes.toBytes("1"));