HBASE-23626 Reduced number of Checkstyle violations in tests in hbase-common

Signed-off-by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
Jan Hentschel 2019-12-29 22:39:09 +01:00 committed by GitHub
parent c6a9a4d410
commit 923ba7763e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 355 additions and 335 deletions

View File

@ -17,6 +17,8 @@
*/
package org.apache.hadoop.hbase.net;
import static org.junit.Assert.assertEquals;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
@ -24,8 +26,6 @@ import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import static org.junit.Assert.assertEquals;
@Category({ MiscTests.class, SmallTests.class })
public class TestAddress {
@ClassRule

View File

@ -47,12 +47,11 @@ import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
@Category({MiscTests.class, SmallTests.class})
public class TestStruct {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestStruct.class);
@Parameterized.Parameter(value = 0)
@Parameterized.Parameter()
public Struct generic;
@SuppressWarnings("rawtypes")
@ -88,15 +87,20 @@ public class TestStruct {
return Arrays.asList(params);
}
static final Comparator<byte[]> NULL_SAFE_BYTES_COMPARATOR =
new Comparator<byte[]>() {
@Override
public int compare(byte[] o1, byte[] o2) {
if (o1 == o2) return 0;
if (null == o1) return -1;
if (null == o2) return 1;
return Bytes.compareTo(o1, o2);
static final Comparator<byte[]> NULL_SAFE_BYTES_COMPARATOR = (o1, o2) -> {
if (o1 == o2) {
return 0;
}
if (null == o1) {
return -1;
}
if (null == o2) {
return 1;
}
return Bytes.compareTo(o1, o2);
};
/**
@ -134,7 +138,7 @@ public class TestStruct {
if (cmp != 0) {
return cmp;
}
cmp = Integer.valueOf(intFieldAsc).compareTo(Integer.valueOf(o.intFieldAsc));
cmp = Integer.compare(intFieldAsc, o.intFieldAsc);
if (cmp != 0) {
return cmp;
}
@ -173,13 +177,10 @@ public class TestStruct {
return false;
}
if (stringFieldAsc == null) {
if (other.stringFieldAsc != null) {
return false;
return other.stringFieldAsc == null;
} else {
return stringFieldAsc.equals(other.stringFieldAsc);
}
} else if (!stringFieldAsc.equals(other.stringFieldAsc)) {
return false;
}
return true;
}
}
@ -225,16 +226,17 @@ public class TestStruct {
if (cmp != 0) {
return cmp;
}
if (null == stringFieldDsc) {
cmp = 1;
}
else if (null == o.stringFieldDsc) {
} else if (null == o.stringFieldDsc) {
cmp = -1;
}
else if (stringFieldDsc.equals(o.stringFieldDsc)) {
} else if (stringFieldDsc.equals(o.stringFieldDsc)) {
cmp = 0;
} else {
cmp = -stringFieldDsc.compareTo(o.stringFieldDsc);
}
else cmp = -stringFieldDsc.compareTo(o.stringFieldDsc);
if (cmp != 0) {
return cmp;
}
@ -274,13 +276,10 @@ public class TestStruct {
return false;
}
if (stringFieldDsc == null) {
if (other.stringFieldDsc != null) {
return false;
return other.stringFieldDsc == null;
} else {
return stringFieldDsc.equals(other.stringFieldDsc);
}
} else if (!stringFieldDsc.equals(other.stringFieldDsc)) {
return false;
}
return true;
}
}
@ -288,7 +287,6 @@ public class TestStruct {
* A custom data type implementation specialized for {@link Pojo1}.
*/
private static class SpecializedPojo1Type1 implements DataType<Pojo1> {
private static final RawStringTerminated stringField = new RawStringTerminated("/");
private static final RawInteger intField = new RawInteger();
private static final RawDouble doubleField = new RawDouble();
@ -296,34 +294,40 @@ public class TestStruct {
/**
* The {@link Struct} equivalent of this type.
*/
public static Struct GENERIC =
new StructBuilder().add(stringField)
.add(intField)
.add(doubleField)
.toStruct();
public static Struct GENERIC = new StructBuilder().add(stringField).add(intField)
.add(doubleField).toStruct();
@Override
public boolean isOrderPreserving() { return true; }
public boolean isOrderPreserving() {
return true;
}
@Override
public Order getOrder() { return null; }
public Order getOrder() {
return null;
}
@Override
public boolean isNullable() { return false; }
public boolean isNullable() {
return false;
}
@Override
public boolean isSkippable() { return true; }
public boolean isSkippable() {
return true;
}
@Override
public int encodedLength(Pojo1 val) {
return
stringField.encodedLength(val.stringFieldAsc) +
return stringField.encodedLength(val.stringFieldAsc) +
intField.encodedLength(val.intFieldAsc) +
doubleField.encodedLength(val.doubleFieldAsc);
}
@Override
public Class<Pojo1> encodedClass() { return Pojo1.class; }
public Class<Pojo1> encodedClass() {
return Pojo1.class;
}
@Override
public int skip(PositionedByteRange src) {
@ -355,7 +359,6 @@ public class TestStruct {
* A custom data type implementation specialized for {@link Pojo2}.
*/
private static class SpecializedPojo2Type1 implements DataType<Pojo2> {
private static RawBytesTerminated byteField1 = new RawBytesTerminated("/");
private static RawBytesTerminated byteField2 =
new RawBytesTerminated(Order.DESCENDING, "/");
@ -366,36 +369,41 @@ public class TestStruct {
/**
* The {@link Struct} equivalent of this type.
*/
public static Struct GENERIC =
new StructBuilder().add(byteField1)
.add(byteField2)
.add(stringField)
.add(byteField3)
.toStruct();
public static Struct GENERIC = new StructBuilder().add(byteField1).add(byteField2)
.add(stringField).add(byteField3).toStruct();
@Override
public boolean isOrderPreserving() { return true; }
public boolean isOrderPreserving() {
return true;
}
@Override
public Order getOrder() { return null; }
public Order getOrder() {
return null;
}
@Override
public boolean isNullable() { return false; }
public boolean isNullable() {
return false;
}
@Override
public boolean isSkippable() { return true; }
public boolean isSkippable() {
return true;
}
@Override
public int encodedLength(Pojo2 val) {
return
byteField1.encodedLength(val.byteField1Asc) +
return byteField1.encodedLength(val.byteField1Asc) +
byteField2.encodedLength(val.byteField2Dsc) +
stringField.encodedLength(val.stringFieldDsc) +
byteField3.encodedLength(val.byteField3Dsc);
}
@Override
public Class<Pojo2> encodedClass() { return Pojo2.class; }
public Class<Pojo2> encodedClass() {
return Pojo2.class;
}
@Override
public int skip(PositionedByteRange src) {

View File

@ -18,7 +18,6 @@
package org.apache.hadoop.hbase.types;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MiscTests;
@ -32,7 +31,6 @@ import org.junit.experimental.categories.Category;
@Category({ MiscTests.class, SmallTests.class })
public class TestUnion2 {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestUnion2.class);
@ -41,7 +39,6 @@ public class TestUnion2 {
* An example <code>Union</code>
*/
private static class SampleUnion1 extends Union2<Integer, String> {
private static final byte IS_INTEGER = 0x00;
private static final byte IS_STRING = 0x01;
@ -79,13 +76,19 @@ public class TestUnion2 {
String s = null;
try {
i = (Integer) val;
} catch (ClassCastException e) {}
} catch (ClassCastException ignored) {}
try {
s = (String) val;
} catch (ClassCastException e) {}
} catch (ClassCastException ignored) {}
if (null != i) {
return 1 + typeA.encodedLength(i);
}
if (null != s) {
return 1 + typeB.encodedLength(s);
}
if (null != i) return 1 + typeA.encodedLength(i);
if (null != s) return 1 + typeB.encodedLength(s);
throw new IllegalArgumentException("val is not a valid member of this union.");
}
@ -95,10 +98,10 @@ public class TestUnion2 {
String s = null;
try {
i = (Integer) val;
} catch (ClassCastException e) {}
} catch (ClassCastException ignored) {}
try {
s = (String) val;
} catch (ClassCastException e) {}
} catch (ClassCastException ignored) {}
if (null != i) {
dst.put(IS_INTEGER);
@ -106,31 +109,31 @@ public class TestUnion2 {
} else if (null != s) {
dst.put(IS_STRING);
return 1 + typeB.encode(dst, s);
}
else
} else {
throw new IllegalArgumentException("val is not of a supported type.");
}
}
}
@Test
public void testEncodeDecode() {
Integer intVal = Integer.valueOf(10);
Integer intVal = 10;
String strVal = "hello";
PositionedByteRange buff = new SimplePositionedMutableByteRange(10);
SampleUnion1 type = new SampleUnion1();
type.encode(buff, intVal);
buff.setPosition(0);
assertTrue(0 == intVal.compareTo(type.decodeA(buff)));
assertEquals(0, intVal.compareTo(type.decodeA(buff)));
buff.setPosition(0);
type.encode(buff, strVal);
buff.setPosition(0);
assertTrue(0 == strVal.compareTo(type.decodeB(buff)));
assertEquals(0, strVal.compareTo(type.decodeB(buff)));
}
@Test
public void testSkip() {
Integer intVal = Integer.valueOf(10);
Integer intVal = 10;
String strVal = "hello";
PositionedByteRange buff = new SimplePositionedMutableByteRange(10);
SampleUnion1 type = new SampleUnion1();

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.hbase.util;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.BufferedWriter;
import java.io.File;
@ -43,11 +44,14 @@ import org.slf4j.LoggerFactory;
/**
* Some utilities to help class loader testing
*/
public class ClassLoaderTestHelper {
public final class ClassLoaderTestHelper {
private static final Logger LOG = LoggerFactory.getLogger(ClassLoaderTestHelper.class);
private static final int BUFFER_SIZE = 4096;
private ClassLoaderTestHelper() {
}
/**
* Jar a list of files into a jar archive.
*
@ -57,28 +61,29 @@ public class ClassLoaderTestHelper {
*/
private static boolean createJarArchive(File archiveFile, File[] tobeJared) {
try {
byte buffer[] = new byte[BUFFER_SIZE];
byte[] buffer = new byte[BUFFER_SIZE];
// Open archive file
FileOutputStream stream = new FileOutputStream(archiveFile);
JarOutputStream out = new JarOutputStream(stream, new Manifest());
for (int i = 0; i < tobeJared.length; i++) {
if (tobeJared[i] == null || !tobeJared[i].exists()
|| tobeJared[i].isDirectory()) {
for (File file : tobeJared) {
if (file == null || !file.exists() || file.isDirectory()) {
continue;
}
// Add archive entry
JarEntry jarAdd = new JarEntry(tobeJared[i].getName());
jarAdd.setTime(tobeJared[i].lastModified());
JarEntry jarAdd = new JarEntry(file.getName());
jarAdd.setTime(file.lastModified());
out.putNextEntry(jarAdd);
// Write file to archive
FileInputStream in = new FileInputStream(tobeJared[i]);
FileInputStream in = new FileInputStream(file);
while (true) {
int nRead = in.read(buffer, 0, buffer.length);
if (nRead <= 0)
if (nRead <= 0) {
break;
}
out.write(buffer, 0, nRead);
}
in.close();
@ -163,7 +168,7 @@ public class ClassLoaderTestHelper {
jarFile.getParentFile().mkdirs();
if (!createJarArchive(jarFile,
new File[]{new File(srcDir.toString(), className + ".class")})){
assertTrue("Build jar file failed.", false);
fail("Build jar file failed.");
}
return jarFile;
}
@ -183,7 +188,7 @@ public class ClassLoaderTestHelper {
String libPrefix, File... srcJars) throws Exception {
FileOutputStream stream = new FileOutputStream(targetJar);
JarOutputStream out = new JarOutputStream(stream, new Manifest());
byte buffer[] = new byte[BUFFER_SIZE];
byte[] buffer = new byte[BUFFER_SIZE];
for (File jarFile: srcJars) {
// Add archive entry
@ -195,8 +200,10 @@ public class ClassLoaderTestHelper {
FileInputStream in = new FileInputStream(jarFile);
while (true) {
int nRead = in.read(buffer, 0, buffer.length);
if (nRead <= 0)
if (nRead <= 0) {
break;
}
out.write(buffer, 0, nRead);
}
in.close();
@ -210,5 +217,4 @@ public class ClassLoaderTestHelper {
return conf.get(ClassLoaderBase.LOCAL_DIR_KEY)
+ File.separator + "jars" + File.separator;
}
}

View File

@ -23,7 +23,9 @@ package org.apache.hadoop.hbase.util;
* the use of the injectEdge method giving it default permissions, but in
* testing we may need to use this functionality elsewhere.
*/
public class EnvironmentEdgeManagerTestHelper {
public final class EnvironmentEdgeManagerTestHelper {
private EnvironmentEdgeManagerTestHelper() {
}
public static void reset() {
EnvironmentEdgeManager.reset();

View File

@ -17,6 +17,7 @@
*/
package org.apache.hadoop.hbase.util;
import static org.junit.Assert.assertArrayEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
@ -41,7 +42,6 @@ import org.junit.experimental.categories.Category;
@Category({MiscTests.class, SmallTests.class})
public class TestBytes extends TestCase {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestBytes.class);
@ -99,7 +99,7 @@ public class TestBytes extends TestCase {
assertNotNull(ee);
}
public void testAdd () throws Exception {
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};
byte[] c = {2,2,2,2,2,2,2,2,2,2,2,2};
@ -112,41 +112,41 @@ public class TestBytes extends TestCase {
assertEquals(0, Bytes.compareTo(result1, result2));
}
public void testSplit() throws Exception {
public void testSplit() {
byte[] lowest = Bytes.toBytes("AAA");
byte[] middle = Bytes.toBytes("CCC");
byte[] highest = Bytes.toBytes("EEE");
byte[][] parts = Bytes.split(lowest, highest, 1);
for (int i = 0; i < parts.length; i++) {
System.out.println(Bytes.toString(parts[i]));
for (byte[] bytes : parts) {
System.out.println(Bytes.toString(bytes));
}
assertEquals(3, parts.length);
assertTrue(Bytes.equals(parts[1], middle));
// Now divide into three parts. Change highest so split is even.
highest = Bytes.toBytes("DDD");
parts = Bytes.split(lowest, highest, 2);
for (int i = 0; i < parts.length; i++) {
System.out.println(Bytes.toString(parts[i]));
for (byte[] part : parts) {
System.out.println(Bytes.toString(part));
}
assertEquals(4, parts.length);
// Assert that 3rd part is 'CCC'.
assertTrue(Bytes.equals(parts[2], middle));
}
public void testSplit2() throws Exception {
public void testSplit2() {
// More split tests.
byte [] lowest = Bytes.toBytes("http://A");
byte [] highest = Bytes.toBytes("http://z");
byte [] middle = Bytes.toBytes("http://]");
byte [][] parts = Bytes.split(lowest, highest, 1);
for (int i = 0; i < parts.length; i++) {
System.out.println(Bytes.toString(parts[i]));
for (byte[] part : parts) {
System.out.println(Bytes.toString(part));
}
assertEquals(3, parts.length);
assertTrue(Bytes.equals(parts[1], middle));
}
public void testSplit3() throws Exception {
public void testSplit3() {
// Test invalid split cases
byte[] low = { 1, 1, 1 };
byte[] high = { 1, 1, 3 };
@ -154,7 +154,7 @@ public class TestBytes extends TestCase {
// If swapped, should throw IAE
try {
Bytes.split(high, low, 1);
assertTrue("Should not be able to split if low > high", false);
fail("Should not be able to split if low > high");
} catch(IllegalArgumentException iae) {
// Correct
}
@ -164,72 +164,72 @@ public class TestBytes extends TestCase {
for (int i = 0; i < parts.length; i++) {
System.out.println("" + i + " -> " + Bytes.toStringBinary(parts[i]));
}
assertTrue("Returned split should have 3 parts but has " + parts.length, parts.length == 3);
assertEquals("Returned split should have 3 parts but has " + parts.length, 3, parts.length);
// If split more than once, use additional byte to split
parts = Bytes.split(low, high, 2);
assertTrue("Split with an additional byte", parts != null);
assertNotNull("Split with an additional byte", parts);
assertEquals(parts.length, low.length + 1);
// Split 0 times should throw IAE
try {
parts = Bytes.split(low, high, 0);
assertTrue("Should not be able to split 0 times", false);
Bytes.split(low, high, 0);
fail("Should not be able to split 0 times");
} catch(IllegalArgumentException iae) {
// Correct
}
}
public void testToInt() throws Exception {
public void testToInt() {
int[] ints = { -1, 123, Integer.MIN_VALUE, Integer.MAX_VALUE };
for (int i = 0; i < ints.length; i++) {
byte [] b = Bytes.toBytes(ints[i]);
assertEquals(ints[i], Bytes.toInt(b));
for (int anInt : ints) {
byte[] b = Bytes.toBytes(anInt);
assertEquals(anInt, Bytes.toInt(b));
byte[] b2 = bytesWithOffset(b);
assertEquals(ints[i], Bytes.toInt(b2, 1));
assertEquals(ints[i], Bytes.toInt(b2, 1, Bytes.SIZEOF_INT));
assertEquals(anInt, Bytes.toInt(b2, 1));
assertEquals(anInt, Bytes.toInt(b2, 1, Bytes.SIZEOF_INT));
}
}
public void testToLong() throws Exception {
long [] longs = {-1l, 123l, Long.MIN_VALUE, Long.MAX_VALUE};
for (int i = 0; i < longs.length; i++) {
byte [] b = Bytes.toBytes(longs[i]);
assertEquals(longs[i], Bytes.toLong(b));
public void testToLong() {
long[] longs = { -1L, 123L, Long.MIN_VALUE, Long.MAX_VALUE };
for (long aLong : longs) {
byte[] b = Bytes.toBytes(aLong);
assertEquals(aLong, Bytes.toLong(b));
byte[] b2 = bytesWithOffset(b);
assertEquals(longs[i], Bytes.toLong(b2, 1));
assertEquals(longs[i], Bytes.toLong(b2, 1, Bytes.SIZEOF_LONG));
assertEquals(aLong, Bytes.toLong(b2, 1));
assertEquals(aLong, Bytes.toLong(b2, 1, Bytes.SIZEOF_LONG));
}
}
public void testToFloat() throws Exception {
public void testToFloat() {
float[] floats = { -1f, 123.123f, Float.MAX_VALUE };
for (int i = 0; i < floats.length; i++) {
byte [] b = Bytes.toBytes(floats[i]);
assertEquals(floats[i], Bytes.toFloat(b), 0.0f);
for (float aFloat : floats) {
byte[] b = Bytes.toBytes(aFloat);
assertEquals(aFloat, Bytes.toFloat(b), 0.0f);
byte[] b2 = bytesWithOffset(b);
assertEquals(floats[i], Bytes.toFloat(b2, 1), 0.0f);
assertEquals(aFloat, Bytes.toFloat(b2, 1), 0.0f);
}
}
public void testToDouble() throws Exception {
public void testToDouble() {
double [] doubles = {Double.MIN_VALUE, Double.MAX_VALUE};
for (int i = 0; i < doubles.length; i++) {
byte [] b = Bytes.toBytes(doubles[i]);
assertEquals(doubles[i], Bytes.toDouble(b), 0.0);
for (double aDouble : doubles) {
byte[] b = Bytes.toBytes(aDouble);
assertEquals(aDouble, Bytes.toDouble(b), 0.0);
byte[] b2 = bytesWithOffset(b);
assertEquals(doubles[i], Bytes.toDouble(b2, 1), 0.0);
assertEquals(aDouble, Bytes.toDouble(b2, 1), 0.0);
}
}
public void testToBigDecimal() throws Exception {
public void testToBigDecimal() {
BigDecimal[] decimals = { new BigDecimal("-1"), new BigDecimal("123.123"),
new BigDecimal("123123123123") };
for (int i = 0; i < decimals.length; i++) {
byte [] b = Bytes.toBytes(decimals[i]);
assertEquals(decimals[i], Bytes.toBigDecimal(b));
for (BigDecimal decimal : decimals) {
byte[] b = Bytes.toBytes(decimal);
assertEquals(decimal, Bytes.toBigDecimal(b));
byte[] b2 = bytesWithOffset(b);
assertEquals(decimals[i], Bytes.toBigDecimal(b2, 1, b.length));
assertEquals(decimal, Bytes.toBigDecimal(b2, 1, b.length));
}
}
@ -249,7 +249,7 @@ public class TestBytes extends TestCase {
byte[] actual = Bytes.toBytes(target);
byte[] expected = { 0, 1, 2, 3, 4, 5, 6 };
assertTrue(Arrays.equals(expected, actual));
assertArrayEquals(expected, actual);
assertEquals(2, target.position());
assertEquals(7, target.limit());
@ -259,7 +259,7 @@ public class TestBytes extends TestCase {
byte[] actual2 = Bytes.toBytes(target2);
byte[] expected2 = { 2, 3, 4, 5, 6 };
assertTrue(Arrays.equals(expected2, actual2));
assertArrayEquals(expected2, actual2);
assertEquals(0, target2.position());
assertEquals(5, target2.limit());
}
@ -272,21 +272,21 @@ public class TestBytes extends TestCase {
byte[] actual = Bytes.getBytes(target);
byte[] expected = { 2, 3, 4, 5, 6 };
assertTrue(Arrays.equals(expected, actual));
assertArrayEquals(expected, actual);
assertEquals(2, target.position());
assertEquals(7, target.limit());
}
public void testReadAsVLong() throws Exception {
long [] longs = {-1l, 123l, Long.MIN_VALUE, Long.MAX_VALUE};
for (int i = 0; i < longs.length; i++) {
long[] longs = { -1L, 123L, Long.MIN_VALUE, Long.MAX_VALUE };
for (long aLong : longs) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(baos);
WritableUtils.writeVLong(output, longs[i]);
WritableUtils.writeVLong(output, aLong);
byte[] long_bytes_no_offset = baos.toByteArray();
assertEquals(longs[i], Bytes.readAsVLong(long_bytes_no_offset, 0));
assertEquals(aLong, Bytes.readAsVLong(long_bytes_no_offset, 0));
byte[] long_bytes_with_offset = bytesWithOffset(long_bytes_no_offset);
assertEquals(longs[i], Bytes.readAsVLong(long_bytes_with_offset, 1));
assertEquals(aLong, Bytes.readAsVLong(long_bytes_with_offset, 1));
}
}
@ -317,7 +317,7 @@ public class TestBytes extends TestCase {
assertEquals(expected, actual);
}
public void testBinarySearch() throws Exception {
public void testBinarySearch() {
byte[][] arr = {
{ 1 },
{ 3 },
@ -389,8 +389,7 @@ public class TestBytes extends TestCase {
assertFalse(Bytes.startsWith(Bytes.toBytes(""), Bytes.toBytes("hello")));
}
public void testIncrementBytes() throws IOException {
public void testIncrementBytes() {
assertTrue(checkTestIncrementBytes(10, 1));
assertTrue(checkTestIncrementBytes(12, 123435445));
assertTrue(checkTestIncrementBytes(124634654, 1));
@ -410,8 +409,7 @@ public class TestBytes extends TestCase {
assertTrue(checkTestIncrementBytes(-1546543452, -34565445));
}
private static boolean checkTestIncrementBytes(long val, long amount)
throws IOException {
private static boolean checkTestIncrementBytes(long val, long amount) {
byte[] value = Bytes.toBytes(val);
byte[] testValue = { -1, -1, -1, -1, -1, -1, -1, -1 };
if (value[0] > 0) {
@ -450,14 +448,14 @@ public class TestBytes extends TestCase {
assertEquals("", Bytes.readStringFixedSize(dis, 9));
}
public void testCopy() throws Exception {
public void testCopy() {
byte[] bytes = Bytes.toBytes("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
byte[] copy = Bytes.copy(bytes);
assertFalse(bytes == copy);
assertNotSame(bytes, copy);
assertTrue(Bytes.equals(bytes, copy));
}
public void testToBytesBinaryTrailingBackslashes() throws Exception {
public void testToBytesBinaryTrailingBackslashes() {
try {
Bytes.toBytesBinary("abc\\x00\\x01\\");
} catch (StringIndexOutOfBoundsException ex) {
@ -465,7 +463,7 @@ public class TestBytes extends TestCase {
}
}
public void testToStringBinary_toBytesBinary_Reversable() throws Exception {
public void testToStringBinary_toBytesBinary_Reversable() {
String bytes = Bytes.toStringBinary(Bytes.toBytes(2.17));
assertEquals(2.17, Bytes.toDouble(Bytes.toBytesBinary(bytes)), 0);
}
@ -484,17 +482,17 @@ public class TestBytes extends TestCase {
public void testUnsignedIncrement(){
byte[] a = Bytes.toBytes(0);
int a2 = Bytes.toInt(Bytes.unsignedCopyAndIncrement(a), 0);
Assert.assertTrue(a2==1);
Assert.assertEquals(1, a2);
byte[] b = Bytes.toBytes(-1);
byte[] actual = Bytes.unsignedCopyAndIncrement(b);
Assert.assertNotSame(b, actual);
byte[] expected = new byte[]{1,0,0,0,0};
Assert.assertArrayEquals(expected, actual);
assertArrayEquals(expected, actual);
byte[] c = Bytes.toBytes(255);//should wrap to the next significant byte
int c2 = Bytes.toInt(Bytes.unsignedCopyAndIncrement(c), 0);
Assert.assertTrue(c2==256);
Assert.assertEquals(256, c2);
}
public void testIndexOf() {
@ -520,8 +518,8 @@ public class TestBytes extends TestCase {
public void testZero() {
byte[] array = Bytes.toBytes("hello");
Bytes.zero(array);
for (int i = 0; i < array.length; i++) {
assertEquals(0, array[i]);
for (byte b : array) {
assertEquals(0, b);
}
array = Bytes.toBytes("hello world");
Bytes.zero(array, 2, 7);
@ -547,18 +545,9 @@ public class TestBytes extends TestCase {
public void testToFromHex() {
List<String> testStrings = new ArrayList<>(8);
testStrings.addAll(Arrays.asList(new String[] {
"",
"00",
"A0",
"ff",
"FFffFFFFFFFFFF",
"12",
"0123456789abcdef",
"283462839463924623984692834692346ABCDFEDDCA0",
}));
for (String testString : testStrings)
{
testStrings.addAll(Arrays.asList("", "00", "A0", "ff", "FFffFFFFFFFFFF", "12",
"0123456789abcdef", "283462839463924623984692834692346ABCDFEDDCA0"));
for (String testString : testStrings) {
byte[] byteData = Bytes.fromHex(testString);
Assert.assertEquals(testString.length() / 2, byteData.length);
String result = Bytes.toHex(byteData);
@ -566,27 +555,20 @@ public class TestBytes extends TestCase {
}
List<byte[]> testByteData = new ArrayList<>(5);
testByteData.addAll(Arrays.asList(new byte[][] {
new byte[0],
new byte[1],
new byte[10],
new byte[] {1, 2, 3, 4, 5},
new byte[] {(byte) 0xFF},
}));
testByteData.addAll(Arrays.asList(new byte[0], new byte[1], new byte[10],
new byte[] { 1, 2, 3, 4, 5 }, new byte[] { (byte) 0xFF }));
Random r = new Random();
for (int i = 0; i < 20; i++)
{
for (int i = 0; i < 20; i++) {
byte[] bytes = new byte[r.nextInt(100)];
r.nextBytes(bytes);
testByteData.add(bytes);
}
for (byte[] testData : testByteData)
{
for (byte[] testData : testByteData) {
String hexString = Bytes.toHex(testData);
Assert.assertEquals(testData.length * 2, hexString.length());
byte[] result = Bytes.fromHex(hexString);
Assert.assertArrayEquals(testData, result);
assertArrayEquals(testData, result);
}
}
}

View File

@ -42,7 +42,6 @@ import org.junit.experimental.categories.Category;
*/
@Category({MiscTests.class, SmallTests.class})
public class TestCoprocessorClassLoader {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestCoprocessorClassLoader.class);
@ -60,7 +59,11 @@ public class TestCoprocessorClassLoader {
File jarFile = ClassLoaderTestHelper.buildJar(
folder, className, null, ClassLoaderTestHelper.localDirPath(conf));
File tmpJarFile = new File(jarFile.getParent(), "/tmp/" + className + ".test.jar");
if (tmpJarFile.exists()) tmpJarFile.delete();
if (tmpJarFile.exists()) {
tmpJarFile.delete();
}
assertFalse("tmp jar file should not exist", tmpJarFile.exists());
ClassLoader parent = TestCoprocessorClassLoader.class.getClassLoader();
CoprocessorClassLoader.getClassLoader(new Path(jarFile.getParent()), parent, "112", conf);
@ -133,12 +136,10 @@ public class TestCoprocessorClassLoader {
ClassLoader parent = TestCoprocessorClassLoader.class.getClassLoader();
CoprocessorClassLoader.parentDirLockSet.clear(); // So that clean up can be triggered
CoprocessorClassLoader coprocessorClassLoader = null;
Path testPath = null;
// Directory
testPath = new Path(localDirContainingJar);
coprocessorClassLoader = CoprocessorClassLoader.getClassLoader(testPath, parent, "113_1", conf);
Path testPath = new Path(localDirContainingJar);
CoprocessorClassLoader coprocessorClassLoader = CoprocessorClassLoader.getClassLoader(testPath,
parent, "113_1", conf);
verifyCoprocessorClassLoader(coprocessorClassLoader, testClassName);
// Wildcard - *.jar
@ -156,10 +157,11 @@ public class TestCoprocessorClassLoader {
* Verify the coprocessorClassLoader is not null and the expected class can be loaded successfully
* @param coprocessorClassLoader the CoprocessorClassLoader to verify
* @param className the expected class to be loaded by the coprocessorClassLoader
* @throws ClassNotFoundException
* @throws ClassNotFoundException if the class, which should be loaded via the
* coprocessorClassLoader, does not exist
*/
private void verifyCoprocessorClassLoader(CoprocessorClassLoader coprocessorClassLoader, String className)
throws ClassNotFoundException{
private void verifyCoprocessorClassLoader(CoprocessorClassLoader coprocessorClassLoader,
String className) throws ClassNotFoundException {
assertNotNull("Classloader should be created and not null", coprocessorClassLoader);
assertEquals(className, coprocessorClassLoader.loadClass(className).getName());
}

View File

@ -116,12 +116,13 @@ public class TestOrderedBytes {
*/
@Test
public void testVaruint64Boundaries() {
long vals[] =
{ 239L, 240L, 2286L, 2287L, 67822L, 67823L, 16777214L, 16777215L, 4294967294L, 4294967295L,
long[] vals = {
239L, 240L, 2286L, 2287L, 67822L, 67823L, 16777214L, 16777215L, 4294967294L, 4294967295L,
1099511627774L, 1099511627775L, 281474976710654L, 281474976710655L, 72057594037927934L,
72057594037927935L, Long.MAX_VALUE - 1, Long.MAX_VALUE, Long.MIN_VALUE + 1,
Long.MIN_VALUE, -2L, -1L };
int lens[] = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9 };
Long.MIN_VALUE, -2L, -1L
};
int[] lens = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9 };
assertEquals("Broken test!", vals.length, lens.length);
/*
@ -208,8 +209,12 @@ public class TestOrderedBytes {
Arrays.sort(encoded, Bytes.BYTES_COMPARATOR);
Long[] sortedVals = Arrays.copyOf(I_VALS, I_VALS.length);
if (ord == Order.ASCENDING) Arrays.sort(sortedVals);
else Arrays.sort(sortedVals, Collections.reverseOrder());
if (ord == Order.ASCENDING) {
Arrays.sort(sortedVals);
} else {
Arrays.sort(sortedVals, Collections.reverseOrder());
}
for (int i = 0; i < sortedVals.length; i++) {
pbr.set(encoded[i]);
@ -256,8 +261,8 @@ public class TestOrderedBytes {
// verify decode
buf1.setPosition(1);
assertEquals("Deserialization failed.",
D_VALS[i].doubleValue(), OrderedBytes.decodeNumericAsDouble(buf1), MIN_EPSILON);
assertEquals("Deserialization failed.", D_VALS[i],
OrderedBytes.decodeNumericAsDouble(buf1), MIN_EPSILON);
assertEquals("Did not consume enough bytes.", D_LENGTHS[i], buf1.getPosition() - 1);
}
}
@ -275,8 +280,12 @@ public class TestOrderedBytes {
Arrays.sort(encoded, Bytes.BYTES_COMPARATOR);
Double[] sortedVals = Arrays.copyOf(D_VALS, D_VALS.length);
if (ord == Order.ASCENDING) Arrays.sort(sortedVals);
else Arrays.sort(sortedVals, Collections.reverseOrder());
if (ord == Order.ASCENDING) {
Arrays.sort(sortedVals);
} else {
Arrays.sort(sortedVals, Collections.reverseOrder());
}
for (int i = 0; i < sortedVals.length; i++) {
pbr.set(encoded[i]);
@ -284,8 +293,7 @@ public class TestOrderedBytes {
assertEquals(
String.format(
"Encoded representations do not preserve natural order: <%s>, <%s>, %s",
sortedVals[i], decoded, ord),
sortedVals[i].doubleValue(), decoded, MIN_EPSILON);
sortedVals[i], decoded, ord), sortedVals[i], decoded, MIN_EPSILON);
}
}
}
@ -378,17 +386,16 @@ public class TestOrderedBytes {
* starting at an offset to detect over/underflow conditions.
*/
for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
for (int i = 0; i < vals.length; i++) {
for (Byte val : vals) {
// allocate a buffer 3-bytes larger than necessary to detect over/underflow
byte[] a = new byte[2 + 3];
PositionedByteRange buf1 = new SimplePositionedMutableByteRange(a, 1, 2 + 1);
buf1.setPosition(1);
// verify encode
assertEquals("Surprising return value.",
2, OrderedBytes.encodeInt8(buf1, vals[i], ord));
assertEquals("Broken test: serialization did not consume entire buffer.",
buf1.getLength(), buf1.getPosition());
assertEquals("Surprising return value.", 2, OrderedBytes.encodeInt8(buf1, val, ord));
assertEquals("Broken test: serialization did not consume entire buffer.", buf1.getLength(),
buf1.getPosition());
assertEquals("Surprising serialized length.", 2, buf1.getPosition() - 1);
assertEquals("Buffer underflow.", 0, a[0]);
assertEquals("Buffer underflow.", 0, a[1]);
@ -401,8 +408,7 @@ public class TestOrderedBytes {
// verify decode
buf1.setPosition(1);
assertEquals("Deserialization failed.",
vals[i].byteValue(), OrderedBytes.decodeInt8(buf1));
assertEquals("Deserialization failed.", val.byteValue(), OrderedBytes.decodeInt8(buf1));
assertEquals("Did not consume enough bytes.", 2, buf1.getPosition() - 1);
}
}
@ -419,8 +425,12 @@ public class TestOrderedBytes {
Arrays.sort(encoded, Bytes.BYTES_COMPARATOR);
Byte[] sortedVals = Arrays.copyOf(vals, vals.length);
if (ord == Order.ASCENDING) Arrays.sort(sortedVals);
else Arrays.sort(sortedVals, Collections.reverseOrder());
if (ord == Order.ASCENDING) {
Arrays.sort(sortedVals);
} else {
Arrays.sort(sortedVals, Collections.reverseOrder());
}
for (int i = 0; i < sortedVals.length; i++) {
int decoded = OrderedBytes.decodeInt8(pbr.set(encoded[i]));
@ -446,17 +456,16 @@ public class TestOrderedBytes {
* starting at an offset to detect over/underflow conditions.
*/
for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
for (int i = 0; i < vals.length; i++) {
for (Short val : vals) {
// allocate a buffer 3-bytes larger than necessary to detect over/underflow
byte[] a = new byte[3 + 3];
PositionedByteRange buf1 = new SimplePositionedMutableByteRange(a, 1, 3 + 1);
buf1.setPosition(1);
// verify encode
assertEquals("Surprising return value.",
3, OrderedBytes.encodeInt16(buf1, vals[i], ord));
assertEquals("Broken test: serialization did not consume entire buffer.",
buf1.getLength(), buf1.getPosition());
assertEquals("Surprising return value.", 3, OrderedBytes.encodeInt16(buf1, val, ord));
assertEquals("Broken test: serialization did not consume entire buffer.", buf1.getLength(),
buf1.getPosition());
assertEquals("Surprising serialized length.", 3, buf1.getPosition() - 1);
assertEquals("Buffer underflow.", 0, a[0]);
assertEquals("Buffer underflow.", 0, a[1]);
@ -469,8 +478,7 @@ public class TestOrderedBytes {
// verify decode
buf1.setPosition(1);
assertEquals("Deserialization failed.",
vals[i].shortValue(), OrderedBytes.decodeInt16(buf1));
assertEquals("Deserialization failed.", val.shortValue(), OrderedBytes.decodeInt16(buf1));
assertEquals("Did not consume enough bytes.", 3, buf1.getPosition() - 1);
}
}
@ -487,8 +495,12 @@ public class TestOrderedBytes {
Arrays.sort(encoded, Bytes.BYTES_COMPARATOR);
Short[] sortedVals = Arrays.copyOf(vals, vals.length);
if (ord == Order.ASCENDING) Arrays.sort(sortedVals);
else Arrays.sort(sortedVals, Collections.reverseOrder());
if (ord == Order.ASCENDING) {
Arrays.sort(sortedVals);
} else {
Arrays.sort(sortedVals, Collections.reverseOrder());
}
for (int i = 0; i < sortedVals.length; i++) {
int decoded = OrderedBytes.decodeInt16(pbr.set(encoded[i]));
@ -514,17 +526,16 @@ public class TestOrderedBytes {
* starting at an offset to detect over/underflow conditions.
*/
for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
for (int i = 0; i < vals.length; i++) {
for (Integer val : vals) {
// allocate a buffer 3-bytes larger than necessary to detect over/underflow
byte[] a = new byte[5 + 3];
PositionedByteRange buf1 = new SimplePositionedMutableByteRange(a, 1, 5 + 1);
buf1.setPosition(1);
// verify encode
assertEquals("Surprising return value.",
5, OrderedBytes.encodeInt32(buf1, vals[i], ord));
assertEquals("Broken test: serialization did not consume entire buffer.",
buf1.getLength(), buf1.getPosition());
assertEquals("Surprising return value.", 5, OrderedBytes.encodeInt32(buf1, val, ord));
assertEquals("Broken test: serialization did not consume entire buffer.", buf1.getLength(),
buf1.getPosition());
assertEquals("Surprising serialized length.", 5, buf1.getPosition() - 1);
assertEquals("Buffer underflow.", 0, a[0]);
assertEquals("Buffer underflow.", 0, a[1]);
@ -537,8 +548,7 @@ public class TestOrderedBytes {
// verify decode
buf1.setPosition(1);
assertEquals("Deserialization failed.",
vals[i].intValue(), OrderedBytes.decodeInt32(buf1));
assertEquals("Deserialization failed.", val.intValue(), OrderedBytes.decodeInt32(buf1));
assertEquals("Did not consume enough bytes.", 5, buf1.getPosition() - 1);
}
}
@ -555,8 +565,12 @@ public class TestOrderedBytes {
Arrays.sort(encoded, Bytes.BYTES_COMPARATOR);
Integer[] sortedVals = Arrays.copyOf(vals, vals.length);
if (ord == Order.ASCENDING) Arrays.sort(sortedVals);
else Arrays.sort(sortedVals, Collections.reverseOrder());
if (ord == Order.ASCENDING) {
Arrays.sort(sortedVals);
} else {
Arrays.sort(sortedVals, Collections.reverseOrder());
}
for (int i = 0; i < sortedVals.length; i++) {
int decoded = OrderedBytes.decodeInt32(pbr.set(encoded[i]));
@ -581,17 +595,16 @@ public class TestOrderedBytes {
* starting at an offset to detect over/underflow conditions.
*/
for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
for (int i = 0; i < vals.length; i++) {
for (Long val : vals) {
// allocate a buffer 3-bytes larger than necessary to detect over/underflow
byte[] a = new byte[9 + 3];
PositionedByteRange buf1 = new SimplePositionedMutableByteRange(a, 1, 9 + 1);
buf1.setPosition(1);
// verify encode
assertEquals("Surprising return value.",
9, OrderedBytes.encodeInt64(buf1, vals[i], ord));
assertEquals("Broken test: serialization did not consume entire buffer.",
buf1.getLength(), buf1.getPosition());
assertEquals("Surprising return value.", 9, OrderedBytes.encodeInt64(buf1, val, ord));
assertEquals("Broken test: serialization did not consume entire buffer.", buf1.getLength(),
buf1.getPosition());
assertEquals("Surprising serialized length.", 9, buf1.getPosition() - 1);
assertEquals("Buffer underflow.", 0, a[0]);
assertEquals("Buffer underflow.", 0, a[1]);
@ -604,8 +617,7 @@ public class TestOrderedBytes {
// verify decode
buf1.setPosition(1);
assertEquals("Deserialization failed.",
vals[i].longValue(), OrderedBytes.decodeInt64(buf1));
assertEquals("Deserialization failed.", val.longValue(), OrderedBytes.decodeInt64(buf1));
assertEquals("Did not consume enough bytes.", 9, buf1.getPosition() - 1);
}
}
@ -622,8 +634,12 @@ public class TestOrderedBytes {
Arrays.sort(encoded, Bytes.BYTES_COMPARATOR);
Long[] sortedVals = Arrays.copyOf(vals, vals.length);
if (ord == Order.ASCENDING) Arrays.sort(sortedVals);
else Arrays.sort(sortedVals, Collections.reverseOrder());
if (ord == Order.ASCENDING) {
Arrays.sort(sortedVals);
} else {
Arrays.sort(sortedVals, Collections.reverseOrder());
}
for (int i = 0; i < sortedVals.length; i++) {
long decoded = OrderedBytes.decodeInt64(pbr.set(encoded[i]));
@ -649,17 +665,16 @@ public class TestOrderedBytes {
* starting at an offset to detect over/underflow conditions.
*/
for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
for (int i = 0; i < vals.length; i++) {
for (Float val : vals) {
// allocate a buffer 3-bytes larger than necessary to detect over/underflow
byte[] a = new byte[5 + 3];
PositionedByteRange buf1 = new SimplePositionedMutableByteRange(a, 1, 5 + 1);
buf1.setPosition(1);
// verify encode
assertEquals("Surprising return value.",
5, OrderedBytes.encodeFloat32(buf1, vals[i], ord));
assertEquals("Broken test: serialization did not consume entire buffer.",
buf1.getLength(), buf1.getPosition());
assertEquals("Surprising return value.", 5, OrderedBytes.encodeFloat32(buf1, val, ord));
assertEquals("Broken test: serialization did not consume entire buffer.", buf1.getLength(),
buf1.getPosition());
assertEquals("Surprising serialized length.", 5, buf1.getPosition() - 1);
assertEquals("Buffer underflow.", 0, a[0]);
assertEquals("Buffer underflow.", 0, a[1]);
@ -672,8 +687,7 @@ public class TestOrderedBytes {
// verify decode
buf1.setPosition(1);
assertEquals("Deserialization failed.",
Float.floatToIntBits(vals[i].floatValue()),
assertEquals("Deserialization failed.", Float.floatToIntBits(val),
Float.floatToIntBits(OrderedBytes.decodeFloat32(buf1)));
assertEquals("Did not consume enough bytes.", 5, buf1.getPosition() - 1);
}
@ -691,8 +705,12 @@ public class TestOrderedBytes {
Arrays.sort(encoded, Bytes.BYTES_COMPARATOR);
Float[] sortedVals = Arrays.copyOf(vals, vals.length);
if (ord == Order.ASCENDING) Arrays.sort(sortedVals);
else Arrays.sort(sortedVals, Collections.reverseOrder());
if (ord == Order.ASCENDING) {
Arrays.sort(sortedVals);
} else {
Arrays.sort(sortedVals, Collections.reverseOrder());
}
for (int i = 0; i < sortedVals.length; i++) {
float decoded = OrderedBytes.decodeFloat32(pbr.set(encoded[i]));
@ -700,7 +718,7 @@ public class TestOrderedBytes {
String.format(
"Encoded representations do not preserve natural order: <%s>, <%s>, %s",
sortedVals[i], decoded, ord),
Float.floatToIntBits(sortedVals[i].floatValue()),
Float.floatToIntBits(sortedVals[i]),
Float.floatToIntBits(decoded));
}
}
@ -719,17 +737,16 @@ public class TestOrderedBytes {
* starting at an offset to detect over/underflow conditions.
*/
for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
for (int i = 0; i < vals.length; i++) {
for (Double val : vals) {
// allocate a buffer 3-bytes larger than necessary to detect over/underflow
byte[] a = new byte[9 + 3];
PositionedByteRange buf1 = new SimplePositionedMutableByteRange(a, 1, 9 + 1);
buf1.setPosition(1);
// verify encode
assertEquals("Surprising return value.",
9, OrderedBytes.encodeFloat64(buf1, vals[i], ord));
assertEquals("Broken test: serialization did not consume entire buffer.",
buf1.getLength(), buf1.getPosition());
assertEquals("Surprising return value.", 9, OrderedBytes.encodeFloat64(buf1, val, ord));
assertEquals("Broken test: serialization did not consume entire buffer.", buf1.getLength(),
buf1.getPosition());
assertEquals("Surprising serialized length.", 9, buf1.getPosition() - 1);
assertEquals("Buffer underflow.", 0, a[0]);
assertEquals("Buffer underflow.", 0, a[1]);
@ -742,8 +759,7 @@ public class TestOrderedBytes {
// verify decode
buf1.setPosition(1);
assertEquals("Deserialization failed.",
Double.doubleToLongBits(vals[i].doubleValue()),
assertEquals("Deserialization failed.", Double.doubleToLongBits(val),
Double.doubleToLongBits(OrderedBytes.decodeFloat64(buf1)));
assertEquals("Did not consume enough bytes.", 9, buf1.getPosition() - 1);
}
@ -761,8 +777,12 @@ public class TestOrderedBytes {
Arrays.sort(encoded, Bytes.BYTES_COMPARATOR);
Double[] sortedVals = Arrays.copyOf(vals, vals.length);
if (ord == Order.ASCENDING) Arrays.sort(sortedVals);
else Arrays.sort(sortedVals, Collections.reverseOrder());
if (ord == Order.ASCENDING) {
Arrays.sort(sortedVals);
} else {
Arrays.sort(sortedVals, Collections.reverseOrder());
}
for (int i = 0; i < sortedVals.length; i++) {
double decoded = OrderedBytes.decodeFloat64(pbr.set(encoded[i]));
@ -770,7 +790,7 @@ public class TestOrderedBytes {
String.format(
"Encoded representations do not preserve natural order: <%s>, <%s>, %s",
sortedVals[i], decoded, ord),
Double.doubleToLongBits(sortedVals[i].doubleValue()),
Double.doubleToLongBits(sortedVals[i]),
Double.doubleToLongBits(decoded));
}
}
@ -782,7 +802,7 @@ public class TestOrderedBytes {
@Test
public void testString() {
String[] vals = { "foo", "baaaar", "bazz" };
int expectedLengths[] = { 5, 8, 6 };
int[] expectedLengths = { 5, 8, 6 };
/*
* assert encoded values match decoded values. encode into target buffer
@ -831,8 +851,12 @@ public class TestOrderedBytes {
Arrays.sort(encoded, Bytes.BYTES_COMPARATOR);
String[] sortedVals = Arrays.copyOf(vals, vals.length);
if (ord == Order.ASCENDING) Arrays.sort(sortedVals);
else Arrays.sort(sortedVals, Collections.reverseOrder());
if (ord == Order.ASCENDING) {
Arrays.sort(sortedVals);
} else {
Arrays.sort(sortedVals, Collections.reverseOrder());
}
for (int i = 0; i < sortedVals.length; i++) {
pbr.set(encoded[i]);
@ -952,8 +976,12 @@ public class TestOrderedBytes {
Arrays.sort(encoded, Bytes.BYTES_COMPARATOR);
byte[][] sortedVals = Arrays.copyOf(vals, vals.length);
if (ord == Order.ASCENDING) Arrays.sort(sortedVals, Bytes.BYTES_COMPARATOR);
else Arrays.sort(sortedVals, Collections.reverseOrder(Bytes.BYTES_COMPARATOR));
if (ord == Order.ASCENDING) {
Arrays.sort(sortedVals, Bytes.BYTES_COMPARATOR);
} else {
Arrays.sort(sortedVals, Collections.reverseOrder(Bytes.BYTES_COMPARATOR));
}
for (int i = 0; i < sortedVals.length; i++) {
pbr.set(encoded[i]);
@ -1029,8 +1057,12 @@ public class TestOrderedBytes {
Arrays.sort(encoded, Bytes.BYTES_COMPARATOR);
byte[][] sortedVals = Arrays.copyOf(vals, vals.length);
if (ord == Order.ASCENDING) Arrays.sort(sortedVals, Bytes.BYTES_COMPARATOR);
else Arrays.sort(sortedVals, Collections.reverseOrder(Bytes.BYTES_COMPARATOR));
if (ord == Order.ASCENDING) {
Arrays.sort(sortedVals, Bytes.BYTES_COMPARATOR);
} else {
Arrays.sort(sortedVals, Collections.reverseOrder(Bytes.BYTES_COMPARATOR));
}
for (int i = 0; i < sortedVals.length; i++) {
pbr.set(encoded[i]);
@ -1082,7 +1114,7 @@ public class TestOrderedBytes {
BigDecimal negLarge = longMax.multiply(longMax).negate();
BigDecimal negMed = new BigDecimal("-10.0");
BigDecimal negSmall = new BigDecimal("-0.0010");
long zero = 0l;
long zero = 0L;
BigDecimal posSmall = negSmall.negate();
BigDecimal posMed = negMed.negate();
BigDecimal posLarge = negLarge.negate();
@ -1091,7 +1123,7 @@ public class TestOrderedBytes {
byte int8 = 100;
short int16 = 100;
int int32 = 100;
long int64 = 100l;
long int64 = 100L;
float float32 = 100.0f;
double float64 = 100.0d;
String text = "hello world.";
@ -1213,7 +1245,7 @@ public class TestOrderedBytes {
BigDecimal negLarge = longMax.multiply(longMax).negate();
BigDecimal negMed = new BigDecimal("-10.0");
BigDecimal negSmall = new BigDecimal("-0.0010");
long zero = 0l;
long zero = 0L;
BigDecimal posSmall = negSmall.negate();
BigDecimal posMed = negMed.negate();
BigDecimal posLarge = negLarge.negate();
@ -1222,7 +1254,7 @@ public class TestOrderedBytes {
byte int8 = 100;
short int16 = 100;
int int32 = 100;
long int64 = 100l;
long int64 = 100L;
float float32 = 100.0f;
double float64 = 100.0d;
String text = "hello world.";

View File

@ -38,9 +38,7 @@ public class TestSimplePositionedMutableByteRange {
PositionedByteRange r = new SimplePositionedMutableByteRange(new byte[5], 1, 3);
// exercise single-byte put
r.put(Bytes.toBytes("f")[0])
.put(Bytes.toBytes("o")[0])
.put(Bytes.toBytes("o")[0]);
r.put(Bytes.toBytes("f")[0]).put(Bytes.toBytes("o")[0]).put(Bytes.toBytes("o")[0]);
Assert.assertEquals(3, r.getPosition());
Assert.assertArrayEquals(
new byte[] { 0, Bytes.toBytes("f")[0], Bytes.toBytes("o")[0], Bytes.toBytes("o")[0], 0 },
@ -48,9 +46,7 @@ public class TestSimplePositionedMutableByteRange {
// exercise multi-byte put
r.setPosition(0);
r.put(Bytes.toBytes("f"))
.put(Bytes.toBytes("o"))
.put(Bytes.toBytes("o"));
r.put(Bytes.toBytes("f")).put(Bytes.toBytes("o")).put(Bytes.toBytes("o"));
Assert.assertEquals(3, r.getPosition());
Assert.assertArrayEquals(
new byte[] { 0, Bytes.toBytes("f")[0], Bytes.toBytes("o")[0], Bytes.toBytes("o")[0], 0 },
@ -76,7 +72,7 @@ public class TestSimplePositionedMutableByteRange {
}
@Test
public void testPutAndGetPrimitiveTypes() throws Exception {
public void testPutAndGetPrimitiveTypes() {
PositionedByteRange pbr = new SimplePositionedMutableByteRange(100);
int i1 = 18, i2 = 2;
short s1 = 0;
@ -102,7 +98,7 @@ public class TestSimplePositionedMutableByteRange {
}
@Test
public void testPutGetAPIsCompareWithBBAPIs() throws Exception {
public void testPutGetAPIsCompareWithBBAPIs() {
// confirm that the long/int/short writing is same as BBs
PositionedByteRange pbr = new SimplePositionedMutableByteRange(100);
int i1 = -234, i2 = 2;

View File

@ -16,7 +16,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.util;
import org.apache.yetus.audience.InterfaceAudience;
@ -25,19 +24,10 @@ import org.apache.yetus.audience.InterfaceAudience;
public class TimeOffsetEnvironmentEdge implements EnvironmentEdge {
private long offset;
public TimeOffsetEnvironmentEdge(){}
public void setTimeOffset(long off){
this.offset = off;
public TimeOffsetEnvironmentEdge() {
}
public long getTimeOffset()
{
return offset;
}
public void increment(long incr)
{
public void increment(long incr) {
this.offset += incr;
}
@ -45,5 +35,4 @@ public class TimeOffsetEnvironmentEdge implements EnvironmentEdge {
public long currentTime() {
return System.currentTimeMillis() + offset;
}
}