Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D8C69200D6A for ; Sat, 16 Dec 2017 01:18:24 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id D6C04160C29; Sat, 16 Dec 2017 00:18:24 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A9F0B160C14 for ; Sat, 16 Dec 2017 01:18:22 +0100 (CET) Received: (qmail 19307 invoked by uid 500); 16 Dec 2017 00:18:21 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 19286 invoked by uid 99); 16 Dec 2017 00:18:21 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Dec 2017 00:18:21 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7DCEBDFBD3; Sat, 16 Dec 2017 00:18:21 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: stack@apache.org To: commits@hbase.apache.org Date: Sat, 16 Dec 2017 00:18:21 -0000 Message-Id: <8182f93da86048079c42ec1bc07ed214@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/4] hbase git commit: HBASE-19497 Fix findbugs and error-prone warnings in hbase-common (branch-2) Signed-off-by: Apekshit Sharma archived-at: Sat, 16 Dec 2017 00:18:25 -0000 Repository: hbase Updated Branches: refs/heads/branch-2 2043c337d -> 4c2b2b3e6 http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCompoundConfiguration.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCompoundConfiguration.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCompoundConfiguration.java index 0a0a1d2..2b565f4 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCompoundConfiguration.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCompoundConfiguration.java @@ -19,25 +19,28 @@ */ package org.apache.hadoop.hbase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + import java.util.HashMap; import java.util.Map; -import junit.framework.TestCase; - import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.Bytes; +import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; @Category({MiscTests.class, SmallTests.class}) -public class TestCompoundConfiguration extends TestCase { +public class TestCompoundConfiguration { private Configuration baseConf; private int baseConfSize; - @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { baseConf = new Configuration(); baseConf.set("A", "1"); baseConf.setInt("B", 2); @@ -104,12 +107,15 @@ public class TestCompoundConfiguration extends TestCase { assertEquals(4, compoundConf.getInt("D", 0)); assertNull(compoundConf.get("E")); assertEquals(6, compoundConf.getInt("F", 6)); - + int cnt = 0; for (Map.Entry entry : compoundConf) { cnt++; - if (entry.getKey().equals("B")) assertEquals("2b", entry.getValue()); - else if (entry.getKey().equals("G")) assertEquals(null, entry.getValue()); + if (entry.getKey().equals("B")) { + assertEquals("2b", entry.getValue()); + } else if (entry.getKey().equals("G")) { + assertNull(entry.getValue()); + } } // verify that entries from ImmutableConfigMap's are merged in the iterator's view assertEquals(baseConfSize + 1, cnt); @@ -139,12 +145,15 @@ public class TestCompoundConfiguration extends TestCase { assertNull(compoundConf.get("E")); assertEquals(6, compoundConf.getInt("F", 6)); assertNull(compoundConf.get("G")); - + int cnt = 0; for (Map.Entry entry : compoundConf) { cnt++; - if (entry.getKey().equals("B")) assertEquals("2b", entry.getValue()); - else if (entry.getKey().equals("G")) assertEquals(null, entry.getValue()); + if (entry.getKey().equals("B")) { + assertEquals("2b", entry.getValue()); + } else if (entry.getKey().equals("G")) { + assertNull(entry.getValue()); + } } // verify that entries from ImmutableConfigMap's are merged in the iterator's view assertEquals(baseConfSize + 2, cnt); @@ -180,12 +189,15 @@ public class TestCompoundConfiguration extends TestCase { int cnt = 0; for (Map.Entry entry : compoundConf) { cnt++; - if (entry.getKey().equals("B")) assertEquals("2b", entry.getValue()); - else if (entry.getKey().equals("G")) assertEquals(null, entry.getValue()); + if (entry.getKey().equals("B")) { + assertEquals("2b", entry.getValue()); + } else if (entry.getKey().equals("G")) { + assertNull(entry.getValue()); + } } // verify that entries from ImmutableConfigMap's are merged in the iterator's view assertEquals(4, cnt); - + // Verify that adding map after compound configuration is modified overrides properly CompoundConfiguration conf2 = new CompoundConfiguration(); conf2.set("X", "modification"); @@ -218,8 +230,11 @@ public class TestCompoundConfiguration extends TestCase { int cnt = 0; for (Map.Entry entry : compoundConf) { cnt++; - if (entry.getKey().equals("A")) assertEquals(newValueForA, entry.getValue()); - else if (entry.getKey().equals("B")) assertEquals(newValueForB, entry.getValue()); + if (entry.getKey().equals("A")) { + assertEquals(newValueForA, entry.getValue()); + } else if (entry.getKey().equals("B")) { + assertEquals(newValueForB, entry.getValue()); + } } // verify that entries from ImmutableConfigMap's are merged in the iterator's view assertEquals(baseConfSize + 1, cnt); http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/TestHBaseConfiguration.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestHBaseConfiguration.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestHBaseConfiguration.java index b713ff6..abb6a28 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestHBaseConfiguration.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestHBaseConfiguration.java @@ -192,10 +192,9 @@ public class TestHBaseConfiguration { } // Instantiate Hadoop CredentialProviderFactory try { - hadoopCredProviderFactory = hadoopCredProviderFactoryClz.newInstance(); - } catch (InstantiationException e) { - return false; - } catch (IllegalAccessException e) { + hadoopCredProviderFactory = + hadoopCredProviderFactoryClz.getDeclaredConstructor().newInstance(); + } catch (Exception e) { return false; } http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/TestIndividualBytesFieldCell.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestIndividualBytesFieldCell.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestIndividualBytesFieldCell.java index 9abf908..e255677 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestIndividualBytesFieldCell.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestIndividualBytesFieldCell.java @@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; import java.nio.ByteBuffer; + import org.apache.hadoop.hbase.io.ByteArrayOutputStream; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; @@ -117,15 +118,16 @@ public class TestIndividualBytesFieldCell { * @param ic An instance of IndividualBytesFieldCell to compare. * @param kv An instance of KeyValue to compare. * @param withTags Whether to write tags. - * @throws IOException */ private void testWriteIntoOutputStream(IndividualBytesFieldCell ic, KeyValue kv, boolean withTags) throws IOException { ByteArrayOutputStream outIC = new ByteArrayOutputStream(ic.getSerializedSize(withTags)); ByteArrayOutputStream outKV = new ByteArrayOutputStream(kv.getSerializedSize(withTags)); - assertEquals(kv.write(outKV, withTags), ic.write(outIC, withTags)); // compare the number of bytes written - assertArrayEquals(outKV.getBuffer(), outIC.getBuffer()); // compare the underlying byte array + // compare the number of bytes written + assertEquals(kv.write(outKV, withTags), ic.write(outIC, withTags)); + // compare the underlying byte array + assertArrayEquals(outKV.getBuffer(), outIC.getBuffer()); } /** @@ -146,15 +148,21 @@ public class TestIndividualBytesFieldCell { byte[] value = null; byte[] tags = null; - Cell ic1 = new IndividualBytesFieldCell(row, family, qualifier, timestamp, type, seqId, value, tags); + Cell ic1 = + new IndividualBytesFieldCell(row, family, qualifier, timestamp, type, seqId, value, tags); Cell kv1 = new KeyValue(row, family, qualifier, timestamp, type, value, tags); - byte[] familyArrayInKV = Bytes.copy(kv1.getFamilyArray() , kv1.getFamilyOffset() , kv1.getFamilyLength()); - byte[] qualifierArrayInKV = Bytes.copy(kv1.getQualifierArray(), kv1.getQualifierOffset(), kv1.getQualifierLength()); - byte[] valueArrayInKV = Bytes.copy(kv1.getValueArray() , kv1.getValueOffset() , kv1.getValueLength()); - byte[] tagsArrayInKV = Bytes.copy(kv1.getTagsArray() , kv1.getTagsOffset() , kv1.getTagsLength()); - - // getXXXArray() for family, qualifier, value and tags are supposed to return empty byte array, rather than null. + byte[] familyArrayInKV = + Bytes.copy(kv1.getFamilyArray(), kv1.getFamilyOffset(), kv1.getFamilyLength()); + byte[] qualifierArrayInKV = + Bytes.copy(kv1.getQualifierArray(), kv1.getQualifierOffset(), kv1.getQualifierLength()); + byte[] valueArrayInKV = + Bytes.copy(kv1.getValueArray(), kv1.getValueOffset(), kv1.getValueLength()); + byte[] tagsArrayInKV = + Bytes.copy(kv1.getTagsArray(), kv1.getTagsOffset(), kv1.getTagsLength()); + + // getXXXArray() for family, qualifier, value and tags are supposed to return empty byte array, + // rather than null. assertArrayEquals(familyArrayInKV , ic1.getFamilyArray()); assertArrayEquals(qualifierArrayInKV, ic1.getQualifierArray()); assertArrayEquals(valueArrayInKV , ic1.getValueArray()); http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java index 45adc98..86891ae 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java @@ -18,6 +18,8 @@ */ package org.apache.hadoop.hbase; +import static org.junit.Assert.assertNotEquals; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; @@ -30,15 +32,12 @@ import java.util.Set; import java.util.TreeSet; import junit.framework.TestCase; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hbase.KeyValue.Type; import org.apache.hadoop.hbase.util.ByteBufferUtils; import org.apache.hadoop.hbase.util.Bytes; -import static org.junit.Assert.assertNotEquals; - public class TestKeyValue extends TestCase { private static final Log LOG = LogFactory.getLog(TestKeyValue.class); @@ -582,7 +581,7 @@ public class TestKeyValue extends TestCase { assertTrue(kvA2.equals(deSerKV2)); } - private class MockKeyValue implements Cell { + private static class MockKeyValue implements Cell { private final KeyValue kv; public MockKeyValue(KeyValue kv) { http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java index 54e25e8..3bf05c4 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java @@ -17,18 +17,18 @@ */ package org.apache.hadoop.hbase; -import java.nio.ByteBuffer; -import java.util.HashMap; -import java.util.Map; - import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; -import org.apache.hadoop.hbase.testclassification.MiscTests; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; + import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.util.Bytes; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -54,22 +54,23 @@ public class TestTableName extends TestWatcher { return tableName; } - String emptyNames[] ={"", " "}; - String invalidNamespace[] = {":a", "%:a"}; - String legalTableNames[] = { "foo", "with-dash_under.dot", "_under_start_ok", - "with-dash.with_underscore", "02-01-2012.my_table_01-02", "xyz._mytable_", "9_9_0.table_02" - , "dot1.dot2.table", "new.-mytable", "with-dash.with.dot", "legal..t2", "legal..legal.t2", - "trailingdots..", "trailing.dots...", "ns:mytable", "ns:_mytable_", "ns:my_table_01-02"}; - String illegalTableNames[] = { ".dot_start_illegal", "-dash_start_illegal", "spaces not ok", - "-dash-.start_illegal", "new.table with space", "01 .table", "ns:-illegaldash", - "new:.illegaldot", "new:illegalcolon1:", "new:illegalcolon1:2"}; + String[] emptyNames = {"", " "}; + String[] invalidNamespace = {":a", "%:a"}; + String[] legalTableNames = {"foo", "with-dash_under.dot", "_under_start_ok", + "with-dash.with_underscore", "02-01-2012.my_table_01-02", "xyz._mytable_", "9_9_0.table_02", + "dot1.dot2.table", "new.-mytable", "with-dash.with.dot", "legal..t2", "legal..legal.t2", + "trailingdots..", "trailing.dots...", "ns:mytable", "ns:_mytable_", "ns:my_table_01-02"}; + String[] illegalTableNames = {".dot_start_illegal", "-dash_start_illegal", "spaces not ok", + "-dash-.start_illegal", "new.table with space", "01 .table", "ns:-illegaldash", + "new:.illegaldot", "new:illegalcolon1:", "new:illegalcolon1:2"}; @Test(expected = IllegalArgumentException.class) public void testInvalidNamespace() { for (String tn : invalidNamespace) { TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn)); - fail("invalid namespace " + tn + " should have failed with IllegalArgumentException for namespace"); + fail("invalid namespace " + tn + + " should have failed with IllegalArgumentException for namespace"); } } @@ -108,7 +109,7 @@ public class TestTableName extends TestWatcher { } } - class Names { + static class Names { String ns; byte[] nsb; String tn; @@ -118,22 +119,30 @@ public class TestTableName extends TestWatcher { Names(String ns, String tn) { this.ns = ns; - nsb = ns.getBytes(); + nsb = ns.getBytes(StandardCharsets.UTF_8); this.tn = tn; - tnb = tn.getBytes(); + tnb = tn.getBytes(StandardCharsets.UTF_8); nn = this.ns + ":" + this.tn; - nnb = nn.getBytes(); + nnb = nn.getBytes(StandardCharsets.UTF_8); } @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } Names names = (Names) o; - if (!ns.equals(names.ns)) return false; - if (!tn.equals(names.tn)) return false; + if (!ns.equals(names.ns)) { + return false; + } + if (!tn.equals(names.tn)) { + return false; + } return true; } @@ -147,16 +156,16 @@ public class TestTableName extends TestWatcher { } Names[] names = new Names[] { - new Names("n1", "n1"), - new Names("n2", "n2"), - new Names("table1", "table1"), - new Names("table2", "table2"), - new Names("table2", "table1"), - new Names("table1", "table2"), - new Names("n1", "table1"), - new Names("n1", "table1"), - new Names("n2", "table2"), - new Names("n2", "table2") + new Names("n1", "n1"), + new Names("n2", "n2"), + new Names("table1", "table1"), + new Names("table2", "table2"), + new Names("table2", "table1"), + new Names("table1", "table2"), + new Names("n1", "table1"), + new Names("n1", "table1"), + new Names("n2", "table2"), + new Names("n2", "table2") }; @Test http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java index 65fae46..fc4a2be 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java @@ -18,8 +18,8 @@ package org.apache.hadoop.hbase; import org.apache.hadoop.hbase.testclassification.SmallTests; -import org.junit.Rule; import org.junit.Ignore; +import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.rules.TestRule; http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/Waiter.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/Waiter.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/Waiter.java index d0ad81d..6ee52cb 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/Waiter.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/Waiter.java @@ -19,6 +19,8 @@ package org.apache.hadoop.hbase; +import static org.junit.Assert.fail; + import java.text.MessageFormat; import org.apache.commons.logging.Log; @@ -26,8 +28,6 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.yetus.audience.InterfaceAudience; -import static org.junit.Assert.fail; - /** * A class that provides a standard waitFor pattern * See details at https://issues.apache.org/jira/browse/HBASE-7384 http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodecWithTags.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodecWithTags.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodecWithTags.java index fad30de..78b84f7 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodecWithTags.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodecWithTags.java @@ -35,14 +35,15 @@ import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.RawCell; import org.apache.hadoop.hbase.Tag; -import org.apache.hadoop.hbase.shaded.com.google.common.io.CountingInputStream; -import org.apache.hadoop.hbase.shaded.com.google.common.io.CountingOutputStream; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.Bytes; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.apache.hadoop.hbase.shaded.com.google.common.io.CountingInputStream; +import org.apache.hadoop.hbase.shaded.com.google.common.io.CountingOutputStream; + @Category({MiscTests.class, SmallTests.class}) public class TestCellCodecWithTags { http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodec.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodec.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodec.java index 128ef62..48239fb 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodec.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodec.java @@ -68,7 +68,7 @@ public class TestKeyValueCodec { Codec.Encoder encoder = kvc.getEncoder(dos); final KeyValue kv = new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("q"), Bytes.toBytes("v")); - final long length = kv.getLength() + Bytes.SIZEOF_INT; + final int length = kv.getLength() + Bytes.SIZEOF_INT; encoder.write(kv); encoder.flush(); dos.close(); @@ -98,7 +98,7 @@ public class TestKeyValueCodec { new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("2"), Bytes.toBytes("2")); final KeyValue kv3 = new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("3"), Bytes.toBytes("3")); - final long length = kv1.getLength() + Bytes.SIZEOF_INT; + final int length = kv1.getLength() + Bytes.SIZEOF_INT; encoder.write(kv1); encoder.write(kv2); encoder.write(kv3); http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodecWithTags.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodecWithTags.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodecWithTags.java index 27c6430..c35f434 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodecWithTags.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodecWithTags.java @@ -35,14 +35,15 @@ import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.RawCell; import org.apache.hadoop.hbase.Tag; -import org.apache.hadoop.hbase.shaded.com.google.common.io.CountingInputStream; -import org.apache.hadoop.hbase.shaded.com.google.common.io.CountingOutputStream; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.Bytes; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.apache.hadoop.hbase.shaded.com.google.common.io.CountingInputStream; +import org.apache.hadoop.hbase.shaded.com.google.common.io.CountingOutputStream; + @Category({MiscTests.class, SmallTests.class}) public class TestKeyValueCodecWithTags { http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBufferListOutputStream.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBufferListOutputStream.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBufferListOutputStream.java index e1d1e04..d28064c 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBufferListOutputStream.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBufferListOutputStream.java @@ -19,6 +19,7 @@ package org.apache.hadoop.hbase.io; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; + import java.nio.ByteBuffer; import java.util.List; http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBufferPool.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBufferPool.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBufferPool.java index 64a4103..cf1f8ca 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBufferPool.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBufferPool.java @@ -17,13 +17,15 @@ */ package org.apache.hadoop.hbase.io; +import static org.junit.Assert.assertEquals; + import java.nio.ByteBuffer; import org.apache.hadoop.hbase.testclassification.IOTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.junit.Test; import org.junit.experimental.categories.Category; -import static org.junit.Assert.assertEquals; + @Category({ IOTests.class, SmallTests.class }) public class TestByteBufferPool { http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestTagCompressionContext.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestTagCompressionContext.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestTagCompressionContext.java index dddd9e7..5f4115e 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestTagCompressionContext.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestTagCompressionContext.java @@ -26,12 +26,12 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; -import org.apache.hadoop.hbase.KeyValue; -import org.apache.hadoop.hbase.ByteBufferKeyValue; -import org.apache.hadoop.hbase.Tag; import org.apache.hadoop.hbase.ArrayBackedTag; import org.apache.hadoop.hbase.ByteBufferCell; +import org.apache.hadoop.hbase.ByteBufferKeyValue; import org.apache.hadoop.hbase.Cell; +import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.Tag; import org.apache.hadoop.hbase.io.util.LRUDictionary; import org.apache.hadoop.hbase.nio.SingleByteBuff; import org.apache.hadoop.hbase.testclassification.MiscTests; http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/KeyProviderForTesting.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/KeyProviderForTesting.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/KeyProviderForTesting.java index 781924b..9b45d09 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/KeyProviderForTesting.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/KeyProviderForTesting.java @@ -17,7 +17,6 @@ package org.apache.hadoop.hbase.io.crypto; import java.security.Key; - import javax.crypto.spec.SecretKeySpec; /** http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestCipherProvider.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestCipherProvider.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestCipherProvider.java index dbf7fc5..0f45e5d 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestCipherProvider.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestCipherProvider.java @@ -133,8 +133,8 @@ public class TestCipherProvider { Cipher a = Encryption.getCipher(conf, "TEST"); assertNotNull(a); assertTrue(a.getProvider() instanceof MyCipherProvider); - assertEquals(a.getName(), "TEST"); - assertEquals(a.getKeyLength(), 0); + assertEquals("TEST", a.getName()); + assertEquals(0, a.getKeyLength()); } @Test @@ -149,7 +149,7 @@ public class TestCipherProvider { assertNotNull(a); assertTrue(a.getProvider() instanceof DefaultCipherProvider); assertEquals(a.getName(), algorithm); - assertEquals(a.getKeyLength(), AES.KEY_LENGTH); + assertEquals(AES.KEY_LENGTH, a.getKeyLength()); } } http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestEncryption.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestEncryption.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestEncryption.java index 0d38356..07dd601 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestEncryption.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestEncryption.java @@ -22,7 +22,6 @@ import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.security.Key; - import javax.crypto.spec.SecretKeySpec; import org.apache.commons.logging.Log; http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestKeyProvider.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestKeyProvider.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestKeyProvider.java index dab03f2..036ad60 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestKeyProvider.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestKeyProvider.java @@ -44,9 +44,9 @@ public class TestKeyProvider { Key key = provider.getKey("foo"); assertNotNull("Test provider did not return a key as expected", key); - assertEquals("Test provider did not create a key for AES", key.getAlgorithm(), "AES"); - assertEquals("Test provider did not create a key of adequate length", - key.getEncoded().length, AES.KEY_LENGTH); + assertEquals("Test provider did not create a key for AES", "AES", key.getAlgorithm()); + assertEquals("Test provider did not create a key of adequate length", AES.KEY_LENGTH, + key.getEncoded().length); } } http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestKeyStoreKeyProvider.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestKeyStoreKeyProvider.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestKeyStoreKeyProvider.java index 6e9816a..790568e 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestKeyStoreKeyProvider.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestKeyStoreKeyProvider.java @@ -22,11 +22,11 @@ import static org.junit.Assert.assertNotNull; import java.io.File; import java.io.FileOutputStream; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.security.Key; import java.security.KeyStore; import java.security.MessageDigest; import java.util.Properties; - import javax.crypto.spec.SecretKeySpec; import org.apache.commons.logging.Log; @@ -52,7 +52,7 @@ public class TestKeyStoreKeyProvider { @BeforeClass public static void setUp() throws Exception { - KEY = MessageDigest.getInstance("SHA-256").digest(ALIAS.getBytes()); + KEY = MessageDigest.getInstance("SHA-256").digest(ALIAS.getBytes(StandardCharsets.UTF_8)); // Create a JKECS store containing a test secret key KeyStore store = KeyStore.getInstance("JCEKS"); store.load(null, PASSWORD.toCharArray()); http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/aes/TestAES.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/aes/TestAES.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/aes/TestAES.java index ea8879b..d0f2600 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/aes/TestAES.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/aes/TestAES.java @@ -30,7 +30,6 @@ import java.security.Provider; import java.security.SecureRandom; import java.security.SecureRandomSpi; import java.security.Security; - import javax.crypto.spec.SecretKeySpec; import org.apache.commons.io.IOUtils; @@ -55,8 +54,8 @@ public class TestAES { public void testAESAlgorithm() throws Exception { Configuration conf = HBaseConfiguration.create(); Cipher aes = Encryption.getCipher(conf, "AES"); - assertEquals(aes.getKeyLength(), AES.KEY_LENGTH); - assertEquals(aes.getIvLength(), AES.IV_LENGTH); + assertEquals(AES.KEY_LENGTH, aes.getKeyLength()); + assertEquals(AES.IV_LENGTH, aes.getIvLength()); Encryptor e = aes.getEncryptor(); e.setKey(new SecretKeySpec(Bytes.fromHex("2b7e151628aed2a6abf7158809cf4f3c"), "AES")); e.setIv(Bytes.fromHex("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff")); @@ -91,8 +90,7 @@ public class TestAES { DefaultCipherProvider.getInstance().setConf(conf); AES aes = new AES(DefaultCipherProvider.getInstance()); - assertEquals("AES did not find alternate RNG", aes.getRNG().getAlgorithm(), - "TestRNG"); + assertEquals("AES did not find alternate RNG", "TestRNG", aes.getRNG().getAlgorithm()); } static class TestProvider extends Provider { @@ -100,6 +98,7 @@ public class TestAES { public TestProvider() { super("TEST", 1.0, "Test provider"); AccessController.doPrivileged(new PrivilegedAction() { + @Override public Object run() { put("SecureRandom.TestRNG", TestAES.class.getName() + "$TestRNG"); return null; http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/aes/TestCommonsAES.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/aes/TestCommonsAES.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/aes/TestCommonsAES.java index dca62e5..de9b787 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/aes/TestCommonsAES.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/aes/TestCommonsAES.java @@ -16,6 +16,22 @@ */ package org.apache.hadoop.hbase.io.crypto.aes; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.OutputStream; +import java.security.AccessController; +import java.security.NoSuchAlgorithmException; +import java.security.PrivilegedAction; +import java.security.Provider; +import java.security.SecureRandom; +import java.security.SecureRandomSpi; +import java.security.Security; +import javax.crypto.spec.SecretKeySpec; + import org.apache.commons.io.IOUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; @@ -29,14 +45,6 @@ import org.apache.hadoop.hbase.util.Bytes; import org.junit.Test; import org.junit.experimental.categories.Category; -import javax.crypto.spec.SecretKeySpec; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.OutputStream; -import java.security.*; - -import static org.junit.Assert.*; - @Category({MiscTests.class, SmallTests.class}) public class TestCommonsAES { @@ -46,8 +54,8 @@ public class TestCommonsAES { public void testAESAlgorithm() throws Exception { Configuration conf = HBaseConfiguration.create(); Cipher aes = Encryption.getCipher(conf, "AES"); - assertEquals(aes.getKeyLength(), CommonsCryptoAES.KEY_LENGTH); - assertEquals(aes.getIvLength(), CommonsCryptoAES.IV_LENGTH); + assertEquals(CommonsCryptoAES.KEY_LENGTH, aes.getKeyLength()); + assertEquals(CommonsCryptoAES.IV_LENGTH, aes.getIvLength()); Encryptor e = aes.getEncryptor(); e.setKey(new SecretKeySpec(Bytes.fromHex("2b7e151628aed2a6abf7158809cf4f3c"), "AES")); e.setIv(Bytes.fromHex("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff")); @@ -82,8 +90,7 @@ public class TestCommonsAES { DefaultCipherProvider.getInstance().setConf(conf); AES aes = new AES(DefaultCipherProvider.getInstance()); - assertEquals("AES did not find alternate RNG", aes.getRNG().getAlgorithm(), - "TestRNG"); + assertEquals("AES did not find alternate RNG", "TestRNG", aes.getRNG().getAlgorithm()); } static class TestProvider extends Provider { @@ -91,6 +98,7 @@ public class TestCommonsAES { public TestProvider() { super("TEST", 1.0, "Test provider"); AccessController.doPrivileged(new PrivilegedAction() { + @Override public Object run() { put("SecureRandom.TestRNG", TestCommonsAES.class.getName() + "$TestRNG"); return null; http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/io/hadoopbackport/TestThrottledInputStream.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/hadoopbackport/TestThrottledInputStream.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/hadoopbackport/TestThrottledInputStream.java index 15d292d..00bd1fb 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/hadoopbackport/TestThrottledInputStream.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/hadoopbackport/TestThrottledInputStream.java @@ -16,9 +16,10 @@ */ package org.apache.hadoop.hbase.io.hadoopbackport; +import static org.junit.Assert.assertEquals; + import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; -import static org.junit.Assert.assertEquals; import org.junit.Test; import org.junit.experimental.categories.Category; http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/io/util/TestLRUDictionary.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/util/TestLRUDictionary.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/util/TestLRUDictionary.java index 9569ba8..c53c9f5 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/util/TestLRUDictionary.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/util/TestLRUDictionary.java @@ -81,7 +81,7 @@ public class TestLRUDictionary { rand.nextBytes(testBytes); // Verify that our randomly generated array doesn't exist in the dictionary - assertEquals(testee.findEntry(testBytes, 0, testBytes.length), -1); + assertEquals(-1, testee.findEntry(testBytes, 0, testBytes.length)); // now since we looked up an entry, we should have added it to the // dictionary, so it isn't empty http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/nio/TestMultiByteBuff.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/nio/TestMultiByteBuff.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/nio/TestMultiByteBuff.java index 48922d9..3b724b1 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/nio/TestMultiByteBuff.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/nio/TestMultiByteBuff.java @@ -21,6 +21,7 @@ package org.apache.hadoop.hbase.nio; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -102,10 +103,10 @@ public class TestMultiByteBuff { public void testPutPrimitives() { ByteBuffer bb = ByteBuffer.allocate(10); SingleByteBuff s = new SingleByteBuff(bb); - s.putLong(-4465109508325701663l); + s.putLong(-4465109508325701663L); bb.rewind(); long long1 = bb.getLong(); - assertEquals(long1, -4465109508325701663l); + assertEquals(-4465109508325701663L, long1); s.position(8); } @@ -235,18 +236,18 @@ public class TestMultiByteBuff { multi.putLong(l2); multi.rewind(); ByteBuffer sub = multi.asSubByteBuffer(Bytes.SIZEOF_LONG); - assertTrue(bb1 == sub); + assertEquals(bb1, sub); assertEquals(l1, ByteBufferUtils.toLong(sub, sub.position())); multi.skip(Bytes.SIZEOF_LONG); sub = multi.asSubByteBuffer(Bytes.SIZEOF_LONG); - assertFalse(bb1 == sub); - assertFalse(bb2 == sub); + assertNotEquals(bb1, sub); + assertNotEquals(bb2, sub); assertEquals(l2, ByteBufferUtils.toLong(sub, sub.position())); multi.rewind(); ObjectIntPair p = new ObjectIntPair<>(); multi.asSubByteBuffer(8, Bytes.SIZEOF_LONG, p); - assertFalse(bb1 == p.getFirst()); - assertFalse(bb2 == p.getFirst()); + assertNotEquals(bb1, p.getFirst()); + assertNotEquals(bb2, p.getFirst()); assertEquals(0, p.getSecond()); assertEquals(l2, ByteBufferUtils.toLong(sub, p.getSecond())); } @@ -291,7 +292,7 @@ public class TestMultiByteBuff { bres[2] = mbb1.get(4); bres[3] = mbb1.get(5); int expected = Bytes.toInt(bres); - assertEquals(res, expected); + assertEquals(expected, res); } @Test http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestCopyOnWriteMaps.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestCopyOnWriteMaps.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestCopyOnWriteMaps.java index 381d3df..eca6c47 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestCopyOnWriteMaps.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestCopyOnWriteMaps.java @@ -18,18 +18,22 @@ package org.apache.hadoop.hbase.types; -import org.apache.hadoop.hbase.testclassification.MiscTests; -import org.apache.hadoop.hbase.testclassification.SmallTests; -import org.junit.Before; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.util.Map; import java.util.concurrent.ConcurrentNavigableMap; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.ThreadLocalRandom; -import static org.junit.Assert.*; +import org.apache.hadoop.hbase.testclassification.MiscTests; +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; @Category({MiscTests.class, SmallTests.class}) public class TestCopyOnWriteMaps { @@ -258,8 +262,8 @@ public class TestCopyOnWriteMaps { long n = 100L; CopyOnWriteArrayMap tm99 = (CopyOnWriteArrayMap) m.tailMap(99L, false); for (Map.Entry e:tm99.entrySet()) { - assertEquals(new Long(n), e.getKey()); - assertEquals(new Long(n), e.getValue()); + assertEquals(Long.valueOf(n), e.getKey()); + assertEquals(Long.valueOf(n), e.getValue()); n++; } } @@ -277,15 +281,15 @@ public class TestCopyOnWriteMaps { long n = 102; CopyOnWriteArrayMap tm102 = (CopyOnWriteArrayMap) m.tailMap(102L, true); for (Map.Entry e:tm102.entrySet()) { - assertEquals(new Long(n), e.getKey()); - assertEquals(new Long(n), e.getValue()); + assertEquals(Long.valueOf(n), e.getKey()); + assertEquals(Long.valueOf(n), e.getValue()); n++; } n = 99; CopyOnWriteArrayMap tm98 = (CopyOnWriteArrayMap) m.tailMap(98L, true); for (Map.Entry e:tm98.entrySet()) { - assertEquals(new Long(n), e.getKey()); - assertEquals(new Long(n), e.getValue()); + assertEquals(Long.valueOf(n), e.getKey()); + assertEquals(Long.valueOf(n), e.getValue()); n++; } } @@ -302,11 +306,11 @@ public class TestCopyOnWriteMaps { long n = 99; for (Map.Entry e:m.entrySet()) { - assertEquals(new Long(n), e.getKey()); - assertEquals(new Long(n), e.getValue()); + assertEquals(Long.valueOf(n), e.getKey()); + assertEquals(Long.valueOf(n), e.getValue()); n++; } assertEquals(5, m.size()); - assertEquals(false, m.isEmpty()); + assertFalse(m.isEmpty()); } } http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStruct.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStruct.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStruct.java index 4fcaaec..994948b 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStruct.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStruct.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import java.lang.reflect.Constructor; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; @@ -60,20 +61,25 @@ public class TestStruct { @Parameters public static Collection params() { Object[][] pojo1Args = { - new Object[] { "foo", 5, 10.001 }, - new Object[] { "foo", 100, 7.0 }, - new Object[] { "foo", 100, 10.001 }, - new Object[] { "bar", 5, 10.001 }, - new Object[] { "bar", 100, 10.001 }, - new Object[] { "baz", 5, 10.001 }, + new Object[] { "foo", 5, 10.001 }, + new Object[] { "foo", 100, 7.0 }, + new Object[] { "foo", 100, 10.001 }, + new Object[] { "bar", 5, 10.001 }, + new Object[] { "bar", 100, 10.001 }, + new Object[] { "baz", 5, 10.001 }, }; Object[][] pojo2Args = { - new Object[] { new byte[0], "it".getBytes(), "was", "the".getBytes() }, - new Object[] { "best".getBytes(), new byte[0], "of", "times,".getBytes() }, - new Object[] { "it".getBytes(), "was".getBytes(), "", "the".getBytes() }, - new Object[] { "worst".getBytes(), "of".getBytes(), "times,", new byte[0] }, - new Object[] { new byte[0], new byte[0], "", new byte[0] }, + new Object[] { new byte[0], "it".getBytes(StandardCharsets.UTF_8), "was", + "the".getBytes(StandardCharsets.UTF_8) }, + new Object[] { "best".getBytes(StandardCharsets.UTF_8), new byte[0], "of", + "times,".getBytes(StandardCharsets.UTF_8) }, + new Object[] { "it".getBytes(StandardCharsets.UTF_8), + "was".getBytes(StandardCharsets.UTF_8), "", + "the".getBytes(StandardCharsets.UTF_8) }, + new Object[] { "worst".getBytes(StandardCharsets.UTF_8), + "of".getBytes(StandardCharsets.UTF_8), "times,", new byte[0] }, + new Object[] { new byte[0], new byte[0], "", new byte[0] }, }; Object[][] params = new Object[][] { @@ -126,19 +132,55 @@ public class TestStruct { @Override public int compareTo(Pojo1 o) { int cmp = stringFieldAsc.compareTo(o.stringFieldAsc); - if (cmp != 0) return cmp; + if (cmp != 0) { + return cmp; + } cmp = Integer.valueOf(intFieldAsc).compareTo(Integer.valueOf(o.intFieldAsc)); - if (cmp != 0) return cmp; + if (cmp != 0) { + return cmp; + } return Double.compare(doubleFieldAsc, o.doubleFieldAsc); } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (null == o) return false; - if (!(o instanceof Pojo1)) return false; - Pojo1 that = (Pojo1) o; - return 0 == this.compareTo(that); + public int hashCode() { + final int prime = 31; + int result = 1; + long temp; + temp = Double.doubleToLongBits(doubleFieldAsc); + result = prime * result + (int) (temp ^ (temp >>> 32)); + result = prime * result + intFieldAsc; + result = prime * result + ((stringFieldAsc == null) ? 0 : stringFieldAsc.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Pojo1 other = (Pojo1) obj; + if (Double.doubleToLongBits(doubleFieldAsc) != + Double.doubleToLongBits(other.doubleFieldAsc)) { + return false; + } + if (intFieldAsc != other.intFieldAsc) { + return false; + } + if (stringFieldAsc == null) { + if (other.stringFieldAsc != null) { + return false; + } + } else if (!stringFieldAsc.equals(other.stringFieldAsc)) { + return false; + } + return true; } } @@ -177,24 +219,69 @@ public class TestStruct { @Override public int compareTo(Pojo2 o) { int cmp = NULL_SAFE_BYTES_COMPARATOR.compare(byteField1Asc, o.byteField1Asc); - if (cmp != 0) return cmp; + if (cmp != 0) { + return cmp; + } cmp = -NULL_SAFE_BYTES_COMPARATOR.compare(byteField2Dsc, o.byteField2Dsc); - if (cmp != 0) return cmp; - if (stringFieldDsc == o.stringFieldDsc) cmp = 0; - else if (null == stringFieldDsc) cmp = 1; - else if (null == o.stringFieldDsc) cmp = -1; + if (cmp != 0) { + return cmp; + } + if (null == stringFieldDsc) { + cmp = 1; + } + else if (null == o.stringFieldDsc) { + cmp = -1; + } + else if (stringFieldDsc.equals(o.stringFieldDsc)) { + cmp = 0; + } else cmp = -stringFieldDsc.compareTo(o.stringFieldDsc); - if (cmp != 0) return cmp; + if (cmp != 0) { + return cmp; + } return -NULL_SAFE_BYTES_COMPARATOR.compare(byteField3Dsc, o.byteField3Dsc); } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (null == o) return false; - if (!(o instanceof Pojo2)) return false; - Pojo2 that = (Pojo2) o; - return 0 == this.compareTo(that); + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Arrays.hashCode(byteField1Asc); + result = prime * result + Arrays.hashCode(byteField2Dsc); + result = prime * result + Arrays.hashCode(byteField3Dsc); + result = prime * result + ((stringFieldDsc == null) ? 0 : stringFieldDsc.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Pojo2 other = (Pojo2) obj; + if (!Arrays.equals(byteField1Asc, other.byteField1Asc)) { + return false; + } + if (!Arrays.equals(byteField2Dsc, other.byteField2Dsc)) { + return false; + } + if (!Arrays.equals(byteField3Dsc, other.byteField3Dsc)) { + return false; + } + if (stringFieldDsc == null) { + if (other.stringFieldDsc != null) { + return false; + } + } else if (!stringFieldDsc.equals(other.stringFieldDsc)) { + return false; + } + return true; } } http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/util/AbstractHBaseToolTest.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/AbstractHBaseToolTest.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/AbstractHBaseToolTest.java index 79dafe7..9618111 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/AbstractHBaseToolTest.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/AbstractHBaseToolTest.java @@ -17,19 +17,22 @@ package org.apache.hadoop.hbase.util; +import static org.apache.hadoop.hbase.util.AbstractHBaseTool.EXIT_FAILURE; +import static org.apache.hadoop.hbase.util.AbstractHBaseTool.EXIT_SUCCESS; +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 java.util.ArrayList; +import java.util.List; + import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; import org.apache.hadoop.hbase.HBaseConfiguration; import org.junit.Before; import org.junit.Test; -import java.util.ArrayList; -import java.util.List; - -import static org.apache.hadoop.hbase.util.AbstractHBaseTool.EXIT_FAILURE; -import static org.apache.hadoop.hbase.util.AbstractHBaseTool.EXIT_SUCCESS; -import static org.junit.Assert.*; - public class AbstractHBaseToolTest { static final class Options { static final Option REQUIRED = new Option(null, "required", true, ""); @@ -43,7 +46,7 @@ public class AbstractHBaseToolTest { * 2 deprecated options to test backward compatibility: -opt (old version of --optional) and * -bool (old version of --boolean). */ - private class TestTool extends AbstractHBaseTool { + private static class TestTool extends AbstractHBaseTool { String requiredValue; String optionalValue; boolean booleanValue; http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/util/ClassLoaderTestHelper.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/ClassLoaderTestHelper.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/ClassLoaderTestHelper.java index ba6cea0..17471bb 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/ClassLoaderTestHelper.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/ClassLoaderTestHelper.java @@ -23,13 +23,13 @@ import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; -import java.io.FileWriter; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; - import javax.tools.JavaCompiler; import javax.tools.JavaFileObject; import javax.tools.StandardJavaFileManager; @@ -127,7 +127,7 @@ public class ClassLoaderTestHelper { File srcDirPath = new File(srcDir.toString()); srcDirPath.mkdirs(); File sourceCodeFile = new File(srcDir.toString(), className + ".java"); - BufferedWriter bw = new BufferedWriter(new FileWriter(sourceCodeFile)); + BufferedWriter bw = Files.newBufferedWriter(sourceCodeFile.toPath(), StandardCharsets.UTF_8); bw.write(javaCode); bw.close(); http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/util/RedundantKVGenerator.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/RedundantKVGenerator.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/RedundantKVGenerator.java index 6835c98..9cca312 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/RedundantKVGenerator.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/RedundantKVGenerator.java @@ -25,13 +25,13 @@ import java.util.Map; import java.util.Random; import org.apache.hadoop.hbase.ArrayBackedTag; +import org.apache.hadoop.hbase.ByteBufferKeyValue; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellComparator; import org.apache.hadoop.hbase.KeyValue; -import org.apache.hadoop.hbase.ByteBufferKeyValue; import org.apache.hadoop.hbase.Tag; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.io.WritableUtils; +import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.shaded.com.google.common.primitives.Bytes; http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestAvlUtil.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestAvlUtil.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestAvlUtil.java index 554e108..6c4e08e 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestAvlUtil.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestAvlUtil.java @@ -17,13 +17,18 @@ package org.apache.hadoop.hbase.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.util.Random; import java.util.TreeMap; -import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.testclassification.MiscTests; -import org.apache.hadoop.hbase.util.AvlUtil.AvlKeyComparator; +import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.AvlUtil.AvlIterableList; +import org.apache.hadoop.hbase.util.AvlUtil.AvlKeyComparator; import org.apache.hadoop.hbase.util.AvlUtil.AvlLinkedNode; import org.apache.hadoop.hbase.util.AvlUtil.AvlNode; import org.apache.hadoop.hbase.util.AvlUtil.AvlNodeVisitor; @@ -32,13 +37,6 @@ import org.apache.hadoop.hbase.util.AvlUtil.AvlTreeIterator; import org.junit.Test; import org.junit.experimental.categories.Category; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - @Category({MiscTests.class, SmallTests.class}) public class TestAvlUtil { private static final TestAvlKeyComparator KEY_COMPARATOR = new TestAvlKeyComparator(); @@ -97,6 +95,7 @@ public class TestAvlUtil { AvlTree.visit(root, new AvlNodeVisitor() { private int prevKey = -1; + @Override public boolean visitNode(TestAvlNode node) { assertEquals(prevKey, node.getKey() - 1); assertTrue(node.getKey() >= MIN_KEY); @@ -254,6 +253,7 @@ public class TestAvlUtil { } private static class TestAvlKeyComparator implements AvlKeyComparator { + @Override public int compareKey(TestAvlNode node, Object key) { return node.getKey() - (int)key; } http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBase64.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBase64.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBase64.java index 7c74bca..e609804 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBase64.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBase64.java @@ -24,7 +24,6 @@ import java.util.Map; import java.util.TreeMap; import junit.framework.TestCase; - import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.junit.experimental.categories.Category; http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferArray.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferArray.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferArray.java index 4b87945..9ee356f 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferArray.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferArray.java @@ -64,9 +64,9 @@ public class TestByteBufferArray { assertEquals(119, array.buffers.length); for (int i = 0; i < array.buffers.length; i++) { if (i == array.buffers.length - 1) { - assertEquals(array.buffers[i].capacity(), 0); + assertEquals(0, array.buffers[i].capacity()); } else { - assertEquals(array.buffers[i].capacity(), ByteBufferArray.DEFAULT_BUFFER_SIZE); + assertEquals(ByteBufferArray.DEFAULT_BUFFER_SIZE, array.buffers[i].capacity()); } } } @@ -86,9 +86,9 @@ public class TestByteBufferArray { array.createBuffers(allocator); for (int i = 0; i < array.buffers.length; i++) { if (i == array.buffers.length - 1) { - assertEquals(array.buffers[i].capacity(), 0); + assertEquals(0, array.buffers[i].capacity()); } else { - assertEquals(array.buffers[i].capacity(), 458752); + assertEquals(458752, array.buffers[i].capacity()); } } } http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtils.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtils.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtils.java index 81923ca..f4687fa 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtils.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtils.java @@ -313,8 +313,8 @@ public class TestByteBufferUtils { public void testLongFitsIn() { assertEquals(1, ByteBufferUtils.longFitsIn(0)); assertEquals(1, ByteBufferUtils.longFitsIn(1)); - assertEquals(3, ByteBufferUtils.longFitsIn(1l << 16)); - assertEquals(5, ByteBufferUtils.longFitsIn(1l << 32)); + assertEquals(3, ByteBufferUtils.longFitsIn(1L << 16)); + assertEquals(5, ByteBufferUtils.longFitsIn(1L << 32)); assertEquals(8, ByteBufferUtils.longFitsIn(-1)); assertEquals(8, ByteBufferUtils.longFitsIn(Long.MIN_VALUE)); assertEquals(8, ByteBufferUtils.longFitsIn(Long.MAX_VALUE)); http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteRangeWithKVSerialization.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteRangeWithKVSerialization.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteRangeWithKVSerialization.java index a3609e3..297bd62 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteRangeWithKVSerialization.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteRangeWithKVSerialization.java @@ -20,9 +20,9 @@ package org.apache.hadoop.hbase.util; import java.util.ArrayList; import java.util.List; +import org.apache.hadoop.hbase.ArrayBackedTag; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.Tag; -import org.apache.hadoop.hbase.ArrayBackedTag; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.junit.Assert; http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java index 38b01b8..546840c 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java @@ -30,7 +30,6 @@ import java.util.List; import java.util.Random; import junit.framework.TestCase; - import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.io.WritableUtils; @@ -158,9 +157,9 @@ public class TestBytes extends TestCase { 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)); + assertEquals(floats[i], Bytes.toFloat(b), 0.0f); byte [] b2 = bytesWithOffset(b); - assertEquals(floats[i], Bytes.toFloat(b2, 1)); + assertEquals(floats[i], Bytes.toFloat(b2, 1), 0.0f); } } @@ -168,9 +167,9 @@ public class TestBytes extends TestCase { 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)); + assertEquals(doubles[i], Bytes.toDouble(b), 0.0); byte [] b2 = bytesWithOffset(b); - assertEquals(doubles[i], Bytes.toDouble(b2, 1)); + assertEquals(doubles[i], Bytes.toDouble(b2, 1), 0.0); } } @@ -419,18 +418,18 @@ public class TestBytes extends TestCase { public void testToStringBinary_toBytesBinary_Reversable() throws Exception { 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); } public void testUnsignedBinarySearch(){ byte[] bytes = new byte[]{0,5,123,127,-128,-100,-1}; - Assert.assertEquals(Bytes.unsignedBinarySearch(bytes, 0, bytes.length, (byte)5), 1); - Assert.assertEquals(Bytes.unsignedBinarySearch(bytes, 0, bytes.length, (byte)127), 3); - Assert.assertEquals(Bytes.unsignedBinarySearch(bytes, 0, bytes.length, (byte)-128), 4); - Assert.assertEquals(Bytes.unsignedBinarySearch(bytes, 0, bytes.length, (byte)-100), 5); - Assert.assertEquals(Bytes.unsignedBinarySearch(bytes, 0, bytes.length, (byte)-1), 6); - Assert.assertEquals(Bytes.unsignedBinarySearch(bytes, 0, bytes.length, (byte)2), -1-1); - Assert.assertEquals(Bytes.unsignedBinarySearch(bytes, 0, bytes.length, (byte)-5), -6-1); + Assert.assertEquals(1, Bytes.unsignedBinarySearch(bytes, 0, bytes.length, (byte)5)); + Assert.assertEquals(3, Bytes.unsignedBinarySearch(bytes, 0, bytes.length, (byte)127)); + Assert.assertEquals(4, Bytes.unsignedBinarySearch(bytes, 0, bytes.length, (byte)-128)); + Assert.assertEquals(5, Bytes.unsignedBinarySearch(bytes, 0, bytes.length, (byte)-100)); + Assert.assertEquals(6, Bytes.unsignedBinarySearch(bytes, 0, bytes.length, (byte)-1)); + Assert.assertEquals(-1-1, Bytes.unsignedBinarySearch(bytes, 0, bytes.length, (byte)2)); + Assert.assertEquals(-6-1, Bytes.unsignedBinarySearch(bytes, 0, bytes.length, (byte)-5)); } public void testUnsignedIncrement(){ @@ -448,7 +447,7 @@ public class TestBytes extends TestCase { int c2 = Bytes.toInt(Bytes.unsignedCopyAndIncrement(c), 0); Assert.assertTrue(c2==256); } - + public void testIndexOf() { byte[] array = Bytes.toBytes("hello"); assertEquals(1, Bytes.indexOf(array, (byte) 'e')); @@ -458,7 +457,7 @@ public class TestBytes extends TestCase { assertEquals(2, Bytes.indexOf(array, Bytes.toBytes("ll"))); assertEquals(-1, Bytes.indexOf(array, Bytes.toBytes("hll"))); } - + public void testContains() { byte[] array = Bytes.toBytes("hello world"); assertTrue(Bytes.contains(array, (byte) 'e')); @@ -468,7 +467,7 @@ public class TestBytes extends TestCase { assertTrue(Bytes.contains(array, Bytes.toBytes("ello"))); assertFalse(Bytes.contains(array, Bytes.toBytes("owo"))); } - + public void testZero() { byte[] array = Bytes.toBytes("hello"); Bytes.zero(array); @@ -496,7 +495,7 @@ public class TestBytes extends TestCase { Assert.assertEquals(i, b[i]); } } - + public void testToFromHex() { List testStrings = new ArrayList<>(8); testStrings.addAll(Arrays.asList(new String[] { @@ -516,7 +515,7 @@ public class TestBytes extends TestCase { String result = Bytes.toHex(byteData); Assert.assertTrue(testString.equalsIgnoreCase(result)); } - + List testByteData = new ArrayList<>(5); testByteData.addAll(Arrays.asList(new byte[][] { new byte[0], @@ -528,12 +527,11 @@ public class TestBytes extends TestCase { Random r = new Random(); for (int i = 0; i < 20; i++) { - byte[] bytes = new byte[r.nextInt(100)]; r.nextBytes(bytes); testByteData.add(bytes); } - + for (byte[] testData : testByteData) { String hexString = Bytes.toHex(testData); http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCommonFSUtils.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCommonFSUtils.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCommonFSUtils.java index 7ff5792..7dd27d4 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCommonFSUtils.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCommonFSUtils.java @@ -100,10 +100,10 @@ public class TestCommonFSUtils { Path root = new Path("file:///hbase/root"); Path walRoot = new Path("file:///hbase/logroot"); CommonFSUtils.setRootDir(conf, root); - assertEquals(CommonFSUtils.getRootDir(conf), root); - assertEquals(CommonFSUtils.getWALRootDir(conf), root); + assertEquals(root, CommonFSUtils.getRootDir(conf)); + assertEquals(root, CommonFSUtils.getWALRootDir(conf)); CommonFSUtils.setWALRootDir(conf, walRoot); - assertEquals(CommonFSUtils.getWALRootDir(conf), walRoot); + assertEquals(walRoot, CommonFSUtils.getWALRootDir(conf)); } @Test(expected=IllegalStateException.class) @@ -120,12 +120,12 @@ public class TestCommonFSUtils { CommonFSUtils.setRootDir(conf, new Path("file:///user/hbase")); Path testFile = new Path(CommonFSUtils.getRootDir(conf), "test/testfile"); Path tmpFile = new Path("file:///test/testfile"); - assertEquals(CommonFSUtils.removeWALRootPath(testFile, conf), "test/testfile"); - assertEquals(CommonFSUtils.removeWALRootPath(tmpFile, conf), tmpFile.toString()); + assertEquals("test/testfile", CommonFSUtils.removeWALRootPath(testFile, conf)); + assertEquals(tmpFile.toString(), CommonFSUtils.removeWALRootPath(tmpFile, conf)); CommonFSUtils.setWALRootDir(conf, new Path("file:///user/hbaseLogDir")); - assertEquals(CommonFSUtils.removeWALRootPath(testFile, conf), testFile.toString()); + assertEquals(testFile.toString(), CommonFSUtils.removeWALRootPath(testFile, conf)); Path logFile = new Path(CommonFSUtils.getWALRootDir(conf), "test/testlog"); - assertEquals(CommonFSUtils.removeWALRootPath(logFile, conf), "test/testlog"); + assertEquals("test/testlog", CommonFSUtils.removeWALRootPath(logFile, conf)); } @Test(expected=NullPointerException.class) http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestConcatenatedLists.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestConcatenatedLists.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestConcatenatedLists.java index 08d5569..18670a1 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestConcatenatedLists.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestConcatenatedLists.java @@ -119,6 +119,8 @@ public class TestConcatenatedLists { } @SuppressWarnings("ModifyingCollectionWithItself") + @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="DMI_VACUOUS_SELF_COLLECTION_CALL", + justification="Intended vacuous containsAll call on 'c'") private void verify(ConcatenatedLists c, int last) { assertEquals((last == -1), c.isEmpty()); assertEquals(last + 1, c.size()); http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorClassLoader.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorClassLoader.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorClassLoader.java index 967d272..32af01b 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorClassLoader.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorClassLoader.java @@ -18,10 +18,10 @@ */ package org.apache.hadoop.hbase.util; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.File; @@ -87,8 +87,11 @@ public class TestCoprocessorClassLoader { private void checkingLibJarName(String jarName, String libPrefix) throws Exception { File tmpFolder = new File(ClassLoaderTestHelper.localDirPath(conf), "tmp"); if (tmpFolder.exists()) { // Clean up the tmp folder - for (File f: tmpFolder.listFiles()) { - f.delete(); + File[] files = tmpFolder.listFiles(); + if (files != null) { + for (File f: files) { + f.delete(); + } } } String className = "CheckingLibJarName"; @@ -102,10 +105,13 @@ public class TestCoprocessorClassLoader { ClassLoader classLoader = CoprocessorClassLoader.getClassLoader(path, parent, "112", conf); assertNotNull("Classloader should be created", classLoader); String fileToLookFor = "." + className + ".jar"; - for (String f: tmpFolder.list()) { - if (f.endsWith(fileToLookFor) && f.contains(jarName)) { - // Cool, found it; - return; + String[] files = tmpFolder.list(); + if (files != null) { + for (String f: files) { + if (f.endsWith(fileToLookFor) && f.contains(jarName)) { + // Cool, found it; + return; + } } } fail("Could not find the expected lib jar file"); http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestDynamicClassLoader.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestDynamicClassLoader.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestDynamicClassLoader.java index 57514e3..5bdb668 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestDynamicClassLoader.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestDynamicClassLoader.java @@ -29,8 +29,8 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseCommonTestingUtility; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; -import org.junit.Test; import org.junit.Before; +import org.junit.Test; import org.junit.experimental.categories.Category; /** http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestJRubyFormat.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestJRubyFormat.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestJRubyFormat.java index 96b3da0..54de497 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestJRubyFormat.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestJRubyFormat.java @@ -23,11 +23,12 @@ import static org.junit.Assert.assertEquals; import java.util.LinkedHashMap; import java.util.Map; -import org.apache.hadoop.hbase.shaded.com.google.common.collect.Lists; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.apache.hadoop.hbase.shaded.com.google.common.collect.Lists; + @Category(SmallTests.class) public class TestJRubyFormat { @Test http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestLoadTestKVGenerator.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestLoadTestKVGenerator.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestLoadTestKVGenerator.java index f5db4c1..2c40342 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestLoadTestKVGenerator.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestLoadTestKVGenerator.java @@ -19,6 +19,7 @@ package org.apache.hadoop.hbase.util; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.nio.charset.StandardCharsets; import java.util.HashSet; import java.util.Random; import java.util.Set; @@ -40,8 +41,8 @@ public class TestLoadTestKVGenerator { @Test public void testValueLength() { for (int i = 0; i < 1000; ++i) { - byte[] v = gen.generateRandomSizeValue(Integer.toString(i).getBytes(), - String.valueOf(rand.nextInt()).getBytes()); + byte[] v = gen.generateRandomSizeValue(Integer.toString(i).getBytes(StandardCharsets.UTF_8), + String.valueOf(rand.nextInt()).getBytes(StandardCharsets.UTF_8)); assertTrue(MIN_LEN <= v.length); assertTrue(v.length <= MAX_LEN); } @@ -51,8 +52,8 @@ public class TestLoadTestKVGenerator { public void testVerification() { for (int i = 0; i < 1000; ++i) { for (int qualIndex = 0; qualIndex < 20; ++qualIndex) { - byte[] qual = String.valueOf(qualIndex).getBytes(); - byte[] rowKey = LoadTestKVGenerator.md5PrefixedKey(i).getBytes(); + byte[] qual = String.valueOf(qualIndex).getBytes(StandardCharsets.UTF_8); + byte[] rowKey = LoadTestKVGenerator.md5PrefixedKey(i).getBytes(StandardCharsets.UTF_8); byte[] v = gen.generateRandomSizeValue(rowKey, qual); assertTrue(LoadTestKVGenerator.verify(v, rowKey, qual)); v[0]++; http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestOrderedBytes.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestOrderedBytes.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestOrderedBytes.java index dc0690a..c62986d 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestOrderedBytes.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestOrderedBytes.java @@ -19,9 +19,11 @@ package org.apache.hadoop.hbase.util; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collections; @@ -872,24 +874,32 @@ public class TestOrderedBytes { @Test public void testBlobVar() { byte[][] vals = - { "".getBytes(), "foo".getBytes(), "foobarbazbub".getBytes(), - { (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, - (byte) 0xaa, /* 7 bytes of alternating bits; testing around HBASE-9893 */ }, - { (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, - (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa }, - { (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, - (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, - (byte) 0xaa, (byte) 0xaa, /* 14 bytes of alternating bits; testing around HBASE-9893 */ }, - { (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, - (byte) 0x55, /* 7 bytes of alternating bits; testing around HBASE-9893 */ }, - { (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, - (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55 }, - { (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, - (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, - (byte) 0x55, (byte) 0x55, /* 14 bytes of alternating bits; testing around HBASE-9893 */ }, - "1".getBytes(), "22".getBytes(), "333".getBytes(), "4444".getBytes(), - "55555".getBytes(), "666666".getBytes(), "7777777".getBytes(), "88888888".getBytes() - }; + { "".getBytes(StandardCharsets.UTF_8), + "foo".getBytes(StandardCharsets.UTF_8), + "foobarbazbub".getBytes(StandardCharsets.UTF_8), + { (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, + (byte) 0xaa, /* 7 bytes of alternating bits; testing around HBASE-9893 */ }, + { (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, + (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa }, + { (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, + (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, + (byte) 0xaa, (byte) 0xaa, /* 14 bytes of alternating bits; testing around HBASE-9893 */ }, + { (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, + (byte) 0x55, /* 7 bytes of alternating bits; testing around HBASE-9893 */ }, + { (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, + (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55 }, + { (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, + (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, + (byte) 0x55, (byte) 0x55, /* 14 bytes of alternating bits; testing around HBASE-9893 */ }, + "1".getBytes(StandardCharsets.UTF_8), + "22".getBytes(StandardCharsets.UTF_8), + "333".getBytes(StandardCharsets.UTF_8), + "4444".getBytes(StandardCharsets.UTF_8), + "55555".getBytes(StandardCharsets.UTF_8), + "666666".getBytes(StandardCharsets.UTF_8), + "7777777".getBytes(StandardCharsets.UTF_8), + "88888888".getBytes(StandardCharsets.UTF_8) + }; /* * assert encoded values match decoded values. encode into target buffer @@ -959,7 +969,9 @@ public class TestOrderedBytes { @Test public void testBlobCopy() { byte[][] vals = - { "".getBytes(), "foo".getBytes(), "foobarbazbub".getBytes(), + { "".getBytes(StandardCharsets.UTF_8), + "foo".getBytes(StandardCharsets.UTF_8), + "foobarbazbub".getBytes(StandardCharsets.UTF_8), { (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa }, { (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, @@ -1034,9 +1046,9 @@ public class TestOrderedBytes { byte[] a = new byte[3 + (Order.ASCENDING == ord ? 1 : 2) + 2]; PositionedByteRange buf = new SimplePositionedMutableByteRange(a, 1, 3 + (Order.ASCENDING == ord ? 1 : 2)); - OrderedBytes.encodeBlobCopy(buf, "foobarbaz".getBytes(), 3, 3, ord); + OrderedBytes.encodeBlobCopy(buf, "foobarbaz".getBytes(StandardCharsets.UTF_8), 3, 3, ord); buf.setPosition(0); - assertArrayEquals("bar".getBytes(), OrderedBytes.decodeBlobCopy(buf)); + assertArrayEquals("bar".getBytes(StandardCharsets.UTF_8), OrderedBytes.decodeBlobCopy(buf)); } } @@ -1240,7 +1252,7 @@ public class TestOrderedBytes { buff.setPosition(0); assertEquals(OrderedBytes.length(buff), cnt); for (int i = 0; i < cnt; i++) { - assertEquals(OrderedBytes.isEncodedValue(buff), true); + assertTrue(OrderedBytes.isEncodedValue(buff)); OrderedBytes.skip(buff); } } http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestVersionInfo.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestVersionInfo.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestVersionInfo.java index 42f6eba..6e71b27 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestVersionInfo.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestVersionInfo.java @@ -17,8 +17,9 @@ */ package org.apache.hadoop.hbase.util; -import org.apache.hadoop.hbase.testclassification.SmallTests; import static org.junit.Assert.assertTrue; + +import org.apache.hadoop.hbase.testclassification.SmallTests; import org.junit.Test; import org.junit.experimental.categories.Category; http://git-wip-us.apache.org/repos/asf/hbase/blob/4c2b2b3e/hbase-common/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKConfig.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKConfig.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKConfig.java index 216fe0c..8309f81 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKConfig.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKConfig.java @@ -17,6 +17,9 @@ */ package org.apache.hadoop.hbase.zookeeper; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.Properties; @@ -28,9 +31,6 @@ import org.apache.hadoop.hbase.testclassification.SmallTests; import org.junit.Test; import org.junit.experimental.categories.Category; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - @Category({MiscTests.class, SmallTests.class}) public class TestZKConfig {