Skip to content

Commit

Permalink
HBASE-22786 Fixed Checkstyle issues in tests in hbase-client
Browse files Browse the repository at this point in the history
  • Loading branch information
HorizonNet committed Aug 3, 2019
1 parent a6f0653 commit 0766bf9
Show file tree
Hide file tree
Showing 18 changed files with 133 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;

/** Tests the HColumnDescriptor with appropriate arguments */
/**
* Tests the HColumnDescriptor with appropriate arguments.
*
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 together with
* {@link HColumnDescriptor}.
*/
@Category({MiscTests.class, SmallTests.class})
@Deprecated
public class TestHColumnDescriptor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@

/**
* Test setting values in the descriptor
*
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 together with
* {@link HTableDescriptor}.
*/
@Category({MiscTests.class, SmallTests.class})
@Deprecated
Expand Down Expand Up @@ -117,8 +120,9 @@ public void testPb() throws DeserializationException, IOException {
}

/**
* Test cps in the table description
* @throws Exception
* Test cps in the table description.
*
* @throws Exception if adding a coprocessor fails
*/
@Test
public void testGetSetRemoveCP() throws Exception {
Expand All @@ -134,8 +138,9 @@ public void testGetSetRemoveCP() throws Exception {
}

/**
* Test cps in the table description
* @throws Exception
* Test cps in the table description.
*
* @throws Exception if adding a coprocessor fails
*/
@Test
public void testSetListRemoveCP() throws Exception {
Expand Down Expand Up @@ -172,10 +177,9 @@ public void testSetListRemoveCP() throws Exception {

/**
* Test that we add and remove strings from settings properly.
* @throws Exception
*/
@Test
public void testAddGetRemoveString() throws Exception {
public void testAddGetRemoveString() {
HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
String key = "Some";
String value = "value";
Expand All @@ -191,15 +195,15 @@ public void testAddGetRemoveString() throws Exception {
assertEquals(null, desc.getValue(keyShouldNotNull));
}

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",
"汉", "汉:字", "_字_", "foo:字", "foo.字", "字.foo"};
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",
"汉", "汉:字", "_字_", "foo:字", "foo.字", "字.foo"};
// Avoiding "zookeeper" in here as it's tough to encode in regex
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.valueOf((char)130),
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.valueOf((char)130),
String.valueOf((char)5), String.valueOf((char)65530)};

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

@Category({ClientTests.class, SmallTests.class})
public class TestAttributes {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestAttributes.class);
Expand All @@ -49,19 +48,22 @@ public void testPutAttributes() {
put.setAttribute("attribute1", Bytes.toBytes("value1"));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), put.getAttribute("attribute1")));
Assert.assertEquals(1, put.getAttributesMap().size());
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), put.getAttributesMap().get("attribute1")));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"),
put.getAttributesMap().get("attribute1")));

// overriding attribute value
put.setAttribute("attribute1", Bytes.toBytes("value12"));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value12"), put.getAttribute("attribute1")));
Assert.assertEquals(1, put.getAttributesMap().size());
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value12"), put.getAttributesMap().get("attribute1")));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value12"),
put.getAttributesMap().get("attribute1")));

// adding another attribute
put.setAttribute("attribute2", Bytes.toBytes("value2"));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), put.getAttribute("attribute2")));
Assert.assertEquals(2, put.getAttributesMap().size());
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), put.getAttributesMap().get("attribute2")));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"),
put.getAttributesMap().get("attribute2")));

// removing attribute
put.setAttribute("attribute2", null);
Expand All @@ -82,7 +84,6 @@ public void testPutAttributes() {
Assert.assertNull(put.getAttributesMap().get("attribute1"));
}


@Test
public void testDeleteAttributes() {
Delete del = new Delete(new byte [] {'r'});
Expand All @@ -97,19 +98,22 @@ public void testDeleteAttributes() {
del.setAttribute("attribute1", Bytes.toBytes("value1"));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), del.getAttribute("attribute1")));
Assert.assertEquals(1, del.getAttributesMap().size());
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), del.getAttributesMap().get("attribute1")));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"),
del.getAttributesMap().get("attribute1")));

// overriding attribute value
del.setAttribute("attribute1", Bytes.toBytes("value12"));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value12"), del.getAttribute("attribute1")));
Assert.assertEquals(1, del.getAttributesMap().size());
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value12"), del.getAttributesMap().get("attribute1")));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value12"),
del.getAttributesMap().get("attribute1")));

// adding another attribute
del.setAttribute("attribute2", Bytes.toBytes("value2"));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), del.getAttribute("attribute2")));
Assert.assertEquals(2, del.getAttributesMap().size());
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), del.getAttributesMap().get("attribute2")));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"),
del.getAttributesMap().get("attribute2")));

// removing attribute
del.setAttribute("attribute2", null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

@Category({ClientTests.class, SmallTests.class})
public class TestClientExponentialBackoff {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestClientExponentialBackoff.class);
Expand Down Expand Up @@ -149,7 +148,7 @@ public void testCompactionPressurePolicy() {
backoffTime = backoff.getBackoffTime(server, regionname, stats);
assertTrue("Compaction pressure has no effect", backoffTime == 0);

long previous = backoffTime;
long previous = backoffTime;
update(stats, 0, 0, 50);
backoffTime = backoff.getBackoffTime(server, regionname, stats);
assertTrue("Compaction pressure should be bigger",
Expand All @@ -163,8 +162,7 @@ public void testCompactionPressurePolicy() {

private void update(ServerStatistics stats, int load) {
ClientProtos.RegionLoadStats stat = ClientProtos.RegionLoadStats.newBuilder()
.setMemStoreLoad
(load).build();
.setMemStoreLoad(load).build();
stats.update(regionname, ProtobufUtil.createRegionLoadStats(stat));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@

@Category({MiscTests.class, SmallTests.class})
public class TestColumnFamilyDescriptorBuilder {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestColumnFamilyDescriptorBuilder.class);
Expand Down Expand Up @@ -85,7 +84,8 @@ public void testBuilder() throws DeserializationException {
assertTrue(hcd.equals(deserializedHcd));
assertEquals(v, hcd.getBlocksize());
assertEquals(v, hcd.getTimeToLive());
assertTrue(Bytes.equals(hcd.getValue(Bytes.toBytes("a")), deserializedHcd.getValue(Bytes.toBytes("a"))));
assertTrue(Bytes.equals(hcd.getValue(Bytes.toBytes("a")),
deserializedHcd.getValue(Bytes.toBytes("a"))));
assertEquals(hcd.getMaxVersions(), deserializedHcd.getMaxVersions());
assertEquals(hcd.getMinVersions(), deserializedHcd.getMinVersions());
assertEquals(hcd.getKeepDeletedCells(), deserializedHcd.getKeepDeletedCells());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
// TODO: cover more test cases
@Category({ClientTests.class, SmallTests.class})
public class TestGet {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestGet.class);
Expand Down Expand Up @@ -122,19 +121,22 @@ public void testGetAttributes() {
get.setAttribute("attribute1", Bytes.toBytes("value1"));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), get.getAttribute("attribute1")));
Assert.assertEquals(1, get.getAttributesMap().size());
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), get.getAttributesMap().get("attribute1")));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"),
get.getAttributesMap().get("attribute1")));

// overriding attribute value
get.setAttribute("attribute1", Bytes.toBytes("value12"));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value12"), get.getAttribute("attribute1")));
Assert.assertEquals(1, get.getAttributesMap().size());
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value12"), get.getAttributesMap().get("attribute1")));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value12"),
get.getAttributesMap().get("attribute1")));

// adding another attribute
get.setAttribute("attribute2", Bytes.toBytes("value2"));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), get.getAttribute("attribute2")));
Assert.assertEquals(2, get.getAttributesMap().size());
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), get.getAttributesMap().get("attribute2")));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"),
get.getAttributesMap().get("attribute2")));

// removing attribute
get.setAttribute("attribute2", null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@

@Category({ClientTests.class, MetricsTests.class, SmallTests.class})
public class TestMetricsConnection {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestMetricsConnection.class);
Expand Down Expand Up @@ -119,8 +118,8 @@ public void testStaticMetrics() throws IOException {
MetricsConnection.newCallStats());
}
for (MetricsConnection.CallTracker t : new MetricsConnection.CallTracker[] {
METRICS.getTracker, METRICS.scanTracker, METRICS.multiTracker, METRICS.appendTracker,
METRICS.deleteTracker, METRICS.incrementTracker, METRICS.putTracker
METRICS.getTracker, METRICS.scanTracker, METRICS.multiTracker, METRICS.appendTracker,
METRICS.deleteTracker, METRICS.incrementTracker, METRICS.putTracker
}) {
assertEquals("Failed to invoke callTimer on " + t, loop, t.callTimer.getCount());
assertEquals("Failed to invoke reqHist on " + t, loop, t.reqHist.getCount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
*/
@Category({ClientTests.class, SmallTests.class})
public class TestOperation {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestOperation.class);
Expand Down Expand Up @@ -284,11 +283,11 @@ public class TestOperation {
/**
* Test the client Operations' JSON encoding to ensure that produced JSON is
* parseable and that the details are present and not corrupted.
* @throws IOException
*
* @throws IOException if the JSON conversion fails
*/
@Test
public void testOperationJSON()
throws IOException {
public void testOperationJSON() throws IOException {
// produce a Scan Operation
Scan scan = new Scan(ROW);
scan.addColumn(FAMILY, QUALIFIER);
Expand Down Expand Up @@ -428,18 +427,17 @@ public void testOperationSubClassMethodsAreBuilderStyle() {

// TODO: We should ensure all subclasses of Operation is checked.
Class[] classes = new Class[] {
Operation.class,
OperationWithAttributes.class,
Mutation.class,
Query.class,
Delete.class,
Increment.class,
Append.class,
Put.class,
Get.class,
Scan.class};
Operation.class,
OperationWithAttributes.class,
Mutation.class,
Query.class,
Delete.class,
Increment.class,
Append.class,
Put.class,
Get.class,
Scan.class};

BuilderStyleTest.assertClassesAreBuilderStyle(classes);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
// TODO: cover more test cases
@Category({ClientTests.class, SmallTests.class})
public class TestScan {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestScan.class);
Expand Down Expand Up @@ -94,7 +93,8 @@ public void testGetToScan() throws Exception {
assertEquals(get.getFilter(), scan.getFilter());
assertEquals(get.getId(), scan.getId());
assertEquals(get.getIsolationLevel(), scan.getIsolationLevel());
assertEquals(get.getLoadColumnFamiliesOnDemandValue(), scan.getLoadColumnFamiliesOnDemandValue());
assertEquals(get.getLoadColumnFamiliesOnDemandValue(),
scan.getLoadColumnFamiliesOnDemandValue());
assertEquals(get.getMaxResultsPerColumnFamily(), scan.getMaxResultsPerColumnFamily());
assertEquals(get.getMaxVersions(), scan.getMaxVersions());
assertEquals(get.getRowOffsetPerColumnFamily(), scan.getRowOffsetPerColumnFamily());
Expand Down Expand Up @@ -125,19 +125,22 @@ public void testScanAttributes() {
scan.setAttribute("attribute1", Bytes.toBytes("value1"));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), scan.getAttribute("attribute1")));
Assert.assertEquals(1, scan.getAttributesMap().size());
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), scan.getAttributesMap().get("attribute1")));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"),
scan.getAttributesMap().get("attribute1")));

// overriding attribute value
scan.setAttribute("attribute1", Bytes.toBytes("value12"));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value12"), scan.getAttribute("attribute1")));
Assert.assertEquals(1, scan.getAttributesMap().size());
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value12"), scan.getAttributesMap().get("attribute1")));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value12"),
scan.getAttributesMap().get("attribute1")));

// adding another attribute
scan.setAttribute("attribute2", Bytes.toBytes("value2"));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), scan.getAttribute("attribute2")));
Assert.assertEquals(2, scan.getAttributesMap().size());
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), scan.getAttributesMap().get("attribute2")));
Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"),
scan.getAttributesMap().get("attribute2")));

// removing attribute
scan.setAttribute("attribute2", null);
Expand Down Expand Up @@ -290,4 +293,3 @@ public void testScanCopyConstructor() throws Exception {
EqualsBuilder.reflectionEquals(scan, scanCopy));
}
}

Loading

0 comments on commit 0766bf9

Please sign in to comment.