Skip to content

HBASE-23623 Reduced the number of Checkstyle violations in hbase-rest #970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

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

@Category({RestTests.class, MediumTests.class})
public class TestGetAndPutResource extends RowResourceBase {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestGetAndPutResource.class);
Expand Down Expand Up @@ -134,7 +133,7 @@ public void testSingleCellGetPutPB() throws IOException, JAXBException {
}

@Test
public void testMultipleCellCheckPutPB() throws IOException, JAXBException {
public void testMultipleCellCheckPutPB() throws IOException {
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
assertEquals(404, response.getCode());

Expand Down Expand Up @@ -200,7 +199,7 @@ public void testMultipleCellCheckPutXML() throws IOException, JAXBException {
}

@Test
public void testMultipleCellCheckDeletePB() throws IOException, JAXBException {
public void testMultipleCellCheckDeletePB() throws IOException {
Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
assertEquals(404, response.getCode());

Expand Down Expand Up @@ -252,6 +251,7 @@ public void testMultipleCellCheckDeletePB() throws IOException, JAXBException {
response = deleteRow(TABLE, ROW_1);
assertEquals(200, response.getCode());
}

@Test
public void testSingleCellGetPutBinary() throws IOException {
final String path = "/" + TABLE + "/" + ROW_3 + "/" + COLUMN_1;
Expand All @@ -278,7 +278,7 @@ public void testSingleCellGetPutBinary() throws IOException {
}

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

@Test
public void testLatestCellGetJSON() throws IOException, JAXBException {
public void testLatestCellGetJSON() throws IOException {
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
CellSetModel cellSetModel = new CellSetModel();
RowModel rowModel = new RowModel(ROW_4);
Expand Down Expand Up @@ -339,7 +339,7 @@ public void testURLEncodedKey() throws IOException, JAXBException {
}

@Test
public void testNoSuchCF() throws IOException, JAXBException {
public void testNoSuchCF() throws IOException {
final String goodPath = "/" + TABLE + "/" + ROW_1 + "/" + CFA+":";
final String badPath = "/" + TABLE + "/" + ROW_1 + "/" + "BAD";
Response response = client.post(goodPath, Constants.MIMETYPE_BINARY,
Expand Down Expand Up @@ -529,7 +529,7 @@ public void testMultiCellGetJson() throws IOException, JAXBException {
}

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

UserProvider userProvider = UserProvider.instantiate(conf);
METRICS_ASSERT.assertCounterGt("requests", 2l,
METRICS_ASSERT.assertCounterGt("requests", 2L,
RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());

METRICS_ASSERT.assertCounterGt("successfulGet", 0l,
METRICS_ASSERT.assertCounterGt("successfulGet", 0L,
RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());

METRICS_ASSERT.assertCounterGt("successfulPut", 0l,
METRICS_ASSERT.assertCounterGt("successfulPut", 0L,
RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());

METRICS_ASSERT.assertCounterGt("successfulDelete", 0l,
METRICS_ASSERT.assertCounterGt("successfulDelete", 0L,
RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
}

Expand Down Expand Up @@ -806,4 +806,3 @@ public void testIncrementJSON() throws IOException, JAXBException {
assertEquals(200, response.getCode());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
*/
package org.apache.hadoop.hbase.rest;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
Expand Down Expand Up @@ -60,7 +63,6 @@

@Category({RestTests.class, MediumTests.class})
public class TestNamespacesInstanceResource {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestNamespacesInstanceResource.class);
Expand Down Expand Up @@ -122,9 +124,9 @@ private static <T> T fromXML(byte[] content)

private NamespaceDescriptor findNamespace(Admin admin, String namespaceName) throws IOException{
NamespaceDescriptor[] nd = admin.listNamespaceDescriptors();
for(int i = 0; i < nd.length; i++){
if(nd[i].getName().equals(namespaceName)){
return nd[i];
for (NamespaceDescriptor namespaceDescriptor : nd) {
if (namespaceDescriptor.getName().equals(namespaceName)) {
return namespaceDescriptor;
}
}
return null;
Expand All @@ -137,15 +139,15 @@ private void checkNamespaceProperties(NamespaceDescriptor nd, Map<String,String>
private void checkNamespaceProperties(Map<String,String> namespaceProps,
Map<String,String> testProps){
assertTrue(namespaceProps.size() == testProps.size());
for(String key: testProps.keySet()){
for (String key: testProps.keySet()) {
assertEquals(testProps.get(key), namespaceProps.get(key));
}
}

private void checkNamespaceTables(List<TableModel> namespaceTables, List<String> testTables){
assertEquals(namespaceTables.size(), testTables.size());
for(int i = 0 ; i < namespaceTables.size() ; i++){
String tableName = ((TableModel) namespaceTables.get(i)).getName();
for (TableModel namespaceTable : namespaceTables) {
String tableName = namespaceTable.getName();
assertTrue(testTables.contains(tableName));
}
}
Expand Down Expand Up @@ -369,7 +371,7 @@ public void testNamespaceCreateAndDeleteXMLAndJSON() throws IOException, JAXBExc
}

@Test
public void testNamespaceCreateAndDeletePBAndNoBody() throws IOException, JAXBException {
public void testNamespaceCreateAndDeletePBAndNoBody() throws IOException {
String namespacePath3 = "/namespaces/" + NAMESPACE3;
String namespacePath4 = "/namespaces/" + NAMESPACE4;
NamespacesInstanceModel model3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
*/
package org.apache.hadoop.hbase.rest;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand All @@ -44,7 +45,6 @@

@Category({RestTests.class, MediumTests.class})
public class TestNamespacesResource {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestNamespacesResource.class);
Expand Down Expand Up @@ -83,8 +83,8 @@ private static NamespacesModel fromXML(byte[] content) throws JAXBException {

private boolean doesNamespaceExist(Admin admin, String namespaceName) throws IOException {
NamespaceDescriptor[] nd = admin.listNamespaceDescriptors();
for(int i = 0; i < nd.length; i++) {
if(nd[i].getName().equals(namespaceName)) {
for (NamespaceDescriptor namespaceDescriptor : nd) {
if (namespaceDescriptor.getName().equals(namespaceName)) {
return true;
}
}
Expand Down Expand Up @@ -156,7 +156,7 @@ public void testNamespaceListXMLandJSON() throws IOException, JAXBException {
}

@Test
public void testNamespaceListPBandDefault() throws IOException, JAXBException {
public void testNamespaceListPBandDefault() throws IOException {
String schemaPath = "/namespaces/";
NamespacesModel model;
Response response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@

@Category({RestTests.class, MediumTests.class})
public class TestScannersWithLabels {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestScannersWithLabels.class);
Expand All @@ -96,7 +95,8 @@ public class TestScannersWithLabels {
private static Unmarshaller unmarshaller;
private static Configuration conf;

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

Expand Down Expand Up @@ -168,20 +168,18 @@ public static void tearDownAfterClass() throws Exception {
}

private static void createLabels() throws IOException, InterruptedException {
PrivilegedExceptionAction<VisibilityLabelsResponse> action = new PrivilegedExceptionAction<VisibilityLabelsResponse>() {
@Override
public VisibilityLabelsResponse run() throws Exception {
String[] labels = { SECRET, CONFIDENTIAL, PRIVATE, PUBLIC, TOPSECRET };
try (Connection conn = ConnectionFactory.createConnection(conf)) {
VisibilityClient.addLabels(conn, labels);
} catch (Throwable t) {
throw new IOException(t);
}
return null;
PrivilegedExceptionAction<VisibilityLabelsResponse> action = () -> {
String[] labels = { SECRET, CONFIDENTIAL, PRIVATE, PUBLIC, TOPSECRET };
try (Connection conn = ConnectionFactory.createConnection(conf)) {
VisibilityClient.addLabels(conn, labels);
} catch (Throwable t) {
throw new IOException(t);
}
return null;
};
SUPERUSER.runAs(action);
}

private static void setAuths() throws Exception {
String[] labels = { SECRET, CONFIDENTIAL, PRIVATE, PUBLIC, TOPSECRET };
try (Connection conn = ConnectionFactory.createConnection(conf)) {
Expand All @@ -190,6 +188,7 @@ private static void setAuths() throws Exception {
throw new IOException(t);
}
}

@Test
public void testSimpleScannerXMLWithLabelsThatReceivesNoData() throws IOException, JAXBException {
final int BATCH_SIZE = 5;
Expand Down Expand Up @@ -242,5 +241,4 @@ public void testSimpleScannerXMLWithLabelsThatReceivesData() throws IOException,
.getBody()));
assertEquals(5, countCellSet(cellSet));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,14 @@
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Category({RestTests.class, MediumTests.class})
@RunWith(Parameterized.class)
public class TestSchemaResource {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestSchemaResource.class);

private static final Logger LOG = LoggerFactory.getLogger(TestSchemaResource.class);

private static String TABLE1 = "TestSchemaResource1";
private static String TABLE2 = "TestSchemaResource2";

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

Admin admin = TEST_UTIL.getAdmin();
assertFalse("Table " + TABLE1 + " should not exist", admin.tableExists(TableName.valueOf(TABLE1)));
assertFalse("Table " + TABLE1 + " should not exist",
admin.tableExists(TableName.valueOf(TABLE1)));

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

@Test
public void testTableCreateAndDeletePB() throws IOException, JAXBException {
public void testTableCreateAndDeletePB() throws IOException {
String schemaPath = "/" + TABLE2 + "/schema";
TableSchemaModel model;
Response response;
Expand Down Expand Up @@ -263,6 +259,4 @@ public void testTableCreateAndDeletePB() throws IOException, JAXBException {
assertEquals(200, response.getCode());
assertFalse(admin.tableExists(TableName.valueOf(TABLE2)));
}

}

Loading