Skip to content

Commit e8d2931

Browse files
authored
HBASE-23623 Reduced the number of Checkstyle violations in hbase-rest
Signed-off-by: stack <stack@apache.org> Signed-off-by: Viraj Jasani <vjasani@apache.org>
1 parent d86778f commit e8d2931

11 files changed

+192
-251
lines changed

hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/PerformanceEvaluation.java

Lines changed: 100 additions & 139 deletions
Large diffs are not rendered by default.

hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestGetAndPutResource.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646

4747
@Category({RestTests.class, MediumTests.class})
4848
public class TestGetAndPutResource extends RowResourceBase {
49-
5049
@ClassRule
5150
public static final HBaseClassTestRule CLASS_RULE =
5251
HBaseClassTestRule.forClass(TestGetAndPutResource.class);
@@ -134,7 +133,7 @@ public void testSingleCellGetPutPB() throws IOException, JAXBException {
134133
}
135134

136135
@Test
137-
public void testMultipleCellCheckPutPB() throws IOException, JAXBException {
136+
public void testMultipleCellCheckPutPB() throws IOException {
138137
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
139138
assertEquals(404, response.getCode());
140139

@@ -200,7 +199,7 @@ public void testMultipleCellCheckPutXML() throws IOException, JAXBException {
200199
}
201200

202201
@Test
203-
public void testMultipleCellCheckDeletePB() throws IOException, JAXBException {
202+
public void testMultipleCellCheckDeletePB() throws IOException {
204203
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
205204
assertEquals(404, response.getCode());
206205

@@ -252,6 +251,7 @@ public void testMultipleCellCheckDeletePB() throws IOException, JAXBException {
252251
response = deleteRow(TABLE, ROW_1);
253252
assertEquals(200, response.getCode());
254253
}
254+
255255
@Test
256256
public void testSingleCellGetPutBinary() throws IOException {
257257
final String path = "/" + TABLE + "/" + ROW_3 + "/" + COLUMN_1;
@@ -278,7 +278,7 @@ public void testSingleCellGetPutBinary() throws IOException {
278278
}
279279

280280
@Test
281-
public void testSingleCellGetJSON() throws IOException, JAXBException {
281+
public void testSingleCellGetJSON() throws IOException {
282282
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
283283
Response response = client.put(path, Constants.MIMETYPE_BINARY,
284284
Bytes.toBytes(VALUE_4));
@@ -292,7 +292,7 @@ public void testSingleCellGetJSON() throws IOException, JAXBException {
292292
}
293293

294294
@Test
295-
public void testLatestCellGetJSON() throws IOException, JAXBException {
295+
public void testLatestCellGetJSON() throws IOException {
296296
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
297297
CellSetModel cellSetModel = new CellSetModel();
298298
RowModel rowModel = new RowModel(ROW_4);
@@ -339,7 +339,7 @@ public void testURLEncodedKey() throws IOException, JAXBException {
339339
}
340340

341341
@Test
342-
public void testNoSuchCF() throws IOException, JAXBException {
342+
public void testNoSuchCF() throws IOException {
343343
final String goodPath = "/" + TABLE + "/" + ROW_1 + "/" + CFA+":";
344344
final String badPath = "/" + TABLE + "/" + ROW_1 + "/" + "BAD";
345345
Response response = client.post(goodPath, Constants.MIMETYPE_BINARY,
@@ -529,7 +529,7 @@ public void testMultiCellGetJson() throws IOException, JAXBException {
529529
}
530530

531531
@Test
532-
public void testMetrics() throws IOException, JAXBException {
532+
public void testMetrics() throws IOException {
533533
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
534534
Response response = client.put(path, Constants.MIMETYPE_BINARY,
535535
Bytes.toBytes(VALUE_4));
@@ -542,16 +542,16 @@ public void testMetrics() throws IOException, JAXBException {
542542
assertEquals(200, response.getCode());
543543

544544
UserProvider userProvider = UserProvider.instantiate(conf);
545-
METRICS_ASSERT.assertCounterGt("requests", 2l,
545+
METRICS_ASSERT.assertCounterGt("requests", 2L,
546546
RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
547547

548-
METRICS_ASSERT.assertCounterGt("successfulGet", 0l,
548+
METRICS_ASSERT.assertCounterGt("successfulGet", 0L,
549549
RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
550550

551-
METRICS_ASSERT.assertCounterGt("successfulPut", 0l,
551+
METRICS_ASSERT.assertCounterGt("successfulPut", 0L,
552552
RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
553553

554-
METRICS_ASSERT.assertCounterGt("successfulDelete", 0l,
554+
METRICS_ASSERT.assertCounterGt("successfulDelete", 0L,
555555
RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
556556
}
557557

@@ -806,4 +806,3 @@ public void testIncrementJSON() throws IOException, JAXBException {
806806
assertEquals(200, response.getCode());
807807
}
808808
}
809-

hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestNamespacesInstanceResource.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
*/
1818
package org.apache.hadoop.hbase.rest;
1919

20-
import static org.junit.Assert.*;
20+
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertNotNull;
22+
import static org.junit.Assert.assertNull;
23+
import static org.junit.Assert.assertTrue;
2124

2225
import com.fasterxml.jackson.databind.ObjectMapper;
2326
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
@@ -60,7 +63,6 @@
6063

6164
@Category({RestTests.class, MediumTests.class})
6265
public class TestNamespacesInstanceResource {
63-
6466
@ClassRule
6567
public static final HBaseClassTestRule CLASS_RULE =
6668
HBaseClassTestRule.forClass(TestNamespacesInstanceResource.class);
@@ -122,9 +124,9 @@ private static <T> T fromXML(byte[] content)
122124

123125
private NamespaceDescriptor findNamespace(Admin admin, String namespaceName) throws IOException{
124126
NamespaceDescriptor[] nd = admin.listNamespaceDescriptors();
125-
for(int i = 0; i < nd.length; i++){
126-
if(nd[i].getName().equals(namespaceName)){
127-
return nd[i];
127+
for (NamespaceDescriptor namespaceDescriptor : nd) {
128+
if (namespaceDescriptor.getName().equals(namespaceName)) {
129+
return namespaceDescriptor;
128130
}
129131
}
130132
return null;
@@ -137,15 +139,15 @@ private void checkNamespaceProperties(NamespaceDescriptor nd, Map<String,String>
137139
private void checkNamespaceProperties(Map<String,String> namespaceProps,
138140
Map<String,String> testProps){
139141
assertTrue(namespaceProps.size() == testProps.size());
140-
for(String key: testProps.keySet()){
142+
for (String key: testProps.keySet()) {
141143
assertEquals(testProps.get(key), namespaceProps.get(key));
142144
}
143145
}
144146

145147
private void checkNamespaceTables(List<TableModel> namespaceTables, List<String> testTables){
146148
assertEquals(namespaceTables.size(), testTables.size());
147-
for(int i = 0 ; i < namespaceTables.size() ; i++){
148-
String tableName = ((TableModel) namespaceTables.get(i)).getName();
149+
for (TableModel namespaceTable : namespaceTables) {
150+
String tableName = namespaceTable.getName();
149151
assertTrue(testTables.contains(tableName));
150152
}
151153
}
@@ -369,7 +371,7 @@ public void testNamespaceCreateAndDeleteXMLAndJSON() throws IOException, JAXBExc
369371
}
370372

371373
@Test
372-
public void testNamespaceCreateAndDeletePBAndNoBody() throws IOException, JAXBException {
374+
public void testNamespaceCreateAndDeletePBAndNoBody() throws IOException {
373375
String namespacePath3 = "/namespaces/" + NAMESPACE3;
374376
String namespacePath4 = "/namespaces/" + NAMESPACE4;
375377
NamespacesInstanceModel model3;

hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestNamespacesResource.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
*/
1818
package org.apache.hadoop.hbase.rest;
1919

20-
import static org.junit.Assert.*;
20+
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertFalse;
2122

2223
import java.io.ByteArrayInputStream;
2324
import java.io.IOException;
@@ -44,7 +45,6 @@
4445

4546
@Category({RestTests.class, MediumTests.class})
4647
public class TestNamespacesResource {
47-
4848
@ClassRule
4949
public static final HBaseClassTestRule CLASS_RULE =
5050
HBaseClassTestRule.forClass(TestNamespacesResource.class);
@@ -83,8 +83,8 @@ private static NamespacesModel fromXML(byte[] content) throws JAXBException {
8383

8484
private boolean doesNamespaceExist(Admin admin, String namespaceName) throws IOException {
8585
NamespaceDescriptor[] nd = admin.listNamespaceDescriptors();
86-
for(int i = 0; i < nd.length; i++) {
87-
if(nd[i].getName().equals(namespaceName)) {
86+
for (NamespaceDescriptor namespaceDescriptor : nd) {
87+
if (namespaceDescriptor.getName().equals(namespaceName)) {
8888
return true;
8989
}
9090
}
@@ -156,7 +156,7 @@ public void testNamespaceListXMLandJSON() throws IOException, JAXBException {
156156
}
157157

158158
@Test
159-
public void testNamespaceListPBandDefault() throws IOException, JAXBException {
159+
public void testNamespaceListPBandDefault() throws IOException {
160160
String schemaPath = "/namespaces/";
161161
NamespacesModel model;
162162
Response response;

hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithLabels.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171

7272
@Category({RestTests.class, MediumTests.class})
7373
public class TestScannersWithLabels {
74-
7574
@ClassRule
7675
public static final HBaseClassTestRule CLASS_RULE =
7776
HBaseClassTestRule.forClass(TestScannersWithLabels.class);
@@ -96,7 +95,8 @@ public class TestScannersWithLabels {
9695
private static Unmarshaller unmarshaller;
9796
private static Configuration conf;
9897

99-
private static int insertData(TableName tableName, String column, double prob) throws IOException {
98+
private static int insertData(TableName tableName, String column, double prob)
99+
throws IOException {
100100
byte[] k = new byte[3];
101101
byte[][] famAndQf = CellUtil.parseColumn(Bytes.toBytes(column));
102102

@@ -168,20 +168,18 @@ public static void tearDownAfterClass() throws Exception {
168168
}
169169

170170
private static void createLabels() throws IOException, InterruptedException {
171-
PrivilegedExceptionAction<VisibilityLabelsResponse> action = new PrivilegedExceptionAction<VisibilityLabelsResponse>() {
172-
@Override
173-
public VisibilityLabelsResponse run() throws Exception {
174-
String[] labels = { SECRET, CONFIDENTIAL, PRIVATE, PUBLIC, TOPSECRET };
175-
try (Connection conn = ConnectionFactory.createConnection(conf)) {
176-
VisibilityClient.addLabels(conn, labels);
177-
} catch (Throwable t) {
178-
throw new IOException(t);
179-
}
180-
return null;
171+
PrivilegedExceptionAction<VisibilityLabelsResponse> action = () -> {
172+
String[] labels = { SECRET, CONFIDENTIAL, PRIVATE, PUBLIC, TOPSECRET };
173+
try (Connection conn = ConnectionFactory.createConnection(conf)) {
174+
VisibilityClient.addLabels(conn, labels);
175+
} catch (Throwable t) {
176+
throw new IOException(t);
181177
}
178+
return null;
182179
};
183180
SUPERUSER.runAs(action);
184181
}
182+
185183
private static void setAuths() throws Exception {
186184
String[] labels = { SECRET, CONFIDENTIAL, PRIVATE, PUBLIC, TOPSECRET };
187185
try (Connection conn = ConnectionFactory.createConnection(conf)) {
@@ -190,6 +188,7 @@ private static void setAuths() throws Exception {
190188
throw new IOException(t);
191189
}
192190
}
191+
193192
@Test
194193
public void testSimpleScannerXMLWithLabelsThatReceivesNoData() throws IOException, JAXBException {
195194
final int BATCH_SIZE = 5;
@@ -242,5 +241,4 @@ public void testSimpleScannerXMLWithLabelsThatReceivesData() throws IOException,
242241
.getBody()));
243242
assertEquals(5, countCellSet(cellSet));
244243
}
245-
246244
}

hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestSchemaResource.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,14 @@
5252
import org.junit.experimental.categories.Category;
5353
import org.junit.runner.RunWith;
5454
import org.junit.runners.Parameterized;
55-
import org.slf4j.Logger;
56-
import org.slf4j.LoggerFactory;
5755

5856
@Category({RestTests.class, MediumTests.class})
5957
@RunWith(Parameterized.class)
6058
public class TestSchemaResource {
61-
6259
@ClassRule
6360
public static final HBaseClassTestRule CLASS_RULE =
6461
HBaseClassTestRule.forClass(TestSchemaResource.class);
6562

66-
private static final Logger LOG = LoggerFactory.getLogger(TestSchemaResource.class);
67-
6863
private static String TABLE1 = "TestSchemaResource1";
6964
private static String TABLE2 = "TestSchemaResource2";
7065

@@ -146,7 +141,8 @@ public void testTableCreateAndDeleteXML() throws IOException, JAXBException {
146141
Response response;
147142

148143
Admin admin = TEST_UTIL.getAdmin();
149-
assertFalse("Table " + TABLE1 + " should not exist", admin.tableExists(TableName.valueOf(TABLE1)));
144+
assertFalse("Table " + TABLE1 + " should not exist",
145+
admin.tableExists(TableName.valueOf(TABLE1)));
150146

151147
// create the table
152148
model = testTableSchemaModel.buildTestModel(TABLE1);
@@ -200,7 +196,7 @@ public void testTableCreateAndDeleteXML() throws IOException, JAXBException {
200196
}
201197

202198
@Test
203-
public void testTableCreateAndDeletePB() throws IOException, JAXBException {
199+
public void testTableCreateAndDeletePB() throws IOException {
204200
String schemaPath = "/" + TABLE2 + "/schema";
205201
TableSchemaModel model;
206202
Response response;
@@ -263,6 +259,4 @@ public void testTableCreateAndDeletePB() throws IOException, JAXBException {
263259
assertEquals(200, response.getCode());
264260
assertFalse(admin.tableExists(TableName.valueOf(TABLE2)));
265261
}
266-
267262
}
268-

0 commit comments

Comments
 (0)