HBASE-26709 Ban the usage of junit 3 TestCase (#4065)

Signed-off-by: Nick Dimiduk <ndimiduk@apache.org>
This commit is contained in:
Duo Zhang 2022-01-27 13:41:48 +08:00
parent cbbb1a0542
commit d747da6985
15 changed files with 211 additions and 113 deletions

View File

@ -18,6 +18,13 @@
package org.apache.hadoop.hbase.util; package org.apache.hadoop.hbase.util;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
@ -31,17 +38,17 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import junit.framework.TestCase;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.io.WritableUtils; import org.apache.hadoop.io.WritableUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
@Category({MiscTests.class, MediumTests.class}) @Category({MiscTests.class, MediumTests.class})
public class TestBytes extends TestCase { public class TestBytes {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestBytes.class); HBaseClassTestRule.forClass(TestBytes.class);
@ -61,10 +68,12 @@ public class TestBytes extends TestCase {
assertEquals(Bytes.UNSAFE_UNALIGNED, value); assertEquals(Bytes.UNSAFE_UNALIGNED, value);
} }
@Test
public void testShort() throws Exception { public void testShort() throws Exception {
testShort(false); testShort(false);
} }
@Test
public void testShortUnsafe() throws Exception { public void testShortUnsafe() throws Exception {
testShort(true); testShort(true);
} }
@ -88,6 +97,7 @@ public class TestBytes extends TestCase {
} }
} }
@Test
public void testNullHashCode() { public void testNullHashCode() {
byte [] b = null; byte [] b = null;
Exception ee = null; Exception ee = null;
@ -99,6 +109,7 @@ public class TestBytes extends TestCase {
assertNotNull(ee); assertNotNull(ee);
} }
@Test
public void testAdd() { public void testAdd() {
byte[] a = {0,0,0,0,0,0,0,0,0,0}; byte[] a = {0,0,0,0,0,0,0,0,0,0};
byte[] b = {1,1,1,1,1,1,1,1,1,1,1}; byte[] b = {1,1,1,1,1,1,1,1,1,1,1};
@ -112,6 +123,7 @@ public class TestBytes extends TestCase {
assertEquals(0, Bytes.compareTo(result1, result2)); assertEquals(0, Bytes.compareTo(result1, result2));
} }
@Test
public void testSplit() { public void testSplit() {
byte[] lowest = Bytes.toBytes("AAA"); byte[] lowest = Bytes.toBytes("AAA");
byte[] middle = Bytes.toBytes("CCC"); byte[] middle = Bytes.toBytes("CCC");
@ -133,6 +145,7 @@ public class TestBytes extends TestCase {
assertTrue(Bytes.equals(parts[2], middle)); assertTrue(Bytes.equals(parts[2], middle));
} }
@Test
public void testSplit2() { public void testSplit2() {
// More split tests. // More split tests.
byte [] lowest = Bytes.toBytes("http://A"); byte [] lowest = Bytes.toBytes("http://A");
@ -146,6 +159,7 @@ public class TestBytes extends TestCase {
assertTrue(Bytes.equals(parts[1], middle)); assertTrue(Bytes.equals(parts[1], middle));
} }
@Test
public void testSplit3() { public void testSplit3() {
// Test invalid split cases // Test invalid split cases
byte[] low = { 1, 1, 1 }; byte[] low = { 1, 1, 1 };
@ -180,6 +194,7 @@ public class TestBytes extends TestCase {
} }
} }
@Test
public void testToInt() { public void testToInt() {
int[] ints = { -1, 123, Integer.MIN_VALUE, Integer.MAX_VALUE }; int[] ints = { -1, 123, Integer.MIN_VALUE, Integer.MAX_VALUE };
for (int anInt : ints) { for (int anInt : ints) {
@ -191,6 +206,7 @@ public class TestBytes extends TestCase {
} }
} }
@Test
public void testToLong() { public void testToLong() {
long[] longs = { -1L, 123L, Long.MIN_VALUE, Long.MAX_VALUE }; long[] longs = { -1L, 123L, Long.MIN_VALUE, Long.MAX_VALUE };
for (long aLong : longs) { for (long aLong : longs) {
@ -202,6 +218,7 @@ public class TestBytes extends TestCase {
} }
} }
@Test
public void testToFloat() { public void testToFloat() {
float[] floats = { -1f, 123.123f, Float.MAX_VALUE }; float[] floats = { -1f, 123.123f, Float.MAX_VALUE };
for (float aFloat : floats) { for (float aFloat : floats) {
@ -212,6 +229,7 @@ public class TestBytes extends TestCase {
} }
} }
@Test
public void testToDouble() { public void testToDouble() {
double [] doubles = {Double.MIN_VALUE, Double.MAX_VALUE}; double [] doubles = {Double.MIN_VALUE, Double.MAX_VALUE};
for (double aDouble : doubles) { for (double aDouble : doubles) {
@ -222,6 +240,7 @@ public class TestBytes extends TestCase {
} }
} }
@Test
public void testToBigDecimal() { public void testToBigDecimal() {
BigDecimal[] decimals = { new BigDecimal("-1"), new BigDecimal("123.123"), BigDecimal[] decimals = { new BigDecimal("-1"), new BigDecimal("123.123"),
new BigDecimal("123123123123") }; new BigDecimal("123123123123") };
@ -241,6 +260,7 @@ public class TestBytes extends TestCase {
return result; return result;
} }
@Test
public void testToBytesForByteBuffer() { public void testToBytesForByteBuffer() {
byte[] array = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; byte[] array = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
ByteBuffer target = ByteBuffer.wrap(array); ByteBuffer target = ByteBuffer.wrap(array);
@ -264,6 +284,7 @@ public class TestBytes extends TestCase {
assertEquals(5, target2.limit()); assertEquals(5, target2.limit());
} }
@Test
public void testGetBytesForByteBuffer() { public void testGetBytesForByteBuffer() {
byte[] array = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; byte[] array = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
ByteBuffer target = ByteBuffer.wrap(array); ByteBuffer target = ByteBuffer.wrap(array);
@ -277,6 +298,7 @@ public class TestBytes extends TestCase {
assertEquals(7, target.limit()); assertEquals(7, target.limit());
} }
@Test
public void testReadAsVLong() throws Exception { public void testReadAsVLong() throws Exception {
long[] longs = { -1L, 123L, Long.MIN_VALUE, Long.MAX_VALUE }; long[] longs = { -1L, 123L, Long.MIN_VALUE, Long.MAX_VALUE };
for (long aLong : longs) { for (long aLong : longs) {
@ -290,6 +312,7 @@ public class TestBytes extends TestCase {
} }
} }
@Test
public void testToStringBinaryForBytes() { public void testToStringBinaryForBytes() {
byte[] array = { '0', '9', 'a', 'z', 'A', 'Z', '@', 1 }; byte[] array = { '0', '9', 'a', 'z', 'A', 'Z', '@', 1 };
String actual = Bytes.toStringBinary(array); String actual = Bytes.toStringBinary(array);
@ -301,6 +324,7 @@ public class TestBytes extends TestCase {
assertEquals(expected2, actual2); assertEquals(expected2, actual2);
} }
@Test
public void testToStringBinaryForArrayBasedByteBuffer() { public void testToStringBinaryForArrayBasedByteBuffer() {
byte[] array = { '0', '9', 'a', 'z', 'A', 'Z', '@', 1 }; byte[] array = { '0', '9', 'a', 'z', 'A', 'Z', '@', 1 };
ByteBuffer target = ByteBuffer.wrap(array); ByteBuffer target = ByteBuffer.wrap(array);
@ -309,6 +333,7 @@ public class TestBytes extends TestCase {
assertEquals(expected, actual); assertEquals(expected, actual);
} }
@Test
public void testToStringBinaryForReadOnlyByteBuffer() { public void testToStringBinaryForReadOnlyByteBuffer() {
byte[] array = { '0', '9', 'a', 'z', 'A', 'Z', '@', 1 }; byte[] array = { '0', '9', 'a', 'z', 'A', 'Z', '@', 1 };
ByteBuffer target = ByteBuffer.wrap(array).asReadOnlyBuffer(); ByteBuffer target = ByteBuffer.wrap(array).asReadOnlyBuffer();
@ -317,6 +342,7 @@ public class TestBytes extends TestCase {
assertEquals(expected, actual); assertEquals(expected, actual);
} }
@Test
public void testBinarySearch() { public void testBinarySearch() {
byte[][] arr = { byte[][] arr = {
{ 1 }, { 1 },
@ -357,6 +383,7 @@ public class TestBytes extends TestCase {
} }
} }
@Test
public void testToStringBytesBinaryReversible() { public void testToStringBytesBinaryReversible() {
// let's run test with 1000 randomly generated byte arrays // let's run test with 1000 randomly generated byte arrays
Random rand = new Random(EnvironmentEdgeManager.currentTime()); Random rand = new Random(EnvironmentEdgeManager.currentTime());
@ -381,6 +408,7 @@ public class TestBytes extends TestCase {
} }
} }
@Test
public void testStartsWith() { public void testStartsWith() {
assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("h"))); assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("h")));
assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes(""))); assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("")));
@ -389,6 +417,7 @@ public class TestBytes extends TestCase {
assertFalse(Bytes.startsWith(Bytes.toBytes(""), Bytes.toBytes("hello"))); assertFalse(Bytes.startsWith(Bytes.toBytes(""), Bytes.toBytes("hello")));
} }
@Test
public void testIncrementBytes() { public void testIncrementBytes() {
assertTrue(checkTestIncrementBytes(10, 1)); assertTrue(checkTestIncrementBytes(10, 1));
assertTrue(checkTestIncrementBytes(12, 123435445)); assertTrue(checkTestIncrementBytes(12, 123435445));
@ -423,6 +452,7 @@ public class TestBytes extends TestCase {
return (Bytes.toLong(testValue) + amount) == incrementResult; return (Bytes.toLong(testValue) + amount) == incrementResult;
} }
@Test
public void testFixedSizeString() throws IOException { public void testFixedSizeString() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos); DataOutputStream dos = new DataOutputStream(baos);
@ -448,6 +478,7 @@ public class TestBytes extends TestCase {
assertEquals("", Bytes.readStringFixedSize(dis, 9)); assertEquals("", Bytes.readStringFixedSize(dis, 9));
} }
@Test
public void testCopy() { public void testCopy() {
byte[] bytes = Bytes.toBytes("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); byte[] bytes = Bytes.toBytes("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
byte[] copy = Bytes.copy(bytes); byte[] copy = Bytes.copy(bytes);
@ -455,6 +486,7 @@ public class TestBytes extends TestCase {
assertTrue(Bytes.equals(bytes, copy)); assertTrue(Bytes.equals(bytes, copy));
} }
@Test
public void testToBytesBinaryTrailingBackslashes() { public void testToBytesBinaryTrailingBackslashes() {
try { try {
Bytes.toBytesBinary("abc\\x00\\x01\\"); Bytes.toBytesBinary("abc\\x00\\x01\\");
@ -463,11 +495,13 @@ public class TestBytes extends TestCase {
} }
} }
@Test
public void testToStringBinary_toBytesBinary_Reversable() { public void testToStringBinary_toBytesBinary_Reversable() {
String bytes = Bytes.toStringBinary(Bytes.toBytes(2.17)); String bytes = Bytes.toStringBinary(Bytes.toBytes(2.17));
assertEquals(2.17, Bytes.toDouble(Bytes.toBytesBinary(bytes)), 0); assertEquals(2.17, Bytes.toDouble(Bytes.toBytesBinary(bytes)), 0);
} }
@Test
public void testUnsignedBinarySearch(){ public void testUnsignedBinarySearch(){
byte[] bytes = new byte[] { 0,5,123,127,-128,-100,-1 }; byte[] bytes = new byte[] { 0,5,123,127,-128,-100,-1 };
Assert.assertEquals(1, Bytes.unsignedBinarySearch(bytes, 0, bytes.length, (byte)5)); Assert.assertEquals(1, Bytes.unsignedBinarySearch(bytes, 0, bytes.length, (byte)5));
@ -479,6 +513,7 @@ public class TestBytes extends TestCase {
Assert.assertEquals(-6-1, Bytes.unsignedBinarySearch(bytes, 0, bytes.length, (byte)-5)); Assert.assertEquals(-6-1, Bytes.unsignedBinarySearch(bytes, 0, bytes.length, (byte)-5));
} }
@Test
public void testUnsignedIncrement(){ public void testUnsignedIncrement(){
byte[] a = Bytes.toBytes(0); byte[] a = Bytes.toBytes(0);
int a2 = Bytes.toInt(Bytes.unsignedCopyAndIncrement(a), 0); int a2 = Bytes.toInt(Bytes.unsignedCopyAndIncrement(a), 0);
@ -495,6 +530,7 @@ public class TestBytes extends TestCase {
Assert.assertEquals(256, c2); Assert.assertEquals(256, c2);
} }
@Test
public void testIndexOf() { public void testIndexOf() {
byte[] array = Bytes.toBytes("hello"); byte[] array = Bytes.toBytes("hello");
assertEquals(1, Bytes.indexOf(array, (byte) 'e')); assertEquals(1, Bytes.indexOf(array, (byte) 'e'));
@ -505,6 +541,7 @@ public class TestBytes extends TestCase {
assertEquals(-1, Bytes.indexOf(array, Bytes.toBytes("hll"))); assertEquals(-1, Bytes.indexOf(array, Bytes.toBytes("hll")));
} }
@Test
public void testContains() { public void testContains() {
byte[] array = Bytes.toBytes("hello world"); byte[] array = Bytes.toBytes("hello world");
assertTrue(Bytes.contains(array, (byte) 'e')); assertTrue(Bytes.contains(array, (byte) 'e'));
@ -515,6 +552,7 @@ public class TestBytes extends TestCase {
assertFalse(Bytes.contains(array, Bytes.toBytes("owo"))); assertFalse(Bytes.contains(array, Bytes.toBytes("owo")));
} }
@Test
public void testZero() { public void testZero() {
byte[] array = Bytes.toBytes("hello"); byte[] array = Bytes.toBytes("hello");
Bytes.zero(array); Bytes.zero(array);
@ -533,6 +571,7 @@ public class TestBytes extends TestCase {
} }
} }
@Test
public void testPutBuffer() { public void testPutBuffer() {
byte[] b = new byte[100]; byte[] b = new byte[100];
for (byte i = 0; i < 100; i++) { for (byte i = 0; i < 100; i++) {
@ -543,6 +582,7 @@ public class TestBytes extends TestCase {
} }
} }
@Test
public void testToFromHex() { public void testToFromHex() {
List<String> testStrings = new ArrayList<>(8); List<String> testStrings = new ArrayList<>(8);
testStrings.addAll(Arrays.asList("", "00", "A0", "ff", "FFffFFFFFFFFFF", "12", testStrings.addAll(Arrays.asList("", "00", "A0", "ff", "FFffFFFFFFFFFF", "12",

View File

@ -17,6 +17,10 @@
*/ */
package org.apache.hadoop.hbase.http.conf; package org.apache.hadoop.hbase.http.conf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.StringReader; import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.HashSet; import java.util.HashSet;
@ -24,7 +28,6 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import junit.framework.TestCase;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.MiscTests;
@ -44,8 +47,8 @@ import org.apache.hbase.thirdparty.org.eclipse.jetty.util.ajax.JSON;
* Basic test case that the ConfServlet can write configuration * Basic test case that the ConfServlet can write configuration
* to its output in XML and JSON format. * to its output in XML and JSON format.
*/ */
@Category({MiscTests.class, SmallTests.class}) @Category({ MiscTests.class, SmallTests.class })
public class TestConfServlet extends TestCase { public class TestConfServlet {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =

View File

@ -21,8 +21,6 @@ package org.apache.hadoop.hbase;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.NavigableMap; import java.util.NavigableMap;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
@ -51,7 +49,7 @@ import org.slf4j.LoggerFactory;
* @see <a href="https://issues.apache.org/jira/browse/HBASE-11912">HBASE-11912</a> * @see <a href="https://issues.apache.org/jira/browse/HBASE-11912">HBASE-11912</a>
*/ */
@Deprecated @Deprecated
public abstract class HBaseTestCase extends TestCase { public abstract class HBaseTestCase extends junit.framework.TestCase {
private static final Logger LOG = LoggerFactory.getLogger(HBaseTestCase.class); private static final Logger LOG = LoggerFactory.getLogger(HBaseTestCase.class);
protected final static byte [] fam1 = Bytes.toBytes("colfamily11"); protected final static byte [] fam1 = Bytes.toBytes("colfamily11");
@ -432,21 +430,17 @@ public abstract class HBaseTestCase extends TestCase {
HBaseTestingUtility.closeRegionAndWAL(meta); HBaseTestingUtility.closeRegionAndWAL(meta);
} }
public static void assertByteEquals(byte[] expected, public static void assertByteEquals(byte[] expected, byte[] actual) {
byte[] actual) {
if (Bytes.compareTo(expected, actual) != 0) { if (Bytes.compareTo(expected, actual) != 0) {
throw new AssertionFailedError("expected:<" + throw new junit.framework.AssertionFailedError(
Bytes.toString(expected) + "> but was:<" + "expected:<" + Bytes.toString(expected) + "> but was:<" + Bytes.toString(actual) + ">");
Bytes.toString(actual) + ">");
} }
} }
public static void assertEquals(byte[] expected, public static void assertEquals(byte[] expected, byte[] actual) {
byte[] actual) {
if (Bytes.compareTo(expected, actual) != 0) { if (Bytes.compareTo(expected, actual) != 0) {
throw new AssertionFailedError("expected:<" + throw new junit.framework.AssertionFailedError("expected:<" + Bytes.toStringBinary(expected) +
Bytes.toStringBinary(expected) + "> but was:<" + "> but was:<" + Bytes.toStringBinary(actual) + ">");
Bytes.toStringBinary(actual) + ">");
} }
} }
} }

View File

@ -19,9 +19,13 @@ package org.apache.hadoop.hbase.client;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan; import static org.hamcrest.Matchers.lessThan;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -29,7 +33,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import junit.framework.TestCase;
import org.apache.hadoop.hbase.ArrayBackedTag; import org.apache.hadoop.hbase.ArrayBackedTag;
import org.apache.hadoop.hbase.ByteBufferKeyValue; import org.apache.hadoop.hbase.ByteBufferKeyValue;
import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.Cell;
@ -44,12 +47,13 @@ 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.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@Category({SmallTests.class, ClientTests.class}) @Category({ SmallTests.class, ClientTests.class })
public class TestResult extends TestCase { public class TestResult {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
@ -79,8 +83,8 @@ public class TestResult extends TestCase {
/** /**
* Run some tests to ensure Result acts like a proper CellScanner. * Run some tests to ensure Result acts like a proper CellScanner.
* @throws IOException
*/ */
@Test
public void testResultAsCellScanner() throws IOException { public void testResultAsCellScanner() throws IOException {
Cell [] cells = genKVs(row, family, value, 1, 10); Cell [] cells = genKVs(row, family, value, 1, 10);
Arrays.sort(cells, CellComparator.getInstance()); Arrays.sort(cells, CellComparator.getInstance());
@ -102,6 +106,7 @@ public class TestResult extends TestCase {
assertEquals(cells.length, count); assertEquals(cells.length, count);
} }
@Test
public void testBasicGetColumn() throws Exception { public void testBasicGetColumn() throws Exception {
KeyValue [] kvs = genKVs(row, family, value, 1, 100); KeyValue [] kvs = genKVs(row, family, value, 1, 100);
@ -119,12 +124,14 @@ public class TestResult extends TestCase {
} }
} }
@Test
public void testCurrentOnEmptyCell() throws IOException { public void testCurrentOnEmptyCell() throws IOException {
Result r = Result.create(new Cell[0]); Result r = Result.create(new Cell[0]);
assertFalse(r.advance()); assertFalse(r.advance());
assertNull(r.current()); assertNull(r.current());
} }
@Test
public void testAdvanceTwiceOnEmptyCell() throws IOException { public void testAdvanceTwiceOnEmptyCell() throws IOException {
Result r = Result.create(new Cell[0]); Result r = Result.create(new Cell[0]);
assertFalse(r.advance()); assertFalse(r.advance());
@ -136,6 +143,7 @@ public class TestResult extends TestCase {
} }
} }
@Test
public void testMultiVersionGetColumn() throws Exception { public void testMultiVersionGetColumn() throws Exception {
KeyValue [] kvs1 = genKVs(row, family, value, 1, 100); KeyValue [] kvs1 = genKVs(row, family, value, 1, 100);
KeyValue [] kvs2 = genKVs(row, family, value, 200, 100); KeyValue [] kvs2 = genKVs(row, family, value, 200, 100);
@ -158,6 +166,7 @@ public class TestResult extends TestCase {
} }
} }
@Test
public void testBasicGetValue() throws Exception { public void testBasicGetValue() throws Exception {
KeyValue [] kvs = genKVs(row, family, value, 1, 100); KeyValue [] kvs = genKVs(row, family, value, 1, 100);
@ -173,6 +182,7 @@ public class TestResult extends TestCase {
} }
} }
@Test
public void testMultiVersionGetValue() throws Exception { public void testMultiVersionGetValue() throws Exception {
KeyValue [] kvs1 = genKVs(row, family, value, 1, 100); KeyValue [] kvs1 = genKVs(row, family, value, 1, 100);
KeyValue [] kvs2 = genKVs(row, family, value, 200, 100); KeyValue [] kvs2 = genKVs(row, family, value, 200, 100);
@ -192,6 +202,7 @@ public class TestResult extends TestCase {
} }
} }
@Test
public void testBasicLoadValue() throws Exception { public void testBasicLoadValue() throws Exception {
KeyValue [] kvs = genKVs(row, family, value, 1, 100); KeyValue [] kvs = genKVs(row, family, value, 1, 100);
@ -212,6 +223,7 @@ public class TestResult extends TestCase {
} }
} }
@Test
public void testMultiVersionLoadValue() throws Exception { public void testMultiVersionLoadValue() throws Exception {
KeyValue [] kvs1 = genKVs(row, family, value, 1, 100); KeyValue [] kvs1 = genKVs(row, family, value, 1, 100);
KeyValue [] kvs2 = genKVs(row, family, value, 200, 100); KeyValue [] kvs2 = genKVs(row, family, value, 200, 100);
@ -240,6 +252,7 @@ public class TestResult extends TestCase {
/** /**
* Verify that Result.compareResults(...) behaves correctly. * Verify that Result.compareResults(...) behaves correctly.
*/ */
@Test
public void testCompareResults() throws Exception { public void testCompareResults() throws Exception {
byte [] value1 = Bytes.toBytes("value1"); byte [] value1 = Bytes.toBytes("value1");
byte [] qual = Bytes.toBytes("qual"); byte [] qual = Bytes.toBytes("qual");
@ -260,6 +273,7 @@ public class TestResult extends TestCase {
} }
} }
@Test
public void testCompareResultsWithTags() throws Exception { public void testCompareResultsWithTags() throws Exception {
Tag t1 = new ArrayBackedTag((byte) 1, Bytes.toBytes("TAG1")); Tag t1 = new ArrayBackedTag((byte) 1, Bytes.toBytes("TAG1"));
Tag t2 = new ArrayBackedTag((byte) 2, Bytes.toBytes("TAG2")); Tag t2 = new ArrayBackedTag((byte) 2, Bytes.toBytes("TAG2"));
@ -374,6 +388,7 @@ public class TestResult extends TestCase {
} }
} }
@Test
public void testCompareResultMemoryUsage() { public void testCompareResultMemoryUsage() {
List<Cell> cells1 = new ArrayList<>(); List<Cell> cells1 = new ArrayList<>();
for (long i = 0; i < 100; i++) { for (long i = 0; i < 100; i++) {
@ -392,7 +407,7 @@ public class TestResult extends TestCase {
fail(); fail();
} catch (Exception x) { } catch (Exception x) {
assertTrue(x.getMessage().startsWith("This result was different:")); assertTrue(x.getMessage().startsWith("This result was different:"));
assertThat(x.getMessage().length(), is(greaterThan(100))); assertThat(x.getMessage().length(), greaterThan(100));
} }
try { try {
@ -400,7 +415,7 @@ public class TestResult extends TestCase {
fail(); fail();
} catch (Exception x) { } catch (Exception x) {
assertEquals("This result was different: row=row", x.getMessage()); assertEquals("This result was different: row=row", x.getMessage());
assertThat(x.getMessage().length(), is(lessThan(100))); assertThat(x.getMessage().length(), lessThan(100));
} }
} }
@ -429,6 +444,7 @@ public class TestResult extends TestCase {
/** /**
* Verifies that one can't modify instance of EMPTY_RESULT. * Verifies that one can't modify instance of EMPTY_RESULT.
*/ */
@Test
public void testEmptyResultIsReadonly() { public void testEmptyResultIsReadonly() {
Result emptyResult = Result.EMPTY_RESULT; Result emptyResult = Result.EMPTY_RESULT;
Result otherResult = new Result(); Result otherResult = new Result();

View File

@ -17,9 +17,10 @@
*/ */
package org.apache.hadoop.hbase.coprocessor; package org.apache.hadoop.hbase.coprocessor;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.util.Optional; import java.util.Optional;
import junit.framework.TestCase;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Coprocessor; import org.apache.hadoop.hbase.Coprocessor;
@ -40,13 +41,15 @@ import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.wal.WALEdit; import org.apache.hadoop.hbase.wal.WALEdit;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.mockito.Mockito; import org.mockito.Mockito;
@Category({CoprocessorTests.class, SmallTests.class}) @Category({CoprocessorTests.class, SmallTests.class})
public class TestRegionObserverStacking extends TestCase { public class TestRegionObserverStacking {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
@ -70,10 +73,7 @@ public class TestRegionObserverStacking extends TestCase {
final Durability durability) final Durability durability)
throws IOException { throws IOException {
id = EnvironmentEdgeManager.currentTime(); id = EnvironmentEdgeManager.currentTime();
try { Threads.sleepWithoutInterrupt(10);
Thread.sleep(10);
} catch (InterruptedException ex) {
}
} }
} }
@ -91,10 +91,7 @@ public class TestRegionObserverStacking extends TestCase {
final Durability durability) final Durability durability)
throws IOException { throws IOException {
id = EnvironmentEdgeManager.currentTime(); id = EnvironmentEdgeManager.currentTime();
try { Threads.sleepWithoutInterrupt(10);
Thread.sleep(10);
} catch (InterruptedException ex) {
}
} }
} }
@ -112,10 +109,7 @@ public class TestRegionObserverStacking extends TestCase {
final Durability durability) final Durability durability)
throws IOException { throws IOException {
id = EnvironmentEdgeManager.currentTime(); id = EnvironmentEdgeManager.currentTime();
try { Threads.sleepWithoutInterrupt(10);
Thread.sleep(10);
} catch (InterruptedException ex) {
}
} }
} }
@ -140,6 +134,7 @@ public class TestRegionObserverStacking extends TestCase {
return r; return r;
} }
@Test
public void testRegionObserverStacking() throws Exception { public void testRegionObserverStacking() throws Exception {
byte[] ROW = Bytes.toBytes("testRow"); byte[] ROW = Bytes.toBytes("testRow");
byte[] TABLE = Bytes.toBytes(this.getClass().getSimpleName()); byte[] TABLE = Bytes.toBytes(this.getClass().getSimpleName());

View File

@ -17,9 +17,10 @@
*/ */
package org.apache.hadoop.hbase.filter; package org.apache.hadoop.hbase.filter;
import static org.junit.Assert.assertTrue;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import junit.framework.TestCase;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.testclassification.FilterTests; import org.apache.hadoop.hbase.testclassification.FilterTests;
@ -30,7 +31,7 @@ import org.junit.experimental.categories.Category;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Category({FilterTests.class, SmallTests.class}) @Category({FilterTests.class, SmallTests.class})
public class TestFirstKeyValueMatchingQualifiersFilter extends TestCase { public class TestFirstKeyValueMatchingQualifiersFilter {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
@ -46,8 +47,6 @@ public class TestFirstKeyValueMatchingQualifiersFilter extends TestCase {
/** /**
* Test the functionality of * Test the functionality of
* {@link FirstKeyValueMatchingQualifiersFilter#filterCell(org.apache.hadoop.hbase.Cell)} * {@link FirstKeyValueMatchingQualifiersFilter#filterCell(org.apache.hadoop.hbase.Cell)}
*
* @throws Exception
*/ */
public void testFirstKeyMatchingQualifierFilter() throws Exception { public void testFirstKeyMatchingQualifierFilter() throws Exception {
Set<byte[]> quals = new TreeSet<>(Bytes.BYTES_COMPARATOR); Set<byte[]> quals = new TreeSet<>(Bytes.BYTES_COMPARATOR);

View File

@ -17,24 +17,29 @@
*/ */
package org.apache.hadoop.hbase.io; package org.apache.hadoop.hbase.io;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import junit.framework.TestCase;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.IOTests; import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
@Category({IOTests.class, SmallTests.class}) @Category({ IOTests.class, SmallTests.class })
public class TestImmutableBytesWritable extends TestCase { public class TestImmutableBytesWritable {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestImmutableBytesWritable.class); HBaseClassTestRule.forClass(TestImmutableBytesWritable.class);
@Test
public void testHash() throws Exception { public void testHash() throws Exception {
assertEquals( assertEquals(
new ImmutableBytesWritable(Bytes.toBytes("xxabc"), 2, 3).hashCode(), new ImmutableBytesWritable(Bytes.toBytes("xxabc"), 2, 3).hashCode(),
@ -47,6 +52,7 @@ public class TestImmutableBytesWritable extends TestCase {
new ImmutableBytesWritable(Bytes.toBytes("xxabc"), 2, 2).hashCode()); new ImmutableBytesWritable(Bytes.toBytes("xxabc"), 2, 2).hashCode());
} }
@Test
public void testSpecificCompare() { public void testSpecificCompare() {
ImmutableBytesWritable ibw1 = new ImmutableBytesWritable(new byte[]{0x0f}); ImmutableBytesWritable ibw1 = new ImmutableBytesWritable(new byte[]{0x0f});
ImmutableBytesWritable ibw2 = new ImmutableBytesWritable(new byte[]{0x00, 0x00}); ImmutableBytesWritable ibw2 = new ImmutableBytesWritable(new byte[]{0x00, 0x00});
@ -54,6 +60,7 @@ public class TestImmutableBytesWritable extends TestCase {
assertFalse("ibw1 < ibw2", c.compare( ibw1, ibw2 ) < 0 ); assertFalse("ibw1 < ibw2", c.compare( ibw1, ibw2 ) < 0 );
} }
@Test
public void testComparison() throws Exception { public void testComparison() throws Exception {
runTests("aa", "b", -1); runTests("aa", "b", -1);
runTests("aa", "aa", 0); runTests("aa", "aa", 0);

View File

@ -17,23 +17,25 @@
*/ */
package org.apache.hadoop.hbase.io.hfile; package org.apache.hadoop.hbase.io.hfile;
import static org.junit.Assert.assertEquals;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import junit.framework.TestCase;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.IOTests; import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
@Category({IOTests.class, SmallTests.class}) @Category({ IOTests.class, SmallTests.class })
public class TestCachedBlockQueue extends TestCase { public class TestCachedBlockQueue {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestCachedBlockQueue.class); HBaseClassTestRule.forClass(TestCachedBlockQueue.class);
@Test
public void testQueue() throws Exception { public void testQueue() throws Exception {
CachedBlock cb1 = new CachedBlock(1000, "cb1", 1); CachedBlock cb1 = new CachedBlock(1000, "cb1", 1);
CachedBlock cb2 = new CachedBlock(1500, "cb2", 2); CachedBlock cb2 = new CachedBlock(1500, "cb2", 2);
CachedBlock cb3 = new CachedBlock(1000, "cb3", 3); CachedBlock cb3 = new CachedBlock(1000, "cb3", 3);
@ -70,8 +72,8 @@ public class TestCachedBlockQueue extends TestCase {
} }
} }
@Test
public void testQueueSmallBlockEdgeCase() throws Exception { public void testQueueSmallBlockEdgeCase() throws Exception {
CachedBlock cb1 = new CachedBlock(1000, "cb1", 1); CachedBlock cb1 = new CachedBlock(1000, "cb1", 1);
CachedBlock cb2 = new CachedBlock(1500, "cb2", 2); CachedBlock cb2 = new CachedBlock(1500, "cb2", 2);
CachedBlock cb3 = new CachedBlock(1000, "cb3", 3); CachedBlock cb3 = new CachedBlock(1000, "cb3", 3);
@ -115,39 +117,35 @@ public class TestCachedBlockQueue extends TestCase {
} }
} }
private static class CachedBlock extends org.apache.hadoop.hbase.io.hfile.LruCachedBlock private static class CachedBlock extends org.apache.hadoop.hbase.io.hfile.LruCachedBlock {
{
public CachedBlock(final long heapSize, String name, long accessTime) { public CachedBlock(final long heapSize, String name, long accessTime) {
super(new BlockCacheKey(name, 0), super(new BlockCacheKey(name, 0), new Cacheable() {
new Cacheable() { @Override
@Override public long heapSize() {
public long heapSize() { return ((int) (heapSize - CachedBlock.PER_BLOCK_OVERHEAD));
return ((int)(heapSize - CachedBlock.PER_BLOCK_OVERHEAD)); }
}
@Override @Override
public int getSerializedLength() { public int getSerializedLength() {
return 0; return 0;
} }
@Override @Override
public void serialize(ByteBuffer destination, boolean includeNextBlockMetadata) { public void serialize(ByteBuffer destination, boolean includeNextBlockMetadata) {
} }
@Override @Override
public CacheableDeserializer<Cacheable> getDeserializer() { public CacheableDeserializer<Cacheable> getDeserializer() {
// TODO Auto-generated method stub return null;
return null; }
}
@Override @Override
public BlockType getBlockType() { public BlockType getBlockType() {
return BlockType.DATA; return BlockType.DATA;
} }
}, accessTime, false); }, accessTime, false);
} }
} }
} }

View File

@ -21,7 +21,6 @@ import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Random; import java.util.Random;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import junit.framework.TestCase;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
@ -36,7 +35,10 @@ import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.RandomDistribution; import org.apache.hadoop.hbase.util.RandomDistribution;
import org.apache.hadoop.io.BytesWritable; import org.apache.hadoop.io.BytesWritable;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -58,8 +60,8 @@ import org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException;
* Remove after tfile is committed and use the tfile version of this class * Remove after tfile is committed and use the tfile version of this class
* instead.</p> * instead.</p>
*/ */
@Category({IOTests.class, SmallTests.class}) @Category({ IOTests.class, SmallTests.class })
public class TestHFileSeek extends TestCase { public class TestHFileSeek {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
@ -79,7 +81,7 @@ public class TestHFileSeek extends TestCase {
private static final Logger LOG = LoggerFactory.getLogger(TestHFileSeek.class); private static final Logger LOG = LoggerFactory.getLogger(TestHFileSeek.class);
@Override @Before
public void setUp() throws IOException { public void setUp() throws IOException {
if (options == null) { if (options == null) {
options = new MyOptions(new String[0]); options = new MyOptions(new String[0]);
@ -111,7 +113,7 @@ public class TestHFileSeek extends TestCase {
options.dictSize); options.dictSize);
} }
@Override @After
public void tearDown() { public void tearDown() {
try { try {
fs.close(); fs.close();
@ -216,6 +218,7 @@ public class TestHFileSeek extends TestCase {
} }
@Test
public void testSeeks() throws IOException { public void testSeeks() throws IOException {
if (options.doCreate()) { if (options.doCreate()) {
createTFile(); createTFile();

View File

@ -17,9 +17,12 @@
*/ */
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 java.util.Iterator; import java.util.Iterator;
import java.util.SortedSet; import java.util.SortedSet;
import junit.framework.TestCase;
import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellComparatorImpl; import org.apache.hadoop.hbase.CellComparatorImpl;
import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.CellUtil;
@ -28,11 +31,15 @@ import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.testclassification.RegionServerTests; import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Before;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.junit.rules.TestName;
@Category({RegionServerTests.class, SmallTests.class}) @Category({ RegionServerTests.class, SmallTests.class })
public class TestCellSkipListSet extends TestCase { public class TestCellSkipListSet {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
@ -41,14 +48,17 @@ public class TestCellSkipListSet extends TestCase {
private final CellSet csls = private final CellSet csls =
new CellSet(CellComparatorImpl.COMPARATOR); new CellSet(CellComparatorImpl.COMPARATOR);
@Override @Rule
protected void setUp() throws Exception { public TestName name = new TestName();
super.setUp();
@Before
public void setUp() throws Exception {
this.csls.clear(); this.csls.clear();
} }
@Test
public void testAdd() throws Exception { public void testAdd() throws Exception {
byte[] bytes = Bytes.toBytes(getName()); byte[] bytes = Bytes.toBytes(name.getMethodName());
KeyValue kv = new KeyValue(bytes, bytes, bytes, bytes); KeyValue kv = new KeyValue(bytes, bytes, bytes, bytes);
this.csls.add(kv); this.csls.add(kv);
assertTrue(this.csls.contains(kv)); assertTrue(this.csls.contains(kv));
@ -69,8 +79,9 @@ public class TestCellSkipListSet extends TestCase {
assertFalse(Bytes.equals(CellUtil.cloneValue(overwrite), CellUtil.cloneValue(kv))); assertFalse(Bytes.equals(CellUtil.cloneValue(overwrite), CellUtil.cloneValue(kv)));
} }
@Test
public void testIterator() throws Exception { public void testIterator() throws Exception {
byte [] bytes = Bytes.toBytes(getName()); byte [] bytes = Bytes.toBytes(name.getMethodName());
byte [] value1 = Bytes.toBytes("1"); byte [] value1 = Bytes.toBytes("1");
byte [] value2 = Bytes.toBytes("2"); byte [] value2 = Bytes.toBytes("2");
final int total = 3; final int total = 3;
@ -104,8 +115,9 @@ public class TestCellSkipListSet extends TestCase {
assertEquals(total, count); assertEquals(total, count);
} }
@Test
public void testDescendingIterator() throws Exception { public void testDescendingIterator() throws Exception {
byte [] bytes = Bytes.toBytes(getName()); byte [] bytes = Bytes.toBytes(name.getMethodName());
byte [] value1 = Bytes.toBytes("1"); byte [] value1 = Bytes.toBytes("1");
byte [] value2 = Bytes.toBytes("2"); byte [] value2 = Bytes.toBytes("2");
final int total = 3; final int total = 3;
@ -141,8 +153,9 @@ public class TestCellSkipListSet extends TestCase {
assertEquals(total, count); assertEquals(total, count);
} }
@Test
public void testHeadTail() throws Exception { public void testHeadTail() throws Exception {
byte [] bytes = Bytes.toBytes(getName()); byte [] bytes = Bytes.toBytes(name.getMethodName());
byte [] value1 = Bytes.toBytes("1"); byte [] value1 = Bytes.toBytes("1");
byte [] value2 = Bytes.toBytes("2"); byte [] value2 = Bytes.toBytes("2");
final int total = 3; final int total = 3;

View File

@ -17,8 +17,10 @@
*/ */
package org.apache.hadoop.hbase.regionserver; package org.apache.hadoop.hbase.regionserver;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import junit.framework.TestCase;
import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellComparator; import org.apache.hadoop.hbase.CellComparator;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
@ -29,16 +31,17 @@ import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
@Category({RegionServerTests.class, SmallTests.class}) @Category({ RegionServerTests.class, SmallTests.class })
public class TestKeyValueScanFixture extends TestCase { public class TestKeyValueScanFixture {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestKeyValueScanFixture.class); HBaseClassTestRule.forClass(TestKeyValueScanFixture.class);
@Test
public void testKeyValueScanFixture() throws IOException { public void testKeyValueScanFixture() throws IOException {
KeyValue kvs[] = new KeyValue[]{ KeyValue kvs[] = new KeyValue[]{
KeyValueTestUtil.create("RowA", "family", "qf1", KeyValueTestUtil.create("RowA", "family", "qf1",

View File

@ -17,24 +17,29 @@
*/ */
package org.apache.hadoop.hbase.util; package org.apache.hadoop.hbase.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import junit.framework.TestCase;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.nio.MultiByteBuff; import org.apache.hadoop.hbase.nio.MultiByteBuff;
import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
@Category({MiscTests.class, SmallTests.class}) @Category({MiscTests.class, SmallTests.class})
public class TestBloomFilterChunk extends TestCase { public class TestBloomFilterChunk {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestBloomFilterChunk.class); HBaseClassTestRule.forClass(TestBloomFilterChunk.class);
@Test
public void testBasicBloom() throws Exception { public void testBasicBloom() throws Exception {
BloomFilterChunk bf1 = new BloomFilterChunk(1000, (float)0.01, Hash.MURMUR_HASH, 0); BloomFilterChunk bf1 = new BloomFilterChunk(1000, (float)0.01, Hash.MURMUR_HASH, 0);
BloomFilterChunk bf2 = new BloomFilterChunk(1000, (float)0.01, Hash.MURMUR_HASH, 0); BloomFilterChunk bf2 = new BloomFilterChunk(1000, (float)0.01, Hash.MURMUR_HASH, 0);
@ -94,6 +99,7 @@ public class TestBloomFilterChunk extends TestCase {
assertTrue(bOut.size() - bf1.byteSize < 10); //... allow small padding assertTrue(bOut.size() - bf1.byteSize < 10); //... allow small padding
} }
@Test
public void testBloomFold() throws Exception { public void testBloomFold() throws Exception {
// test: foldFactor < log(max/actual) // test: foldFactor < log(max/actual)
BloomFilterChunk b = new BloomFilterChunk(1003, (float) 0.01, BloomFilterChunk b = new BloomFilterChunk(1003, (float) 0.01,
@ -123,6 +129,7 @@ public class TestBloomFilterChunk extends TestCase {
// test: foldFactor > log(max/actual) // test: foldFactor > log(max/actual)
} }
@Test
public void testBloomPerf() throws Exception { public void testBloomPerf() throws Exception {
// add // add
float err = (float)0.01; float err = (float)0.01;
@ -166,6 +173,7 @@ public class TestBloomFilterChunk extends TestCase {
// test: foldFactor > log(max/actual) // test: foldFactor > log(max/actual)
} }
@Test
public void testSizing() { public void testSizing() {
int bitSize = 8 * 128 * 1024; // 128 KB int bitSize = 8 * 128 * 1024; // 128 KB
double errorRate = 0.025; // target false positive rate double errorRate = 0.025; // target false positive rate
@ -183,11 +191,10 @@ public class TestBloomFilterChunk extends TestCase {
assertTrue(Math.abs(bitSize2 - bitSize) * 1.0 / bitSize < 1e-5); assertTrue(Math.abs(bitSize2 - bitSize) * 1.0 / bitSize < 1e-5);
} }
@Test
public void testFoldableByteSize() { public void testFoldableByteSize() {
assertEquals(128, BloomFilterUtil.computeFoldableByteSize(1000, 5)); assertEquals(128, BloomFilterUtil.computeFoldableByteSize(1000, 5));
assertEquals(640, BloomFilterUtil.computeFoldableByteSize(5001, 4)); assertEquals(640, BloomFilterUtil.computeFoldableByteSize(5001, 4));
} }
} }

View File

@ -17,35 +17,47 @@
*/ */
package org.apache.hadoop.hbase.util; package org.apache.hadoop.hbase.util;
import junit.framework.TestCase; import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.security.UserProvider; import org.apache.hadoop.hbase.security.UserProvider;
import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
@Category({MiscTests.class, MediumTests.class}) @Category({ MiscTests.class, MediumTests.class })
public class TestConnectionCache extends TestCase { public class TestConnectionCache {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestConnectionCache.class); HBaseClassTestRule.forClass(TestConnectionCache.class);
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
@BeforeClass
public static void setUp() throws Exception {
UTIL.startMiniCluster();
}
@AfterClass
public static void tearDown() throws IOException {
UTIL.shutdownMiniCluster();
}
/** /**
* test for ConnectionCache cleaning expired Connection * test for ConnectionCache cleaning expired Connection
*/ */
@Test @Test
public void testConnectionChore() throws Exception { public void testConnectionChore() throws Exception {
UTIL.startMiniCluster(); // 1s for clean interval & 5s for maxIdleTime
//1s for clean interval & 5s for maxIdleTime
ConnectionCache cache = new ConnectionCache(UTIL.getConfiguration(), ConnectionCache cache = new ConnectionCache(UTIL.getConfiguration(),
UserProvider.instantiate(UTIL.getConfiguration()), 1000, 5000); UserProvider.instantiate(UTIL.getConfiguration()), 1000, 5000);
ConnectionCache.ConnectionInfo info = cache.getCurrentConnection(); ConnectionCache.ConnectionInfo info = cache.getCurrentConnection();
assertEquals(false, info.connection.isClosed()); assertEquals(false, info.connection.isClosed());
@ -53,8 +65,5 @@ public class TestConnectionCache extends TestCase {
Thread.sleep(7000); Thread.sleep(7000);
assertEquals(true, info.connection.isClosed()); assertEquals(true, info.connection.isClosed());
UTIL.shutdownMiniCluster();
} }
} }

View File

@ -17,14 +17,16 @@
*/ */
package org.apache.hadoop.hbase.util; package org.apache.hadoop.hbase.util;
import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import junit.framework.TestCase;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.log.HBaseMarkers; import org.apache.hadoop.hbase.log.HBaseMarkers;
import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -33,7 +35,7 @@ import org.slf4j.LoggerFactory;
* Test requirement that root directory must be a URI * Test requirement that root directory must be a URI
*/ */
@Category({MiscTests.class, SmallTests.class}) @Category({MiscTests.class, SmallTests.class})
public class TestRootPath extends TestCase { public class TestRootPath {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
@ -42,6 +44,7 @@ public class TestRootPath extends TestCase {
private static final Logger LOG = LoggerFactory.getLogger(TestRootPath.class); private static final Logger LOG = LoggerFactory.getLogger(TestRootPath.class);
/** The test */ /** The test */
@Test
public void testRootPath() { public void testRootPath() {
try { try {
// Try good path // Try good path

View File

@ -1211,6 +1211,14 @@
<bannedImport>com.fasterxml.jackson.jaxrs.**</bannedImport> <bannedImport>com.fasterxml.jackson.jaxrs.**</bannedImport>
</bannedImports> </bannedImports>
</restrictImports> </restrictImports>
<restrictImports implementation="de.skuzzle.enforcer.restrictimports.rule.RestrictImports">
<includeTestCode>true</includeTestCode>
<commentLineBufferSize>512</commentLineBufferSize>
<reason>Use junit4 instead</reason>
<bannedImports>
<bannedImport>junit.framework.**</bannedImport>
</bannedImports>
</restrictImports>
</rules> </rules>
</configuration> </configuration>
</execution> </execution>