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 committed by GitHub
parent e1c2c16214
commit f6348d4100
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 202 additions and 99 deletions

View File

@ -18,14 +18,19 @@
package org.apache.hadoop.hbase.util;
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.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
@ -33,17 +38,17 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import junit.framework.TestCase;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.io.WritableUtils;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@Category({MiscTests.class, MediumTests.class})
public class TestBytes extends TestCase {
public class TestBytes {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestBytes.class);
@ -64,10 +69,12 @@ public class TestBytes extends TestCase {
assertEquals(Bytes.UNSAFE_UNALIGNED, value);
}
@Test
public void testShort() throws Exception {
testShort(false);
}
@Test
public void testShortUnsafe() throws Exception {
testShort(true);
}
@ -91,6 +98,7 @@ public class TestBytes extends TestCase {
}
}
@Test
public void testNullHashCode() {
byte [] b = null;
Exception ee = null;
@ -102,6 +110,7 @@ public class TestBytes extends TestCase {
assertNotNull(ee);
}
@Test
public void testAdd() {
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};
@ -115,6 +124,7 @@ public class TestBytes extends TestCase {
assertEquals(0, Bytes.compareTo(result1, result2));
}
@Test
public void testSplit() {
byte[] lowest = Bytes.toBytes("AAA");
byte[] middle = Bytes.toBytes("CCC");
@ -136,6 +146,7 @@ public class TestBytes extends TestCase {
assertTrue(Bytes.equals(parts[2], middle));
}
@Test
public void testSplit2() {
// More split tests.
byte [] lowest = Bytes.toBytes("http://A");
@ -149,6 +160,7 @@ public class TestBytes extends TestCase {
assertTrue(Bytes.equals(parts[1], middle));
}
@Test
public void testSplit3() {
// Test invalid split cases
byte[] low = { 1, 1, 1 };
@ -183,6 +195,7 @@ public class TestBytes extends TestCase {
}
}
@Test
public void testToInt() {
int[] ints = { -1, 123, Integer.MIN_VALUE, Integer.MAX_VALUE };
for (int anInt : ints) {
@ -194,6 +207,7 @@ public class TestBytes extends TestCase {
}
}
@Test
public void testToLong() {
long[] longs = { -1L, 123L, Long.MIN_VALUE, Long.MAX_VALUE };
for (long aLong : longs) {
@ -205,6 +219,7 @@ public class TestBytes extends TestCase {
}
}
@Test
public void testToFloat() {
float[] floats = { -1f, 123.123f, Float.MAX_VALUE };
for (float aFloat : floats) {
@ -215,6 +230,7 @@ public class TestBytes extends TestCase {
}
}
@Test
public void testToDouble() {
double [] doubles = {Double.MIN_VALUE, Double.MAX_VALUE};
for (double aDouble : doubles) {
@ -225,6 +241,7 @@ public class TestBytes extends TestCase {
}
}
@Test
public void testToBigDecimal() {
BigDecimal[] decimals = { new BigDecimal("-1"), new BigDecimal("123.123"),
new BigDecimal("123123123123") };
@ -244,6 +261,7 @@ public class TestBytes extends TestCase {
return result;
}
@Test
public void testToBytesForByteBuffer() {
byte[] array = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
ByteBuffer target = ByteBuffer.wrap(array);
@ -267,6 +285,7 @@ public class TestBytes extends TestCase {
assertEquals(5, target2.limit());
}
@Test
public void testGetBytesForByteBuffer() {
byte[] array = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
ByteBuffer target = ByteBuffer.wrap(array);
@ -280,6 +299,7 @@ public class TestBytes extends TestCase {
assertEquals(7, target.limit());
}
@Test
public void testReadAsVLong() throws Exception {
long[] longs = { -1L, 123L, Long.MIN_VALUE, Long.MAX_VALUE };
for (long aLong : longs) {
@ -293,6 +313,7 @@ public class TestBytes extends TestCase {
}
}
@Test
public void testToStringBinaryForBytes() {
byte[] array = { '0', '9', 'a', 'z', 'A', 'Z', '@', 1 };
String actual = Bytes.toStringBinary(array);
@ -304,6 +325,7 @@ public class TestBytes extends TestCase {
assertEquals(expected2, actual2);
}
@Test
public void testToStringBinaryForArrayBasedByteBuffer() {
byte[] array = { '0', '9', 'a', 'z', 'A', 'Z', '@', 1 };
ByteBuffer target = ByteBuffer.wrap(array);
@ -312,6 +334,7 @@ public class TestBytes extends TestCase {
assertEquals(expected, actual);
}
@Test
public void testToStringBinaryForReadOnlyByteBuffer() {
byte[] array = { '0', '9', 'a', 'z', 'A', 'Z', '@', 1 };
ByteBuffer target = ByteBuffer.wrap(array).asReadOnlyBuffer();
@ -320,6 +343,7 @@ public class TestBytes extends TestCase {
assertEquals(expected, actual);
}
@Test
public void testBinarySearch() {
byte[][] arr = {
{ 1 },
@ -360,6 +384,7 @@ public class TestBytes extends TestCase {
}
}
@Test
public void testToStringBytesBinaryReversible() {
// let's run test with 1000 randomly generated byte arrays
Random rand = new Random(EnvironmentEdgeManager.currentTime());
@ -384,6 +409,7 @@ public class TestBytes extends TestCase {
}
}
@Test
public void testStartsWith() {
assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("h")));
assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("")));
@ -392,6 +418,7 @@ public class TestBytes extends TestCase {
assertFalse(Bytes.startsWith(Bytes.toBytes(""), Bytes.toBytes("hello")));
}
@Test
public void testIncrementBytes() {
assertTrue(checkTestIncrementBytes(10, 1));
assertTrue(checkTestIncrementBytes(12, 123435445));
@ -426,6 +453,7 @@ public class TestBytes extends TestCase {
return (Bytes.toLong(testValue) + amount) == incrementResult;
}
@Test
public void testFixedSizeString() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
@ -451,6 +479,7 @@ public class TestBytes extends TestCase {
assertEquals("", Bytes.readStringFixedSize(dis, 9));
}
@Test
public void testCopy() {
byte[] bytes = Bytes.toBytes("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
byte[] copy = Bytes.copy(bytes);
@ -458,6 +487,7 @@ public class TestBytes extends TestCase {
assertTrue(Bytes.equals(bytes, copy));
}
@Test
public void testToBytesBinaryTrailingBackslashes() {
try {
Bytes.toBytesBinary("abc\\x00\\x01\\");
@ -466,11 +496,13 @@ public class TestBytes extends TestCase {
}
}
@Test
public void testToStringBinary_toBytesBinary_Reversable() {
String bytes = Bytes.toStringBinary(Bytes.toBytes(2.17));
assertEquals(2.17, Bytes.toDouble(Bytes.toBytesBinary(bytes)), 0);
}
@Test
public void testUnsignedBinarySearch(){
byte[] bytes = new byte[] { 0,5,123,127,-128,-100,-1 };
Assert.assertEquals(1, Bytes.unsignedBinarySearch(bytes, 0, bytes.length, (byte)5));
@ -482,6 +514,7 @@ public class TestBytes extends TestCase {
Assert.assertEquals(-6-1, Bytes.unsignedBinarySearch(bytes, 0, bytes.length, (byte)-5));
}
@Test
public void testUnsignedIncrement(){
byte[] a = Bytes.toBytes(0);
int a2 = Bytes.toInt(Bytes.unsignedCopyAndIncrement(a), 0);
@ -498,6 +531,7 @@ public class TestBytes extends TestCase {
Assert.assertEquals(256, c2);
}
@Test
public void testIndexOf() {
byte[] array = Bytes.toBytes("hello");
assertEquals(1, Bytes.indexOf(array, (byte) 'e'));
@ -508,6 +542,7 @@ public class TestBytes extends TestCase {
assertEquals(-1, Bytes.indexOf(array, Bytes.toBytes("hll")));
}
@Test
public void testContains() {
byte[] array = Bytes.toBytes("hello world");
assertTrue(Bytes.contains(array, (byte) 'e'));
@ -518,6 +553,7 @@ public class TestBytes extends TestCase {
assertFalse(Bytes.contains(array, Bytes.toBytes("owo")));
}
@Test
public void testZero() {
byte[] array = Bytes.toBytes("hello");
Bytes.zero(array);
@ -536,6 +572,7 @@ public class TestBytes extends TestCase {
}
}
@Test
public void testPutBuffer() {
byte[] b = new byte[100];
for (byte i = 0; i < 100; i++) {
@ -546,6 +583,7 @@ public class TestBytes extends TestCase {
}
}
@Test
public void testToFromHex() {
List<String> testStrings = new ArrayList<>(8);
testStrings.addAll(Arrays.asList("", "00", "A0", "ff", "FFffFFFFFFFFFF", "12",

View File

@ -17,6 +17,10 @@
*/
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.StringWriter;
import java.util.HashSet;
@ -24,7 +28,6 @@ import java.util.Map;
import java.util.Set;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import junit.framework.TestCase;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
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
* to its output in XML and JSON format.
*/
@Category({MiscTests.class, SmallTests.class})
public class TestConfServlet extends TestCase {
@Category({ MiscTests.class, SmallTests.class })
public class TestConfServlet {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =

View File

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

View File

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

View File

@ -17,24 +17,29 @@
*/
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.DataOutputStream;
import java.io.IOException;
import junit.framework.TestCase;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@Category({IOTests.class, SmallTests.class})
public class TestImmutableBytesWritable extends TestCase {
@Category({ IOTests.class, SmallTests.class })
public class TestImmutableBytesWritable {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestImmutableBytesWritable.class);
@Test
public void testHash() throws Exception {
assertEquals(
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());
}
@Test
public void testSpecificCompare() {
ImmutableBytesWritable ibw1 = new ImmutableBytesWritable(new byte[]{0x0f});
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 );
}
@Test
public void testComparison() throws Exception {
runTests("aa", "b", -1);
runTests("aa", "aa", 0);

View File

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

View File

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

View File

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

View File

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

View File

@ -17,24 +17,29 @@
*/
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.DataOutputStream;
import java.nio.ByteBuffer;
import junit.framework.TestCase;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.nio.MultiByteBuff;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@Category({MiscTests.class, SmallTests.class})
public class TestBloomFilterChunk extends TestCase {
public class TestBloomFilterChunk {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestBloomFilterChunk.class);
@Test
public void testBasicBloom() throws Exception {
BloomFilterChunk bf1 = 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
}
@Test
public void testBloomFold() throws Exception {
// test: foldFactor < log(max/actual)
BloomFilterChunk b = new BloomFilterChunk(1003, (float) 0.01,
@ -123,6 +129,7 @@ public class TestBloomFilterChunk extends TestCase {
// test: foldFactor > log(max/actual)
}
@Test
public void testBloomPerf() throws Exception {
// add
float err = (float)0.01;
@ -166,6 +173,7 @@ public class TestBloomFilterChunk extends TestCase {
// test: foldFactor > log(max/actual)
}
@Test
public void testSizing() {
int bitSize = 8 * 128 * 1024; // 128 KB
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);
}
@Test
public void testFoldableByteSize() {
assertEquals(128, BloomFilterUtil.computeFoldableByteSize(1000, 5));
assertEquals(640, BloomFilterUtil.computeFoldableByteSize(5001, 4));
}
}

View File

@ -17,35 +17,47 @@
*/
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.HBaseTestingUtil;
import org.apache.hadoop.hbase.security.UserProvider;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@Category({MiscTests.class, MediumTests.class})
public class TestConnectionCache extends TestCase {
@Category({ MiscTests.class, MediumTests.class })
public class TestConnectionCache {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestConnectionCache.class);
HBaseClassTestRule.forClass(TestConnectionCache.class);
private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();
@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
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(),
UserProvider.instantiate(UTIL.getConfiguration()), 1000, 5000);
UserProvider.instantiate(UTIL.getConfiguration()), 1000, 5000);
ConnectionCache.ConnectionInfo info = cache.getCurrentConnection();
assertEquals(false, info.connection.isClosed());
@ -53,8 +65,5 @@ public class TestConnectionCache extends TestCase {
Thread.sleep(7000);
assertEquals(true, info.connection.isClosed());
UTIL.shutdownMiniCluster();
}
}

View File

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

View File

@ -1475,6 +1475,14 @@
<bannedImport>com.fasterxml.jackson.jaxrs.**</bannedImport>
</bannedImports>
</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>
</configuration>
</execution>